Overview
Use FastAPI for Python HTTP services that need OpenAPI, async I/O, and typed request and response models. The current release is 0.142.2 (2026-09-30). It requires Python 3.10 or later and Pydantic 2.9 or later, generates OpenAPI 3.1, and pairs with postgres through SQLAlchemy, asyncpg, or psycopg. This page is the baseline; each topic has its own page.
Install fastapi[standard] and use the CLI
pip install "fastapi[standard]" adds uvicorn, the FastAPI CLI, httpx, email-validator (needed for Pydantic’s EmailStr), and the OpenTelemetry SDK. Run fastapi dev for development with reload and fastapi run for production. Since 0.142.0 FastAPI emits OpenTelemetry traces and metrics natively; see observability.
Keep the rules on the page that owns them
- Separate input and output models, validate once at the edge: fastapi-pydantic.
Depends,yieldcleanup, and the lifespan context manager: fastapi-dependencies.- Blocking calls, threadpool offload, and worker counts: fastapi-async-io.
- Work after the response and when to use a real queue: fastapi-background-tasks.
- Response models, status codes, docs URLs, and client generation: fastapi-openapi.
Lay routes out under routers
One router per resource, mounted in main.py. Keep main.py to imports, app construction, and include_router calls.
app/
main.py # FastAPI(lifespan=...) + include_router calls
deps.py # Depends() factories
routers/ # users.py, orders.py; each: APIRouter(prefix="/users", tags=["users"])
schemas/ # Pydantic models
db/ # SQLAlchemy or asyncpg layer
See project-structure for broader layout rules, and webhooks for the raw-body route pattern.