FastAPI uses ordinary Python type hints to validate requests, serialise responses and generate interactive API documentation automatically. It has become a common choice for API-first services, internal tools and the backends behind AI and machine learning features, because so much of that ecosystem is already in Python. This course builds a complete, typed API and shows how to keep it maintainable as it grows past a single file.

What you'll learn

  • How FastAPI uses type hints, and what Pydantic does with them
  • Path operations, query and path parameters, request bodies and response models
  • Validation, custom validators and clear error responses
  • Dependency injection for database sessions, settings and the current user
  • When async helps, when it does not, and how to avoid blocking the event loop
  • Working with PostgreSQL through SQLAlchemy or SQLModel, with Alembic migrations
  • Authentication with OAuth2 password flow and JWTs, plus API keys for service clients
  • Background tasks, streaming responses and calling external APIs, including LLM providers
  • Structuring a larger app with routers and settings management
  • Testing with pytest and the test client, then deploying with a production server and containers

Who it's for

  • Python developers who want to build modern, well-documented APIs
  • Data scientists and ML engineers who need to put models or AI features behind an API
  • Teams moving from Flask or ad hoc scripts to a typed, structured backend

Prerequisites

  • Comfortable with Python, including functions, classes and type hints (our Python for Automation course covers the basics)
  • Basic understanding of HTTP, JSON and SQL
  • Python 3 installed; Docker is useful for the database modules

Outcomes

By the end of this course you will be able to:

  1. Build a FastAPI service with typed requests, responses and automatic documentation.
  2. Use dependencies to share database sessions, configuration and authentication cleanly.
  3. Connect the API to PostgreSQL with migrations and safe async patterns.
  4. Test, containerise and deploy the service.

Projects you'll build

  • Bookings API - A REST API for a small appointment system with Pydantic request and response models, pagination and filtering. You practise path operations, validation and keeping the generated OpenAPI docs accurate.
  • Authenticated multi-tenant backend - The same API extended with OAuth2 password flow, JWT access tokens, per-tenant data isolation through dependencies and Alembic migrations on PostgreSQL. You practise dependency injection and async database sessions.
  • Streaming AI endpoint - An endpoint that calls an LLM API, streams the reply to the client with server-sent events and logs usage in a background task. You practise async I/O, timeouts and error handling against an external service.

Tools you'll use

  • Python 3.12+, FastAPI and Pydantic v2
  • Uvicorn, with Gunicorn or a container runtime for production
  • SQLAlchemy 2.0 or SQLModel, Alembic and PostgreSQL
  • pytest, HTTPX and the FastAPI TestClient
  • uv for dependency management, Ruff for linting
  • Docker for packaging and deployment

Course outline

ModuleTopic
1FastAPI setup, type hints and the interactive docs
2Path operations, parameters and request bodies
3Pydantic models, validation and response models
4Dependency injection
5Async and sync code: when to use each
6Databases with SQLAlchemy or SQLModel and Alembic
7Authentication: OAuth2, JWTs and API keys
8Error handling, middleware and CORS
9Background tasks, streaming and calling external APIs
10Structuring larger apps with routers and settings
11Testing with pytest
12Deployment: servers, containers and configuration

FAQ

Is FastAPI really faster than other Python frameworks?

It performs well for I/O-heavy APIs, but in most real apps the database and external calls matter more than the framework. We focus on the habits that actually affect speed.

Can I use FastAPI to serve AI features?

Yes, it is a common choice. One module covers calling LLM APIs and streaming responses; Building AI Apps with LLM APIs goes deeper into the AI side.

FastAPI or Django?

FastAPI suits lean, API-first services. Django suits projects that need an admin panel and a full set of built-in features. See Django and Django REST Framework for the other path.

What mistakes do beginners make with FastAPI?

The most common are declaring routes with async def and then calling blocking database or HTTP libraries inside them, which stalls the whole server, and returning ORM objects without a response model, which leaks fields such as password hashes. Both are covered early, with tests that catch them.

How do I join?

Get in touch and we'll share the current format, schedule and enrolment details.