FastAPI
Typed, async API framework built on type hints.
FastAPI is taught here in 12 lessons, running from Your first FastAPI app through to Deployment: uvicorn workers, Docker and reverse proxies. Each lesson takes one topic, shows the working code, and links onward to the next, so the course can be read straight through in order.
| Track | Python & Data Science |
| Lessons | 12 |
| Level | Beginner to intermediate |
| Reading time | about 3 hours |
| Prerequisites | Helpful, but not required: Flask |
Lessons
- Your first FastAPI appPath operations, type-driven validation, automatic OpenAPI docs, and the route-ordering trap that silently returns 422 instead of 404.
- Pydantic request and response modelsDefine the wire contract with Pydantic: validation, custom validators, and response models that stop internal fields leaking out of your API.
- Dependencies and asyncReusable dependencies with Depends, yield-based resource cleanup, and the blocking-call mistake that stalls an entire async worker.
- Path, query and body parameters in depthControl every input your API accepts: typed path segments, enums, query aliases and validation, body embedding, and the modern Annotated style.
- Routers, project layout and API versioningSplit a growing application into modules with APIRouter, share prefixes and dependencies, and introduce /api/v1 without breaking existing clients.
- Databases with SQLAlchemy and session dependenciesModel tables with SQLAlchemy 2.0, give every request its own session, commit explicitly, and stop lazy loading from breaking async endpoints.
- Authentication with OAuth2, JWT and password hashingHash passwords safely, issue and verify JSON Web Tokens, read the current user from a dependency, and use scopes to gate endpoints.
- Error handling, middleware and CORSReturn consistent error shapes, log unhandled exceptions, time requests with middleware, and configure CORS so browsers can actually call your API.
- File uploads, streaming and WebSocketsAccept uploads without running out of memory, stream large responses, serve static files, and add a WebSocket endpoint with proper disconnect handling.
- Background tasks and lifespan eventsRun work after the response with BackgroundTasks, own your resources with the lifespan context manager, and know when a real queue is required.
- Testing FastAPI apps with TestClient and pytestExercise endpoints without a running server, swap the database per test, write async tests with httpx, and assert the response shape rather than the whole body.
- Deployment: uvicorn workers, Docker and reverse proxiesRun more than one worker safely, configure settings from the environment, write a real Dockerfile, and place the app behind a reverse proxy.
More in Python & Data Science
Python 3 NumPy pandas Matplotlib Jupyter Notebook Flask Django SciPy Pillow Python 2.x R Julia
FAQ
How long does the FastAPI course take?
It has 12 lessons, about 3 hours of reading. Expect roughly twice that if you type out and run every example.
Do I need prior experience for FastAPI?
Not strictly. It helps to have read Flask first, because some lessons build on it, but every lesson explains its own assumptions.
What should I read after FastAPI?
Continue with Django (12 lessons), the next course in Python & Data Science.