Skip to content

Commit 68d768b

Browse files
Merge pull request #30 from Mohammadreza-kh94/feature/add-lifespan-support
Add lifespan support to FastAPI app creation
2 parents 99c7e58 + a0fdfce commit 68d768b

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

archipy/helpers/utils/app_utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import logging
44
from collections.abc import Awaitable, Callable
5+
from contextlib import AbstractAsyncContextManager
56
from http import HTTPStatus
67
from 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

Comments
 (0)