Skip to content

state

Global server state shared across API modules.

Keeping state in a dedicated module prevents the classic 'main vs package module' duplication that occurs when api_server.py is run with python -m. All modules that need the generator or server args should import from here.

Classes

Functions

fastvideo.entrypoints.openai.state.clear_state

clear_state() -> None

Clear server state on shutdown.

Source code in fastvideo/entrypoints/openai/state.py
def clear_state() -> None:
    """Clear server state on shutdown."""
    global _generator, _fastvideo_args
    _generator = None
    _fastvideo_args = None

fastvideo.entrypoints.openai.state.get_generator

get_generator() -> VideoGenerator

Return the global VideoGenerator instance (set during startup).

Source code in fastvideo/entrypoints/openai/state.py
def get_generator() -> VideoGenerator:
    """Return the global VideoGenerator instance (set during startup)."""
    assert _generator is not None, "Server not initialized — generator is None"
    return _generator

fastvideo.entrypoints.openai.state.get_output_dir

get_output_dir() -> str

Return the configured output directory.

Source code in fastvideo/entrypoints/openai/state.py
def get_output_dir() -> str:
    """Return the configured output directory."""
    return _output_dir

fastvideo.entrypoints.openai.state.get_server_args

get_server_args() -> FastVideoArgs

Return the global FastVideoArgs (set during startup).

Source code in fastvideo/entrypoints/openai/state.py
def get_server_args() -> FastVideoArgs:
    """Return the global FastVideoArgs (set during startup)."""
    assert _fastvideo_args is not None, "Server not initialized — args is None"
    return _fastvideo_args

fastvideo.entrypoints.openai.state.set_state

set_state(generator: VideoGenerator, fastvideo_args: FastVideoArgs, output_dir: str) -> None

Set all server state at once (called from lifespan).

Source code in fastvideo/entrypoints/openai/state.py
def set_state(
    generator: VideoGenerator,
    fastvideo_args: FastVideoArgs,
    output_dir: str,
) -> None:
    """Set all server state at once (called from lifespan)."""
    global _generator, _fastvideo_args, _output_dir
    _generator = generator
    _fastvideo_args = fastvideo_args
    _output_dir = output_dir