on_event() — fastapi Function Reference
Architecture documentation for the on_event() function in routing.py from the fastapi codebase.
Entity Profile
Dependency Diagram
graph TD a27c576c_fb92_8398_f37e_212c576404a2["on_event()"] ecadd3bc_0c58_b4e5_06d8_57da79199adc["APIRouter"] a27c576c_fb92_8398_f37e_212c576404a2 -->|defined in| ecadd3bc_0c58_b4e5_06d8_57da79199adc dac05d36_d298_20ac_8313_653329a27887["on_event()"] dac05d36_d298_20ac_8313_653329a27887 -->|calls| a27c576c_fb92_8398_f37e_212c576404a2 4bbb96be_c308_9252_9434_46c4b5112bf3["add_event_handler()"] a27c576c_fb92_8398_f37e_212c576404a2 -->|calls| 4bbb96be_c308_9252_9434_46c4b5112bf3 style a27c576c_fb92_8398_f37e_212c576404a2 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
fastapi/routing.py lines 4610–4634
def on_event(
self,
event_type: Annotated[
str,
Doc(
"""
The type of event. `startup` or `shutdown`.
"""
),
],
) -> Callable[[DecoratedCallable], DecoratedCallable]:
"""
Add an event handler for the router.
`on_event` is deprecated, use `lifespan` event handlers instead.
Read more about it in the
[FastAPI docs for Lifespan Events](https://fastapi.tiangolo.com/advanced/events/#alternative-events-deprecated).
"""
def decorator(func: DecoratedCallable) -> DecoratedCallable:
self.add_event_handler(event_type, func)
return func
return decorator
Domain
Subdomains
Defined In
Calls
Called By
Source
Frequently Asked Questions
What does on_event() do?
on_event() is a function in the fastapi codebase, defined in fastapi/routing.py.
Where is on_event() defined?
on_event() is defined in fastapi/routing.py at line 4610.
What does on_event() call?
on_event() calls 1 function(s): add_event_handler.
What calls on_event()?
on_event() is called by 1 function(s): on_event.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free