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.

Dependencies — Dependency Injection and Dependencies with yield.

OpenAPI — OpenAPI & Interactive Docs.

Testing — Testing and Property-based & Load Testing.

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.