_DefaultLifespan Class — fastapi Architecture
Architecture documentation for the _DefaultLifespan class in routing.py from the fastapi codebase.
Entity Profile
Dependency Diagram
graph TD 867570c5_b33e_95c7_0468_a87f8aae6ca1["_DefaultLifespan"] de395a51_26f8_3424_1af0_2f5bef39c893["routing.py"] 867570c5_b33e_95c7_0468_a87f8aae6ca1 -->|defined in| de395a51_26f8_3424_1af0_2f5bef39c893 d3c3984c_0be8_b8a8_e206_e5bf01ce1530["__init__()"] 867570c5_b33e_95c7_0468_a87f8aae6ca1 -->|method| d3c3984c_0be8_b8a8_e206_e5bf01ce1530 02d6cbe5_9949_3a5f_4f41_ee05399bd61e["__aenter__()"] 867570c5_b33e_95c7_0468_a87f8aae6ca1 -->|method| 02d6cbe5_9949_3a5f_4f41_ee05399bd61e 0bcce1e6_c4c6_e1ff_31ae_19d689ccec1d["__aexit__()"] 867570c5_b33e_95c7_0468_a87f8aae6ca1 -->|method| 0bcce1e6_c4c6_e1ff_31ae_19d689ccec1d 4cf8e38d_9a32_29bb_8e5e_a7062495ed3b["__call__()"] 867570c5_b33e_95c7_0468_a87f8aae6ca1 -->|method| 4cf8e38d_9a32_29bb_8e5e_a7062495ed3b
Relationship Graph
Source Code
fastapi/routing.py lines 213–234
class _DefaultLifespan:
"""
Default lifespan context manager that runs on_startup and on_shutdown handlers.
This is a copy of the Starlette _DefaultLifespan class that was removed
in Starlette. FastAPI keeps it to maintain backward compatibility with
on_startup and on_shutdown event handlers.
Ref: https://github.com/Kludex/starlette/pull/3117
"""
def __init__(self, router: "APIRouter") -> None:
self._router = router
async def __aenter__(self) -> None:
await self._router._startup()
async def __aexit__(self, *exc_info: object) -> None:
await self._router._shutdown()
def __call__(self: _T, app: object) -> _T:
return self
Domain
Defined In
Source
Frequently Asked Questions
What is the _DefaultLifespan class?
_DefaultLifespan is a class in the fastapi codebase, defined in fastapi/routing.py.
Where is _DefaultLifespan defined?
_DefaultLifespan is defined in fastapi/routing.py at line 213.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free