fastapi
Use when working with FastAPI endpoints, Pydantic v2 models, dependency injection, middleware, background tasks, WebSockets, or streaming responses. Also use when testing FastAPI with httpx/TestClient, deploying with uvicorn, or debugging async route handling and OpenAPI schema generation.
| Model | Source |
|---|---|
| sonnet | pack: python |
Full Reference
fastapi
Section titled “fastapi”FastAPI is an async-first Python web framework built on Starlette and Pydantic v2. It auto-generates OpenAPI (Swagger) docs from type annotations. Pydantic v1 support is deprecated — use Pydantic v2 patterns throughout.
Quick Reference
Section titled “Quick Reference”| Item | Value |
|---|---|
| Install | pip install fastapi uvicorn[standard] |
| Pydantic version | v2 — model_config = ConfigDict(from_attributes=True) (not orm_mode) |
| Dev server | uvicorn main:app --reload |
| Prod server | gunicorn main:app -w 4 -k uvicorn.workers.UvicornWorker |
| Docs URL | /docs (Swagger) and /redoc |
| Background tasks limit | 30s max — use Celery/ARQ for longer work |
Reference Index
Section titled “Reference Index”| I want to… | File |
|---|---|
| Set up the app, CORS middleware, and lifespan hooks | reference/app-setup.md |
| Define path operations (GET, POST, PUT, DELETE) with query/path params | reference/path-operations.md |
| Write Pydantic v2 request/response models and validators | reference/pydantic-models.md |
| Implement dependency injection for DB sessions and auth | reference/dependency-injection.md |
| Add streaming responses, WebSockets, background tasks, and file uploads | reference/advanced-features.md |
| Test FastAPI routes with httpx and pytest-asyncio | reference/testing.md |
Usage: Read the reference file matching your current task from the index above. Each file is self-contained with code examples and inline gotchas.
Announcement
Section titled “Announcement”┏━ ⚡ fastapi ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Async Python API framework with Pydantic v2 and auto OpenAPI docs ┃ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛