Skip to content

Repository files navigation

Logo

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.

PyPI Downloads


📦 Installation

Install only FastOpenAPI:

pip install fastopenapi

Install FastOpenAPI with a specific framework:

pip 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]

🛠️ Quick Start

Step 1. Create an application

  • Create the main.py file
  • Copy the code from an example
  • For some examples uvicorn is required (pip install uvicorn)

Examples:

  • AIOHTTP

    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)
  • Falcon

    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)
  • Flask

    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)
  • Quart

    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)
  • Sanic

    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)
  • Starlette

    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)
  • Tornado

    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())
  • Django

    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")

Step 2. Run the server

Launch the application:

python main.py

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

⚙️ Features

  • 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

📖 Documentation

Explore the Docs for an overview of FastOpenAPI, its core components, and usage guidelines. The documentation is continuously updated and improved.


📂 Advanced Examples

Examples of integration and detailed usage for each framework are available in the examples directory.


📊 Quick & Dirty Benchmarks

Fast but not perfect benchmarks. Check the benchmarks directory for details.


✅ Development Recommendations

  • 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.

🛠️ Contributing

If you have suggestions or find a bug, please open an issue or create a pull request on GitHub.


🤝 Acknowledgements

JetBrains logo

Supported by JetBrains under the Open Source Support Program.


📄 License

This project is licensed under the terms of the MIT license.

About

FastOpenAPI is a library for generating and integrating OpenAPI schemas using Pydantic v2 and various frameworks (AioHttp, Django, Falcon, Flask, Quart, Sanic, Starlette, Tornado).

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

512 stars

Watchers

2 watching

Forks

Releases

Used by

Contributors

Languages