Skip to content

Playback API

Use this namespace for direct control over timing, output, and session lifecycle.

anihmm.playback

Playback engines, options, helpers, and session wrappers.

AnimationSession

Background animation session for embedding in terminal workflows.

is_running property

is_running: bool

Whether the current worker thread is alive.

__enter__

__enter__() -> AnimationSession

Start the session on context entry.

__exit__

__exit__(
    exc_type: type[BaseException] | None,
    exc_val: BaseException | None,
    exc_tb: TracebackType | None,
) -> None

Stop the session and preserve any exception from the context body.

__init__

__init__(
    frames: FrameSource,
    *,
    options: PlaybackOptions | None = None,
    fps: float = DEFAULT_FPS,
    columns: int | None = None,
    repeat: bool = True,
    hold_final_seconds: float | None = None,
    console: Console | None = None,
    enabled: bool | None = None,
    alternate_screen: bool = False,
) -> None

Create a reusable background session for frames.

start

start() -> AnimationSession

Start playback in a background thread and return this session.

stop

stop() -> None

Request cooperative cancellation of the active run.

wait

wait(timeout: float | None = None) -> None

Wait for the active run and surface its timeout or worker error.

AsyncAnimationSession

Async wrapper around :class:AnimationSession.

is_running property

is_running: bool

Whether the wrapped worker thread is alive.

__aenter__ async

__aenter__() -> AsyncAnimationSession

Start the wrapped session on async context entry.

__aexit__ async

__aexit__(
    exc_type: type[BaseException] | None,
    exc_val: BaseException | None,
    exc_tb: TracebackType | None,
) -> None

Stop the session and preserve any exception from the context body.

__init__

__init__(
    frames: FrameSource,
    *,
    options: PlaybackOptions | None = None,
    fps: float = DEFAULT_FPS,
    columns: int | None = None,
    repeat: bool = True,
    hold_final_seconds: float | None = None,
    console: Console | None = None,
    enabled: bool | None = None,
    alternate_screen: bool = False,
) -> None

Create an async wrapper around a background animation session.

start async

start() -> AsyncAnimationSession

Start the wrapped background session and return this wrapper.

stop

stop() -> None

Request cooperative cancellation of the wrapped session.

wait async

wait(timeout: float | None = None) -> None

Await completion and surface timeout or worker errors.

PlaybackOptions dataclass

Runtime playback configuration.

__post_init__

__post_init__() -> None

Validate playback configuration.

background classmethod

background(
    *,
    fps: float = DEFAULT_FPS,
    hold_final_seconds: float | None = None,
    console: Console | None = None,
    enabled: bool | None = None,
    alternate_screen: bool = False,
) -> PlaybackOptions

Build options for looping background playback sessions.

ProcessingOptions dataclass

Preset selection for looping background animations.

__post_init__

__post_init__() -> None

Validate preset configuration.

demo classmethod

demo(*, columns: int = DEMO_COLUMNS) -> ProcessingOptions

Build the default demo preset selection.

frame_source

frame_source() -> FrameSource

Build a reusable frame source for playback sessions.

random classmethod

random(
    *,
    columns: int = DEMO_COLUMNS,
    seed: int | None = None,
    emissions: int | str | None = None,
) -> ProcessingOptions

Build a random-path preset selection.

ProgressSession

Cycle candidate transitions until application work advances the path.

current_node property

current_node: str

The most recently settled node.

is_finished property

is_finished: bool

Whether :meth:finish has committed the path to E.

is_running property

is_running: bool

Whether terminal playback is active in the worker thread.

__enter__

__enter__() -> ProgressSession

Start scanning transitions on context entry.

__exit__

__exit__(
    exc_type: type[BaseException] | None,
    exc_val: BaseException | None,
    exc_tb: TracebackType | None,
) -> None

Stop playback while preserving exceptions raised by the work block.

__init__

__init__(
    *,
    columns: int = 8,
    fps: float = DEFAULT_FPS,
    settle_seconds: float = _DEFAULT_SETTLE_SECONDS,
    console: Console | None = None,
    enabled: bool | None = None,
    alternate_screen: bool = False,
) -> None

Create a single-use progress session for a bounded HMM lattice.

advance

advance(
    kind: str, *, emission: str | None = None
) -> ProgressSession

Settle on the chosen state, then begin scanning its outgoing transitions.

finish

finish() -> ProgressSession

Commit the current path to E and hold its completed frame.

start

start() -> ProgressSession

Start scanning and return this session.

stop

stop() -> None

Request cooperative cancellation of terminal playback.

wait

wait(timeout: float | None = None) -> None

Wait for playback to stop and surface timeout or worker errors.

animate_frames

animate_frames(
    frames: FrameSource,
    *,
    fps: float = DEFAULT_FPS,
    columns: int | None = None,
    repeat: bool = False,
    hold_final_seconds: float | None = None,
    console: Console | None = None,
    stop_event: Event | None = None,
    enabled: bool | None = None,
    alternate_screen: bool = False,
) -> None

Render frames synchronously with optional repetition and cancellation.

async_processing_animation

async_processing_animation(
    processing: ProcessingOptions | None = None,
    playback: PlaybackOptions | None = None,
) -> AsyncAnimationSession

Build an asynchronous background animation session from reusable options.

print_frame_in_place

print_frame_in_place(
    frame: HMMFrame,
    *,
    console: Console | None = None,
    columns: int | None = None,
) -> None

Replace the previous fixed-height lattice region with frame.

processing_animation

processing_animation(
    processing: ProcessingOptions | None = None,
    playback: PlaybackOptions | None = None,
) -> AnimationSession

Build a synchronous background animation session from reusable options.

progress_animation

progress_animation(
    *,
    columns: int = 8,
    fps: float = DEFAULT_FPS,
    settle_seconds: float = _DEFAULT_SETTLE_SECONDS,
    console: Console | None = None,
    enabled: bool | None = None,
    alternate_screen: bool = False,
) -> ProgressSession

Build a work-driven progress session for use as a context manager.