include_router() — fastapi Function Reference
Architecture documentation for the include_router() function in routing.py from the fastapi codebase.
Entity Profile
Dependency Diagram
graph TD c1d02f65_9a84_123a_bdd4_304e5732f35a["include_router()"] ecadd3bc_0c58_b4e5_06d8_57da79199adc["APIRouter"] c1d02f65_9a84_123a_bdd4_304e5732f35a -->|defined in| ecadd3bc_0c58_b4e5_06d8_57da79199adc 2f430556_420d_2b59_49d3_a547e308f1ab["include_router()"] 2f430556_420d_2b59_49d3_a547e308f1ab -->|calls| c1d02f65_9a84_123a_bdd4_304e5732f35a b52314f4_2210_73b7_9368_6287f2dc93a0["websocket()"] b52314f4_2210_73b7_9368_6287f2dc93a0 -->|calls| c1d02f65_9a84_123a_bdd4_304e5732f35a 1b892f95_174f_a6fa_5ff9_9cd8b88e8ee0["get()"] 1b892f95_174f_a6fa_5ff9_9cd8b88e8ee0 -->|calls| c1d02f65_9a84_123a_bdd4_304e5732f35a c1007317_485d_af85_4574_92026d01331d["put()"] c1007317_485d_af85_4574_92026d01331d -->|calls| c1d02f65_9a84_123a_bdd4_304e5732f35a 12dce19e_74a0_f6cd_7c8f_689f6d3bd491["post()"] 12dce19e_74a0_f6cd_7c8f_689f6d3bd491 -->|calls| c1d02f65_9a84_123a_bdd4_304e5732f35a 7976336e_039f_c69e_acb3_2df2820fae83["delete()"] 7976336e_039f_c69e_acb3_2df2820fae83 -->|calls| c1d02f65_9a84_123a_bdd4_304e5732f35a 30dd5917_7bd2_dda4_e8f5_42f8618c5ed8["options()"] 30dd5917_7bd2_dda4_e8f5_42f8618c5ed8 -->|calls| c1d02f65_9a84_123a_bdd4_304e5732f35a 36211ab6_1627_aac7_93a9_dc398d2b88a2["head()"] 36211ab6_1627_aac7_93a9_dc398d2b88a2 -->|calls| c1d02f65_9a84_123a_bdd4_304e5732f35a c5bafab2_5f69_c237_195d_2a065cbb446e["patch()"] c5bafab2_5f69_c237_195d_2a065cbb446e -->|calls| c1d02f65_9a84_123a_bdd4_304e5732f35a 1605c2e4_0694_395a_b3dc_f4a9f4da045c["trace()"] 1605c2e4_0694_395a_b3dc_f4a9f4da045c -->|calls| c1d02f65_9a84_123a_bdd4_304e5732f35a 151590c8_e931_55e7_3262_5eca3d623171["test_top_level_generate_unique_id()"] 151590c8_e931_55e7_3262_5eca3d623171 -->|calls| c1d02f65_9a84_123a_bdd4_304e5732f35a 4fd33aaf_fe3e_7115_3638_8d3a4c4e1b68["test_router_overrides_generate_unique_id()"] 4fd33aaf_fe3e_7115_3638_8d3a4c4e1b68 -->|calls| c1d02f65_9a84_123a_bdd4_304e5732f35a b5d0d990_bd82_76ac_e2e3_5f9bb785fbaf["test_router_include_overrides_generate_unique_id()"] b5d0d990_bd82_76ac_e2e3_5f9bb785fbaf -->|calls| c1d02f65_9a84_123a_bdd4_304e5732f35a style c1d02f65_9a84_123a_bdd4_304e5732f35a fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
fastapi/routing.py lines 1261–1507
def include_router(
self,
router: Annotated["APIRouter", Doc("The `APIRouter` to include.")],
*,
prefix: Annotated[str, Doc("An optional path prefix for the router.")] = "",
tags: Annotated[
Optional[list[Union[str, Enum]]],
Doc(
"""
A list of tags to be applied to all the *path operations* in this
router.
It will be added to the generated OpenAPI (e.g. visible at `/docs`).
Read more about it in the
[FastAPI docs for Path Operation Configuration](https://fastapi.tiangolo.com/tutorial/path-operation-configuration/).
"""
),
] = None,
dependencies: Annotated[
Optional[Sequence[params.Depends]],
Doc(
"""
A list of dependencies (using `Depends()`) to be applied to all the
*path operations* in this router.
Read more about it in the
[FastAPI docs for Bigger Applications - Multiple Files](https://fastapi.tiangolo.com/tutorial/bigger-applications/#include-an-apirouter-with-a-custom-prefix-tags-responses-and-dependencies).
"""
),
] = None,
default_response_class: Annotated[
type[Response],
Doc(
"""
The default response class to be used.
Read more in the
[FastAPI docs for Custom Response - HTML, Stream, File, others](https://fastapi.tiangolo.com/advanced/custom-response/#default-response-class).
"""
),
] = Default(JSONResponse),
responses: Annotated[
Optional[dict[Union[int, str], dict[str, Any]]],
Doc(
"""
Additional responses to be shown in OpenAPI.
It will be added to the generated OpenAPI (e.g. visible at `/docs`).
Read more about it in the
[FastAPI docs for Additional Responses in OpenAPI](https://fastapi.tiangolo.com/advanced/additional-responses/).
And in the
[FastAPI docs for Bigger Applications](https://fastapi.tiangolo.com/tutorial/bigger-applications/#include-an-apirouter-with-a-custom-prefix-tags-responses-and-dependencies).
"""
),
] = None,
callbacks: Annotated[
Optional[list[BaseRoute]],
Doc(
"""
OpenAPI callbacks that should apply to all *path operations* in this
router.
It will be added to the generated OpenAPI (e.g. visible at `/docs`).
Read more about it in the
[FastAPI docs for OpenAPI Callbacks](https://fastapi.tiangolo.com/advanced/openapi-callbacks/).
"""
),
] = None,
deprecated: Annotated[
Optional[bool],
Doc(
"""
Mark all *path operations* in this router as deprecated.
It will be added to the generated OpenAPI (e.g. visible at `/docs`).
Read more about it in the
Domain
Subdomains
Defined In
Calls
Called By
- delete()
- get()
- head()
- include_router()
- options()
- patch()
- post()
- put()
- test_app_path_operation_overrides_generate_unique_id()
- test_router_include_overrides_generate_unique_id()
- test_router_overrides_generate_unique_id()
- test_router_path_operation_overrides_generate_unique_id()
- test_subrouter_top_level_include_overrides_generate_unique_id()
- test_top_level_generate_unique_id()
- trace()
- websocket()
Source
Frequently Asked Questions
What does include_router() do?
include_router() is a function in the fastapi codebase, defined in fastapi/routing.py.
Where is include_router() defined?
include_router() is defined in fastapi/routing.py at line 1261.
What does include_router() call?
include_router() calls 7 function(s): Default, _merge_lifespan_context, add_api_route, add_api_websocket_route, add_event_handler, get, get_value_or_default.
What calls include_router()?
include_router() is called by 16 function(s): delete, get, head, include_router, options, patch, post, put, and 8 more.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free