22
33import logging
44from collections .abc import Awaitable , Callable
5+ from contextlib import AbstractAsyncContextManager
56from http import HTTPStatus
67from typing import Any , cast
78
@@ -229,12 +230,14 @@ def create_fastapi_app(
229230 config : BaseConfig | None = None ,
230231 * ,
231232 configure_exception_handlers : bool = True ,
233+ lifespan : Callable [..., AbstractAsyncContextManager ] | None = None ,
232234 ) -> FastAPI :
233235 """Creates and configures a FastAPI application.
234236
235237 Args:
236238 config (BaseConfig | None): Optional custom configuration. If not provided, uses global config.
237239 configure_exception_handlers (bool): Whether to configure exception handlers.
240+ lifespan: Callable[..., AbstractAsyncContextManager] | None = None,
238241
239242 Returns:
240243 FastAPI: The configured FastAPI application instance.
@@ -253,6 +256,7 @@ def create_fastapi_app(
253256 docs_url = config .FASTAPI .DOCS_URL ,
254257 redocs_url = config .FASTAPI .RE_DOCS_URL ,
255258 responses = cast (dict [int | str , Any ], common_responses ),
259+ lifespan = lifespan ,
256260 )
257261
258262 FastAPIUtils .setup_sentry (config )
0 commit comments