Home / Function/ include_router() — fastapi Function Reference

include_router() — fastapi Function Reference

Architecture documentation for the include_router() function in applications.py from the fastapi codebase.

Entity Profile

Dependency Diagram

graph TD
  2f430556_420d_2b59_49d3_a547e308f1ab["include_router()"]
  587454b3_6db6_011f_9fa4_3e4e2e09b72d["FastAPI"]
  2f430556_420d_2b59_49d3_a547e308f1ab -->|defined in| 587454b3_6db6_011f_9fa4_3e4e2e09b72d
  c1d02f65_9a84_123a_bdd4_304e5732f35a["include_router()"]
  2f430556_420d_2b59_49d3_a547e308f1ab -->|calls| c1d02f65_9a84_123a_bdd4_304e5732f35a
  28261a63_2ba9_f1ff_1d1b_475348a45a65["Default()"]
  2f430556_420d_2b59_49d3_a547e308f1ab -->|calls| 28261a63_2ba9_f1ff_1d1b_475348a45a65
  style 2f430556_420d_2b59_49d3_a547e308f1ab fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

fastapi/applications.py lines 1339–1542

    def include_router(
        self,
        router: Annotated[routing.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[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).

                **Example**

                ```python
                from fastapi import Depends, FastAPI

                from .dependencies import get_token_header
                from .internal import admin

                app = FastAPI()

                app.include_router(
                    admin.router,
                    dependencies=[Depends(get_token_header)],
                )
                ```
                """
            ),
        ] = None,
        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,
        deprecated: Annotated[
            Optional[bool],
            Doc(
                """
                Mark all the *path operations* in this router as deprecated.

                It will be added to the generated OpenAPI (e.g. visible at `/docs`).

                **Example**

                ```python
                from fastapi import FastAPI

                from .internal import old_api

                app = FastAPI()

                app.include_router(

Domain

Subdomains

Frequently Asked Questions

What does include_router() do?
include_router() is a function in the fastapi codebase, defined in fastapi/applications.py.
Where is include_router() defined?
include_router() is defined in fastapi/applications.py at line 1339.
What does include_router() call?
include_router() calls 2 function(s): Default, include_router.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free