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 fastopenapi[falcon]
pip install fastopenapi[flask]
pip install fastopenapi[sanic]
pip install fastopenapi[starlette]
pip install fastopenapi[tornado]
- Create the
main.py
file - Copy the code from an example
- For some examples uvicorn is required (
pip install uvicorn
)
-
Click to expand the Falcon Example
import falcon.asgi import uvicorn from pydantic import BaseModel from fastopenapi.routers import FalconRouter app = falcon.asgi.App() router = FalconRouter(app=app) class HelloResponse(BaseModel): message: str @router.get("/hello", tags=["Hello"], status_code=200, response_model=HelloResponse) async def hello(name: str): """Say hello from Falcon""" return HelloResponse(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
from flask import Flask from pydantic import BaseModel from fastopenapi.routers import FlaskRouter app = Flask(__name__) router = FlaskRouter(app=app) class HelloResponse(BaseModel): message: str @router.get("/hello", tags=["Hello"], status_code=200, response_model=HelloResponse) def hello(name: str): """Say hello from Flask""" return HelloResponse(message=f"Hello, {name}! It's Flask!") if __name__ == "__main__": app.run(port=8000)
-
Click to expand the Quart Example
from pydantic import BaseModel from quart import Quart from fastopenapi.routers import QuartRouter app = Quart(__name__) router = QuartRouter(app=app) class HelloResponse(BaseModel): message: str @router.get("/hello", tags=["Hello"], status_code=200, response_model=HelloResponse) async def hello(name: str): """Say hello from Quart""" return HelloResponse(message=f"Hello, {name}! It's Quart!") if __name__ == "__main__": app.run(port=8000)
-
Click to expand the Sanic Example
from pydantic import BaseModel from sanic import Sanic from fastopenapi.routers import SanicRouter app = Sanic("MySanicApp") router = SanicRouter(app=app) class HelloResponse(BaseModel): message: str @router.get("/hello", tags=["Hello"], status_code=200, response_model=HelloResponse) async def hello(name: str): """Say hello from Sanic""" return HelloResponse(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
import uvicorn from pydantic import BaseModel from starlette.applications import Starlette from fastopenapi.routers import StarletteRouter app = Starlette() router = StarletteRouter(app=app) class HelloResponse(BaseModel): message: str @router.get("/hello", tags=["Hello"], status_code=200, response_model=HelloResponse) async def hello(name: str): """Say hello from Starlette""" return HelloResponse(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
import asyncio from pydantic import BaseModel from tornado.web import Application from fastopenapi.routers.tornado import TornadoRouter app = Application() router = TornadoRouter(app=app) class HelloResponse(BaseModel): message: str @router.get("/hello", tags=["Hello"], status_code=200, response_model=HelloResponse) def hello(name: str): """Say hello from Tornado""" return HelloResponse(message=f"Hello, {name}! It's Tornado!") async def main(): app.listen(8000) await asyncio.Event().wait() if __name__ == "__main__": asyncio.run(main())
Launch the application:
Once 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: Falcon, Flask, Quart, Sanic, Starlette, Tornado.
- 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.
This project is licensed under the terms of the MIT license.
15 Comments
mr_Fatalyst
Hey everyone!
While working on a project that required OpenAPI docs across multiple frameworks, I got tired of maintaining separate solutions. I liked FastAPI’s clean and intuitive routing, so I built FastOpenAPI, bringing a similar approach to other Python frameworks (Flask, Sanic, Falcon, Starlette, etc).
It's meant for developers who prefer FastAPI-style routing but need or want to use a different framework.
The project is still evolving, and I’d love any feedback or testing from the community!
memset
This is really cool – something I've been looking for with Flask. Cleanest implementation with just the decorator that I've seen.
(As an aside, is there an open-source UI for docs that actually looks good – professional quality, or even lets you try out endpoints? All of the decent ones are proprietary nowadays.)
zapnuk
Why not just use fastAPI and have it built into the framework?
dtkav
Nice work! What's your take on spec-first vs. code-first?
I'm a fan of spec-first (i worked on connexion), but I've noticed that code-first seems to be more popular.
Onavo
No love for Django? I am looking for an alternative to DRF and Django-ninja that can optionally generate typed APIs and docs directly from the model definitions.
Sodosorry
[flagged]
ltbarcly3
Every FastApi project I've worked on (more than a few) had an average of less than 1 concurrent request per process. The amount of engineering effort they put into debugging the absolute mess that is async python when it was easily the worst tool for the job is remarkable. If you don't know why it is hilarious that a FastApi project would have less than one concurrent request per process you shouldn't be making technical decisions.
adhamsalama
Cool!
bravura
I'm looking for a solution to filter large openapi specs to the most concise complete subset. I've implemented three different variations, two of which appear not to prune enough, and one of which appears to prune too much.
Any recommendations?
wseqyrku
I like this. I think genai could be used to fill in gaps in, for example, Wikipedia with a note that it's AI generated. If anything I think that's a good starting point.
JodieBenitez
No Bottle ?
samstave
[dead]
blahhh2525
[flagged]
wg0
After years of development – Now I prefer declarative approach. Specs first, generate the code from it and implement required Interfaces.
One great too for that is TypeSpec[0].
This also allows thinking about the API first and ensures that what's documented is what's implemented.
[0] https://typespec.io
gister123
Python async has been a big mess. I haven’t looked back since moving to a Go + GRPC + Protobuf stack. I would highly recommend it.