Modern Python APIs with type hints — automatic validation, automatic OpenAPI docs, and async-first performance that rivals Node.js.
← Back to Server Sideasync def endpoints are first-class.Depends() system — clean for auth, DB sessions, settings./docs, ReDoc at /redoc, free.from fastapi import FastAPI, Depends from pydantic import BaseModel app = FastAPI() class Product(BaseModel): name: str price: float @app.get("/products/{product_id}") async def get_product(product_id: int) -> Product: return Product(name="Widget", price=9.99) @app.post("/products", status_code=201) async def create_product(p: Product) -> Product: # Pydantic already validated `p` return p
Type hints + Pydantic = automatic request validation. OpenAPI schema is generated from the same signatures, so docs and code never drift apart.
Depends(get_db) on a parameter wires up dependencies (DB sessions, current user, feature flags). Each dependency can also have its own dependencies — composable and testable.
ASGI-based; benchmarks competitive with Node.js and Go for I/O-bound workloads. Use async def with async DB drivers (asyncpg, databases, SQLAlchemy 2.0) for full benefit.
WebSockets are first-class. BackgroundTasks let you schedule work after returning a response (sending emails, log uploads).
| Companion | Purpose |
|---|---|
| Pydantic | Data validation & settings management. |
| SQLAlchemy 2.0 / SQLModel | ORM (SQLModel is by FastAPI's author). |
| Alembic | Database migrations. |
| Uvicorn / Gunicorn | Production ASGI servers. |
| Strawberry | GraphQL on FastAPI. |
Where Django is overkill but you still want type safety.
Wrap PyTorch / scikit-learn models behind a typed API.
Chat, dashboards, integration glue — many concurrent requests.
Auto docs make frontend/backend contracts trivial.