FastAPI and PostgreSQL: build a production ready API

Pydantic models, SQLAlchemy 2.0, Alembic migrations, authentication, background work, tests, Docker and deployment in one service

8 ratings 2,870 students Sample

Created by Lukas Brenner

  • Updated September 2026
  • English
  • Intermediate

What you will learn

  • Structure a FastAPI project with routers, dependencies and settings
  • Validate requests and shape responses with Pydantic v2 models
  • Model data and query PostgreSQL with SQLAlchemy 2.0
  • Manage schema changes safely with Alembic migrations
  • Implement authentication with hashed passwords and JWT access tokens
  • Test the API against a real database and deploy it in Docker

Course content

6 sections, 26 lessons, 4h 38m total

FastAPI fundamentals 5 lessons · 50 min
  • Video: What we are building and the stack Preview 8 min
  • Article: Project setup and the first endpoints Preview 12 min
  • Article: Pydantic models for requests and responses 13 min
  • Article: Dependencies and request scoped resources 12 min
  • Quiz: Check your understanding 5 min
PostgreSQL with SQLAlchemy 2.0 5 lessons · 59 min
  • Article: Running PostgreSQL in Docker 9 min
  • Video: Declarative models with type hints 13 min
  • Video: Async engine, sessions and transactions 12 min
  • Video: Querying with select and relationships 13 min
  • Video: Migrations with Alembic 12 min
Authentication and permissions 4 lessons · 43 min
  • Article: Hashing passwords properly 9 min
  • Video: JWT access tokens 13 min
  • Video: Organisation scoped access 12 min
  • Video: Roles and admin actions 9 min
API features users expect 4 lessons · 44 min
  • Video: Cursor pagination and filtering 12 min
  • Video: Consistent errors and exception handlers 10 min
  • Video: File uploads to object storage 11 min
  • Video: Background tasks and task queues 11 min
Testing the API 3 lessons · 34 min
  • Video: Test setup with a real database 12 min
  • Video: Testing endpoints with httpx 12 min
  • Video: Testing permissions and edge cases 10 min
Deployment and operations 5 lessons · 48 min
  • Video: A production Docker image 12 min
  • Video: Configuration, logging and health checks 10 min
  • Video: Running migrations and deploying 11 min
  • Video: Observability with OpenTelemetry 10 min
  • Quiz: Final check 5 min

Requirements

  • Solid Python, including classes and type hints
  • Basic SQL and HTTP knowledge
  • Docker installed for the database and deployment sections

Description

FastAPI is one of the most popular Python web frameworks for building APIs. It is fast to write, uses standard Python type hints for validation and generates interactive documentation automatically. Getting a demo running takes minutes. Getting a service ready for real users takes a lot more: a proper database layer, migrations, authentication, error handling, tests, configuration, logging and deployment.

This course covers that whole path. We build Taskboard, an API for team task management with organisations, projects, tasks, comments and file attachments, and we take it all the way to a containerised deployment.

What you will build and learn

  • Project structure that stays manageable as the API grows
  • Request and response models with Pydantic v2
  • PostgreSQL access with SQLAlchemy 2.0, sessions and relationships
  • Database migrations with Alembic
  • Password hashing, JWT access tokens and permission checks
  • Pagination, filtering and consistent errors
  • Background tasks and when to use a proper task queue
  • Testing with pytest against a real database
  • Docker images, configuration, logging and health checks

Approach

We write synchronous and asynchronous code where each makes sense, and I explain the trade offs rather than declaring one correct. Every section ends with a working, tested API, and the repository has a tag per lesson.

You should know Python well, including classes and type hints, and understand HTTP and SQL basics.

Who this course is for

  • Python developers building their first serious API
  • Flask or Django developers evaluating FastAPI
  • Data engineers who need to expose data through an API

Instructor

Lukas Brenner

Backend engineer teaching API design, Python services and testing that catches real bugs

  • 4.4 instructor rating
  • 22 reviews
  • 7,060 students
  • 3 courses
  • Sample

I design and build backend services and APIs, mostly in Python with FastAPI and PostgreSQL. A large part of my job is reviewing API contracts, writing tests and figuring out why something that worked on a laptop fails in production.

My courses are opinionated but honest about trade offs. I show the approach I use, explain the alternatives and point out when the alternative is the better choice for your situation.

I like small, boring, well tested systems. If you finish one of my courses with a habit of writing a failing test before a fix, I consider that a success.

View profile

Student reviews

4.4 8 ratings
5 star 50%
4 star 38%
3 star 13%
2 star 0%
1 star 0%
Dominik Z. Oct 1, 2026
Sample

Docker and deployment covered well

The multi stage Dockerfile with uv is now our template for every Python service.

Martina G. Sep 21, 2026
Sample

From demo to production

Every FastAPI tutorial stops at a demo. This one covered migrations, auth, tests and Docker properly.

Ola B. Aug 24, 2026
Sample

SQLAlchemy 2.0 explained clearly

The typed models and selectinload explanation saved me from an N plus one problem in my own project.

Luis M. Aug 20, 2026
Sample

OpenTelemetry was a nice bonus

I did not expect observability to be covered. Found a slow query in my own app the same day.

Rajesh N. Jul 24, 2026
Sample

Very complete and well organised

Lots of material and all of it relevant. The async explanation could use one more diagram.

Clara V. Jun 28, 2026
Sample

Organisation scoping is gold

Building tenant scoping into the service layer is exactly the advice I needed for our SaaS backend.

Yusuf T. May 29, 2026
Sample

Good testing section

Transaction rollback per test plus dependency overrides made our tests fast and reliable.

Ellie P. Apr 14, 2026
Sample

Assumes strong Python

Make sure you are comfortable with type hints and async before starting. Otherwise excellent.

$69.99 Enroll now
SampleSample catalog: the instructors, courses, reviews and stats on this site are demo content.