Skip to content

Application API

Import these objects from anihmm in normal application code.

anihmm

Application-facing API for terminal HMM animations.

AnihmmError

Bases: Exception

Base exception for public anihmm API failures.

AnimationConfigError

Bases: AnihmmError, ValueError

Invalid playback or rendering configuration.

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.

AnimationTimeoutError

Bases: SessionError, TimeoutError

Animation session did not finish before the requested timeout.

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.

FrameCompilationError

Bases: AnihmmError, ValueError

Failure while compiling semantic steps into renderable frames.

HMMFrame dataclass

A single renderable HMM lattice frame.

__post_init__

__post_init__() -> None

Validate the initial frame structure.

HMMSequence

Stateful builder for semantic HMM animation steps.

columns property

columns: int | None

Configured lattice bound, or None for an unbounded sequence.

committed property

committed: list[Transition]

Copy of the committed transition path.

current_node property

current_node: str

Current settled node identifier.

emissions property

emissions: list[str]

Copy of the accumulated emission entries.

steps property

steps: list[Step]

Copy of the semantic steps constructed so far.

__init__

__init__(
    *, start: str = "S", columns: int | None = None
) -> None

Create a sequence at a canonical node with optional bounds.

build

build() -> list[Step]

Return a copy of the semantic steps built so far.

cycle

cycle(
    kind: str, *, title: str | None = None
) -> HMMSequence

Add a transient preview of the next state without committing it.

emit

emit(
    symbol: str, *, title: str | None = None
) -> HMMSequence

Emit one visible terminal-cell symbol from the current state.

finish

finish(*, title: str | None = None) -> HMMSequence

Fill remaining bounded columns with deletions, then commit E.

flash_current

flash_current(*, title: str | None = None) -> HMMSequence

Add a transient flash overlay to the current state.

settle

settle(
    kind: str, *, title: str | None = None
) -> HMMSequence

Commit a transition to the next state of kind.

InvalidTransitionError

Bases: SequenceError

Invalid lattice transition or node reference.

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.

SequenceError

Bases: AnihmmError, ValueError

Invalid semantic sequence construction.

SessionError

Bases: AnihmmError, RuntimeError

Failure while starting, stopping, or monitoring a background session.

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.

compile_steps

compile_steps(
    steps: Iterable[Step], *, columns: int | None = None
) -> list[HMMFrame]

Compile semantic steps with a shared explicit or inferred column count.

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.