2025-03-22 10:10:00
github.com
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.
Keep your files stored safely and securely with the SanDisk 2TB Extreme Portable SSD. With over 69,505 ratings and an impressive 4.6 out of 5 stars, this product has been purchased over 8K+ times in the past month. At only $129.99, this Amazon’s Choice product is a must-have for secure file storage.
Help keep private content private with the included password protection featuring 256-bit AES hardware encryption. Order now for just $129.99 on Amazon!
Help Power Techcratic’s Future – Scan To Support
If Techcratic’s content and insights have helped you, consider giving back by supporting the platform with crypto. Every contribution makes a difference, whether it’s for high-quality content, server maintenance, or future updates. Techcratic is constantly evolving, and your support helps drive that progress.
As a solo operator who wears all the hats, creating content, managing the tech, and running the site, your support allows me to stay focused on delivering valuable resources. Your support keeps everything running smoothly and enables me to continue creating the content you love. I’m deeply grateful for your support, it truly means the world to me! Thank you!
BITCOIN bc1qlszw7elx2qahjwvaryh0tkgg8y68enw30gpvge Scan the QR code with your crypto wallet app |
DOGECOIN D64GwvvYQxFXYyan3oQCrmWfidf6T3JpBA Scan the QR code with your crypto wallet app |
ETHEREUM 0xe9BC980DF3d985730dA827996B43E4A62CCBAA7a Scan the QR code with your crypto wallet app |
Please read the Privacy and Security Disclaimer on how Techcratic handles your support.
Disclaimer: As an Amazon Associate, Techcratic may earn from qualifying purchases.