FastOpenAPI is a library for generating and integrating OpenAPI schemas using Pydantic and various frameworks.
This project was inspired by FastAPI and aims to provide a similar developer-friendly experience.
pip install fastopenapipip install fastopenapi[aiohttp]pip install fastopenapi[falcon]pip install fastopenapi[flask]pip install fastopenapi[quart]pip install fastopenapi[sanic]pip install fastopenapi[starlette]pip install fastopenapi[tornado]pip install fastopenapi[django]- Create the
main.pyfile - Copy the code from an example
- For some examples uvicorn is required (
pip install uvicorn)
Click to expand the AioHTTP Example
fromaiohttpimportwebfrompydanticimportBaseModelfromfastopenapi.routersimportAioHttpRouterapp=web.Application() router=AioHttpRouter(app=app) classHelloResponse(BaseModel): message: str@router.get("/hello", tags=["Hello"], status_code=200, response_model=HelloResponse)asyncdefhello(name: str): """Say hello from aiohttp"""returnHelloResponse(message=f"Hello, {name}! It's aiohttp!") if__name__=="__main__": web.run_app(app, host="127.0.0.1", port=8000)
Click to expand the Falcon Example
fromfalconimportAppfrompydanticimportBaseModelfromwsgiref.simple_serverimportmake_serverfromfastopenapi.routersimportFalconRouterapp=App() router=FalconRouter(app=app) classHelloResponse(BaseModel): message: str@router.get("/hello", tags=["Hello"], status_code=200, response_model=HelloResponse)defhello(name: str): """Say hello from Falcon"""returnHelloResponse(message=f"Hello, {name}! It's Falcon!") if__name__=="__main__": withmake_server("", 8000, app) ashttpd: print("Serving on port 8000...") httpd.serve_forever()
Click to expand the Falcon Async Example
importfalcon.asgiimportuvicornfrompydanticimportBaseModelfromfastopenapi.routersimportFalconAsyncRouterapp=falcon.asgi.App() router=FalconAsyncRouter(app=app) classHelloResponse(BaseModel): message: str@router.get("/hello", tags=["Hello"], status_code=200, response_model=HelloResponse)asyncdefhello(name: str): """Say hello from Falcon"""returnHelloResponse(message=f"Hello, {name}! It's Falcon!") if__name__=="__main__": uvicorn.run(app, host="127.0.0.1", port=8000)
Click to expand the Flask Example
fromflaskimportFlaskfrompydanticimportBaseModelfromfastopenapi.routersimportFlaskRouterapp=Flask(__name__) router=FlaskRouter(app=app) classHelloResponse(BaseModel): message: str@router.get("/hello", tags=["Hello"], status_code=200, response_model=HelloResponse)defhello(name: str): """Say hello from Flask"""returnHelloResponse(message=f"Hello, {name}! It's Flask!") if__name__=="__main__": app.run(port=8000)
Click to expand the Quart Example
frompydanticimportBaseModelfromquartimportQuartfromfastopenapi.routersimportQuartRouterapp=Quart(__name__) router=QuartRouter(app=app) classHelloResponse(BaseModel): message: str@router.get("/hello", tags=["Hello"], status_code=200, response_model=HelloResponse)asyncdefhello(name: str): """Say hello from Quart"""returnHelloResponse(message=f"Hello, {name}! It's Quart!") if__name__=="__main__": app.run(port=8000)
Click to expand the Sanic Example
frompydanticimportBaseModelfromsanicimportSanicfromfastopenapi.routersimportSanicRouterapp=Sanic("MySanicApp") router=SanicRouter(app=app) classHelloResponse(BaseModel): message: str@router.get("/hello", tags=["Hello"], status_code=200, response_model=HelloResponse)asyncdefhello(name: str): """Say hello from Sanic"""returnHelloResponse(message=f"Hello, {name}! It's Sanic!") if__name__=="__main__": app.run(host="0.0.0.0", port=8000)
Click to expand the Starlette Example
importuvicornfrompydanticimportBaseModelfromstarlette.applicationsimportStarlettefromfastopenapi.routersimportStarletteRouterapp=Starlette() router=StarletteRouter(app=app) classHelloResponse(BaseModel): message: str@router.get("/hello", tags=["Hello"], status_code=200, response_model=HelloResponse)asyncdefhello(name: str): """Say hello from Starlette"""returnHelloResponse(message=f"Hello, {name}! It's Starlette!") if__name__=="__main__": uvicorn.run(app, host="127.0.0.1", port=8000)
Click to expand the Tornado Example
importasynciofrompydanticimportBaseModelfromtornado.webimportApplicationfromfastopenapi.routersimportTornadoRouterapp=Application() router=TornadoRouter(app=app) classHelloResponse(BaseModel): message: str@router.get("/hello", tags=["Hello"], status_code=200, response_model=HelloResponse)defhello(name: str): """Say hello from Tornado"""returnHelloResponse(message=f"Hello, {name}! It's Tornado!") asyncdefmain(): app.listen(8000) awaitasyncio.Event().wait() if__name__=="__main__": asyncio.run(main())
Click to expand the Django Example
fromdjango.confimportsettingsfromdjango.core.managementimportcall_commandfromdjango.core.wsgiimportget_wsgi_applicationfromdjango.urlsimportpathfrompydanticimportBaseModelfromfastopenapi.routersimportDjangoRoutersettings.configure(DEBUG=True, SECRET_KEY="__CHANGEME__", ROOT_URLCONF=__name__) application=get_wsgi_application() router=DjangoRouter(app=True) classHelloResponse(BaseModel): message: str@router.get("/hello", tags=["Hello"], status_code=200, response_model=HelloResponse)defhello(name: str): """Say hello from django"""returnHelloResponse(message=f"Hello, {name}! It's Django!") urlpatterns= [path("", router.urls)] if__name__=="__main__": call_command("runserver")
Launch the application:
python main.pyOnce launched, the documentation will be available at:
Swagger UI:
http://127.0.0.1:8000/docs
ReDoc UI:
http://127.0.0.1:8000/redoc
- Generate OpenAPI schemas with Pydantic v2.
- Data validation using Pydantic models.
- Supports multiple frameworks: AIOHTTP, Falcon, Flask, Quart, Sanic, Starlette, Tornado, Django.
- Proxy routing provides FastAPI-style routing
Explore the Docs for an overview of FastOpenAPI, its core components, and usage guidelines. The documentation is continuously updated and improved.
Examples of integration and detailed usage for each framework are available in the examples directory.
Fast but not perfect benchmarks. Check the benchmarks directory for details.
- Use Pydantic models for strict typing and data validation.
- Follow the project structure similar to provided examples for easy scalability.
- Regularly update dependencies and monitor library updates for new features.
If you have suggestions or find a bug, please open an issue or create a pull request on GitHub.
Supported by JetBrains under the Open Source Support Program.
This project is licensed under the terms of the MIT license.

