FastOpenAPI
raw JSON → 0.7.0 verified Fri May 01 auth: no python
FastOpenAPI is a library for generating and integrating OpenAPI schemas using Pydantic v2 with multiple async web frameworks (AioHttp, Falcon, Flask, Quart, Sanic, Starlette, Tornado). The latest stable release is v0.7.0, with v1.0.0rc1 available as a release candidate. The project is actively maintained with frequent releases.
pip install fastopenapi Common errors
error ModuleNotFoundError: No module named 'fastopenapi' ↓
cause Package not installed, or installed without the desired framework extra.
fix
Run 'pip install fastopenapi' for base, or 'pip install fastopenapi[starlette]' for Starlette support.
error ImportError: cannot import name 'StarletteRouter' from 'fastopenapi' ↓
cause Using old import path 'from fastopenapi import StarletteRouter' which is incorrect since v0.3.0.
fix
Use 'from fastopenapi.routers import StarletteRouter'.
error ValueError: 'use_aliases' is not a valid parameter for this router ↓
cause Trying to pass use_aliases argument in v0.7.0 where it was removed.
fix
Remove the use_aliases parameter; aliasing is always enabled.
Warnings
breaking In v0.6.0 the 'use_aliases' parameter was added to BaseRouter (default True). This changed behavior for models with aliases. To revert to previous behavior, set use_aliases=False. ↓
fix Initialize router with use_aliases=False if you need the previous behavior.
deprecated The use_aliases parameter was removed in v0.7.0. The library now always uses aliases via Pydantic. ↓
fix Remove use_aliases parameter; aliasing is always on.
gotcha For GET routes with Pydantic models as parameters, the library reads query parameters at runtime. In v1.0.0rc1 this was fixed but in v0.7.0 the behavior may be incorrect for certain model definitions. ↓
fix Upgrade to v1.0.0rc1 or use manual query parameters for GET endpoints.
gotcha Router imports changed from direct 'from fastopenapi import StarletteRouter' to 'from fastopenapi.routers import StarletteRouter' in v0.3.0. Old imports will raise ModuleNotFoundError. ↓
fix Use correct import path: from fastopenapi.routers import YourRouter.
Install
pip install fastopenapi[starlette] Imports
- StarletteRouter wrong
from fastopenapi import StarletteRoutercorrectfrom fastopenapi.routers import StarletteRouter - FlaskRouter wrong
from fastopenapi import FlaskRoutercorrectfrom fastopenapi.routers import FlaskRouter
Quickstart
from fastopenapi.routers import StarletteRouter
from pydantic import BaseModel
from starlette.applications import Starlette
from starlette.responses import JSONResponse
import uvicorn
app = Starlette()
router = StarletteRouter(app)
class HelloResponse(BaseModel):
message: str
@router.get("/hello/{name}", response_model=HelloResponse)
def hello(name: str) -> HelloResponse:
return HelloResponse(message=f"Hello, {name}!")
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8000)