FastAPI Cheat Sheet
|
This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production. The reference material consulted while preparing these pages is listed in the section bibliography. |
A single-page, colour-coded summary of the FastAPI essentials, written against FastAPI 0.142.2, Pydantic 2.13,
Starlette 1.7 and Python 3.10+ (versions verified 2026-10-02) — how to install and run an app (fastapi dev and
fastapi run, /docs, /redoc and /openapi.json), path operation decorators and async def versus def,
every parameter source declared with Annotated (Path, Query, Body, Header, Cookie, Form and File), Pydantic v2
models and the v1 to v2 renames, return types, response_model, errors and response classes, streaming with JSON
Lines and Server-Sent Events, Depends and yield dependencies, OAuth2 with PyJWT and pwdlib, middleware, CORS
and proxy flags, SQLModel, settings, lifespan and BackgroundTasks, APIRouter and project layout, OpenAPI
metadata, WebSockets, static files, templates and frontend(), testing, deployment, and a strip of what changed
since older tutorials — handy for quick memorization or as a
downloadable PDF desk reference.
For the full explanation, every option, and additional examples, see the dedicated pages:
Start here — Python FastAPI.
Foundations — Introduction & Architecture, Getting Started, Python Types & Annotated, and Async & Concurrency.
Request data — Path Parameters, Query Parameters, Request Body & Models, Pydantic v2 Essentials, Headers & Cookies, Forms & File Uploads, and Request Object & Content-Type.
Responses and errors — Response Models & Return Types, Status Codes & Error Handling, Custom Responses, and Streaming, JSON Lines & SSE.
Dependencies — Dependency Injection and Dependencies with yield.
Security — Security Fundamentals, OAuth2 Password Flow & JWT, OAuth2 Scopes & Authorization, and Middleware, CORS & Proxies.
Data and application structure — SQL Databases with SQLModel, NoSQL & Other Data Stores, Project Structure & Layered Architecture, and Settings, Lifespan & Background Tasks.
OpenAPI — OpenAPI & Interactive Docs.
Real-time, web and composition — WebSockets, Static Files, Templates & Frontend, and Sub-applications, WSGI & GraphQL.
Testing — Testing and Property-based & Load Testing.
Production — Deployment, Docker & Kubernetes, and Performance & Observability.
Beyond the basics — Serving Data Science & AI and What’s Changed & Migration.
References
The PDF summarizes the official documentation; each source is cited in full on the page listed above that covers it, and in the section bibliography.