fastapi_middleware_toolkit.lifespan =================================== .. py:module:: fastapi_middleware_toolkit.lifespan .. autoapi-nested-parse:: Lifespan context manager factory for FastAPI applications. Extracted from GridFlow backend/src/infrastructure/app_factory.py lines 18-26 Attributes ---------- .. autoapisummary:: fastapi_middleware_toolkit.lifespan.logger Functions --------- .. autoapisummary:: fastapi_middleware_toolkit.lifespan.create_lifespan_manager fastapi_middleware_toolkit.lifespan.create_health_check_endpoint Module Contents --------------- .. py:data:: logger .. py:function:: create_lifespan_manager(on_startup: Optional[Callable] = None, on_shutdown: Optional[Callable] = None, service_name: str = 'api', service_version: str = '1.0.0') -> Callable Create a lifespan factory for FastAPI application. Returns a callable compatible with FastAPI's lifespan parameter. Args: on_startup: Optional async function to call on startup on_shutdown: Optional async function to call on shutdown service_name: Name of the service for logging service_version: Version of the service for logging Returns: Lifespan callable for FastAPI(lifespan=...) Example: >>> lifespan = create_lifespan_manager( ... on_startup=init_database, ... service_name="my-api" ... ) >>> app = FastAPI(lifespan=lifespan) .. py:function:: create_health_check_endpoint(service_name: str, version: str = '1.0.0', additional_checks: Optional[Dict[str, Any]] = None) -> Callable Create a health check endpoint function. Args: service_name: Name of the service version: Version of the service additional_checks: Optional dict with additional health check data Returns: Async function that can be used as a FastAPI endpoint Example: >>> app = FastAPI() >>> health_check = create_health_check_endpoint("my-api", "1.0.0") >>> app.get("/health")(health_check)