Sub Applications - Mounts

    The current page still doesn’t have a translation for this language.

    But you can help translating it: Contributing.

    If you need to have two independent FastAPI applications, with their own independent OpenAPI and their own docs UIs, you can have a main app and “mount” one (or more) sub-application(s).

    “Mounting” means adding a completely “independent” application in a specific path, that then takes care of handling everything under that path, with the path operations declared in that sub-application.

    First, create the main, top-level, FastAPI application, and its path operations:

    Then, create your sub-application, and its path operations.

    In your top-level application, app, mount the sub-application, subapi.

    In this case, it will be mounted at the path :

    Now, run uvicorn with the main app, if your file is main.py, it would be:

    And open the docs at http://127.0.0.1:8000/docs.

    You will see the automatic API docs for the main app, including only its own path operations:

    And then, open the docs for the sub-application, at .

    You will see the automatic API docs for the sub-application, including only its own path operations, all under the correct sub-path prefix :

    Sub Applications - Mounts - 图3

    If you try interacting with any of the two user interfaces, they will work correctly, because the browser will be able to talk to each specific app or sub-app.

    When you mount a sub-application as described above, FastAPI will take care of communicating the mount path for the sub-application using a mechanism from the ASGI specification called a root_path.

    That way, the sub-application will know to use that path prefix for the docs UI.

    You will learn more about the root_path and how to use it explicitly in the section about .