Tips and Tricks


FastAPI Sub Applications

FastAPI tip:

You can use sub-applications when you need two separate OpenAPI schemas and Swagger UIs.

You can mount one or many sub-applications.


from fastapi import FastAPI

app = FastAPI()

def read_main():
    return {"message": "Hello World from main app"}

subapi = FastAPI()

def read_sub():
    return {"message": "Hello World from sub API"}

app.mount("/subapi", subapi)