Skip to content

Release Candidate — v1.0.0rc1

You are viewing the documentation for v1.0.0rc1 (release candidate). The API is stable, but minor changes may occur before the final release. The last stable version is available here.

FastOpenAPI

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


What is FastOpenAPI?

FastOpenAPI brings FastAPI-style developer experience to frameworks like Flask, Django, Starlette, AIOHTTP, and others. It provides:

  • Automatic OpenAPI schema generation from your route definitions
  • Interactive API documentation (Swagger UI and ReDoc)
  • Request validation using Pydantic models
  • Response serialization with type safety
  • Framework-agnostic approach - use with your preferred web framework

Inspired by FastAPI, FastOpenAPI aims to provide similar functionality for developers who need to work with existing frameworks or prefer not to adopt a full framework switch.

Key Features

Multi-Framework Support

FastOpenAPI supports 8 popular Python web frameworks out of the box:

  • AIOHTTP - Async HTTP client/server framework
  • Django - High-level web framework (sync and async)
  • Falcon - Minimalist ASGI/WSGI framework (sync and async)
  • Flask - Lightweight WSGI framework
  • Quart - Async version of Flask
  • Sanic - Async web framework built for speed
  • Starlette - Lightweight ASGI framework
  • Tornado - Async networking library

FastAPI-Style API

Use familiar decorator-based routing and parameter declarations:

from fastopenapi import Query, Path, Body
from fastopenapi.routers import FlaskRouter
from pydantic import BaseModel

router = FlaskRouter(app=app)

class User(BaseModel):
    name: str
    email: str

@router.get("/users/{user_id}")
def get_user(user_id: int = Path(..., description="User ID")):
    return {"user_id": user_id}

@router.post("/users", response_model=User)
def create_user(user: User = Body(...)):
    return user

Automatic Documentation

Once configured, your API documentation is automatically available:

  • Swagger UI: http://localhost:8000/docs
  • ReDoc: http://localhost:8000/redoc
  • OpenAPI JSON: http://localhost:8000/openapi.json

Pydantic v2 Integration

Leverage Pydantic v2 for:

  • Request body validation
  • Response model validation
  • Automatic JSON Schema generation
  • Type coercion and error messages

Advanced Features

Dependency Injection

from fastopenapi import Depends

def get_db():
    db = Database()
    try:
        yield db
    finally:
        db.close()

@router.get("/items")
def list_items(db = Depends(get_db)):
    return db.get_items()

Security Schemes

from fastopenapi import Security, SecuritySchemeType

router = FlaskRouter(
    app=app,
    security_scheme=SecuritySchemeType.BEARER_JWT
)

@router.get("/protected")
def protected_endpoint(token: str = Security(verify_token)):  # Your auth function
    return {"message": "Access granted"}

File Uploads

from fastopenapi import File, FileUpload

@router.post("/upload")
async def upload_file(file: FileUpload = File(...)):
    content = await file.aread()
    return {"filename": file.filename, "size": len(content)}

Project Status

FastOpenAPI is currently a release candidate (version 1.0.0rc1). The API is stable, but minor changes may occur before the 1.0.0 release. We welcome feedback and contributions to help improve the library.

Quick Example

Here's a complete working example with Flask:

from flask import Flask
from pydantic import BaseModel
from fastopenapi.routers import FlaskRouter

app = Flask(__name__)
router = FlaskRouter(app=app, title="My API", version="1.0.0")

class Item(BaseModel):
    name: str
    price: float
    description: str | None = None

@router.get("/")
def root():
    return {"message": "Hello, FastOpenAPI!"}

@router.post("/items", response_model=Item, status_code=201)
def create_item(item: Item):
    return item

if __name__ == "__main__":
    app.run(port=8000)

Run the app and visit http://localhost:8000/docs to see your interactive API documentation.

When to Use FastOpenAPI

Use FastOpenAPI when:

  • You have an existing application in Flask, Django, or another supported framework
  • You need OpenAPI documentation without switching frameworks
  • You want FastAPI-style DX but can't use FastAPI
  • You're building a library that needs to support multiple frameworks
  • You prefer the flexibility of choosing your own framework

Consider FastAPI when:

  • You're starting a new project from scratch
  • You want a complete, batteries-included async framework
  • You need built-in features like background tasks, WebSockets, and GraphQL support
  • You need maximum performance with ASGI and modern async features
  • You want the largest ecosystem, extensive documentation, and active community

Next Steps

Ready to get started? Head over to:

Community and Support

License

FastOpenAPI is licensed under the MIT License. See the LICENSE file for details.