package documentation

A package responsible for, setup, booting, and shutting down the server.

Module legacy_api Provide endpoints that mimic the v2 API for OpenFlexure Connect discoverability.
Module serve_static_files Add endpoints for static files to the underlying FastAPI server.

From __init__.py:

Function customise_server Customise the server with additional endpoints, etc.
Function serve_from_cli Start the server from the command line.
Function set_shutdown_function Ensure a function is called before the shutdown.
Constant LOGGER Undocumented
Function _full_config_from_args Load configuration from LabThings args allowing patching.
Function _get_scans_dir Read the config and return the scans directory.
def customise_server(server: lt.ThingServer, log_folder: str, scans_folder: str | None): (source)

Customise the server with additional endpoints, etc.

def serve_from_cli(argv: list[str] | None = None): (source)

Start the server from the command line.

def set_shutdown_function(shutdown_function: Callable[[], None]): (source)

Ensure a function is called before the shutdown.

This monkey patches the Uvicorn Server's handle_exit. This is needed because the uvicorn lifecycle events and FastAPI shutdown events only fire once background tasks have completed.

Without this the system exits cleanly only if no client is receiving a StreamingResponse. This patch is used to stop the async generators that send streaming responses.

Parameters
shutdown_function:Callable[[], None]A callable with no arguments or outputs. This should stop any async generators that may be sending to streaming responses.

Undocumented

Value
logging.getLogger(__name__)
def _full_config_from_args(args: Namespace) -> dict: (source)

Load configuration from LabThings args allowing patching.

This provides similar functionarlity to lt.cli.config_from_args except allows the configuration file to specify a base config, and optionally patches.

def _get_scans_dir(config: dict) -> str | None: (source)

Read the config and return the scans directory.

Return is None if there is no /smart_scan/ thing loaded.