FastAPI Library

FastAPI Tutorials

A hands-on, step-by-step FastAPI learning library — from your first app to production-grade auth, async databases, background tasks, and deployment.

40 tutorials · beginner → advanced

Showing 40 tutorials

FoundationsBeginner

Set Up Python & FastAPI

Install Python, create a virtual environment, and build your very first FastAPI app with auto docs.

10 minRead
FoundationsBeginner

Why FastAPI Is Better

How FastAPI compares to Flask and Django — speed, typing, and auto-generated docs.

8 minRead
FoundationsBeginner

Pydantic Request & Response Schemas

Validate input and shape output with Pydantic models the FastAPI way.

12 minRead
FoundationsBeginner

Dataclasses vs Pydantic

When to reach for Python dataclasses and when Pydantic is the right tool.

10 minRead
Data LayerBeginner

Connect FastAPI to PostgreSQL

Wire up a Postgres database connection and run your first queries from FastAPI.

14 minRead
Data LayerBeginner

FastAPI with SQLModel

Use SQLModel to combine SQLAlchemy and Pydantic into one clean ORM layer.

14 minRead
Data LayerAdvanced

Sessions, Transactions & Connection Pooling

Make multi-step writes atomic with commit/rollback and session.begin(), use savepoints, and tune the connection pool for production load.

14 minRead
Data LayerAdvanced

Async SQLAlchemy 2.0

Go fully async with SQLAlchemy 2.0 sessions and async CRUD operations.

18 minRead
Data LayerIntermediate

Database Migrations with Alembic

Version and evolve your database schema safely using Alembic migrations.

14 minRead
Data LayerIntermediate

CRUD Patterns

Clean, reusable Create/Read/Update/Delete patterns for FastAPI endpoints.

14 minRead
Data LayerIntermediate

Pagination & Filtering

Add limit/offset pagination and flexible query filtering to list endpoints.

12 minRead
Data LayerIntermediate

Config with pydantic-settings

Manage environment variables and typed app settings with pydantic-settings.

10 minRead
Core SkillsIntermediate

Mastering Depends() — Dependency Injection

Understand FastAPI's dependency injection to share logic, auth, and DB sessions.

14 minRead
Core SkillsIntermediate

Custom Exceptions & Global Error Handlers

Raise clean custom exceptions and handle them globally for consistent error responses.

12 minRead
Core SkillsIntermediate

Scalable Project Structure

Organize routers, services, and repositories for a maintainable FastAPI codebase.

16 minRead
Core SkillsIntermediate

Custom Middleware & Request Lifecycle

Build middleware for timing, request IDs, and logging — plus ordering rules.

12 minRead
Core SkillsIntermediate

Response Models — Shape Output & Stop Data Leaks

Control exactly what your API returns with response_model — separate input/output schemas, exclude fields, nested models, and aliases.

12 minRead
Auth & SecurityIntermediate

JWT Access & Refresh Tokens

Implement JWT authentication with access and refresh tokens in FastAPI.

16 minRead
Auth & SecurityAdvanced

OAuth2 Social Login with Google

Add 'Sign in with Google' with Authlib — the authorization code flow, callback handling, user upsert, and issuing your own JWT session securely.

16 minRead
Auth & SecurityIntermediate

Role-Based Access Control (RBAC)

Protect routes by role and permission using FastAPI dependencies.

14 minRead
Auth & SecurityAdvanced

Secure Refresh Token Rotation

Harden JWT auth with rotating refresh tokens and reuse detection — hashed tokens, token families, and automatic session revocation when a stolen token is replayed.

14 minRead
Auth & SecurityIntermediate

Security & Authentication Overview

The big picture of authentication and security options in FastAPI.

14 minRead
Auth & SecurityIntermediate

Cookie Handling

Read, set, and secure cookies for sessions and auth in FastAPI.

10 minRead
Auth & SecurityBeginner

CORS Setup

Configure CORS correctly so your frontend can call your API safely.

8 minRead
Auth & SecurityIntermediate

CSRF Protection

Defend cookie-based auth against cross-site request forgery attacks.

12 minRead
Auth & SecurityIntermediate

Rate Limiting with slowapi

Stop brute-force and abuse: add per-route and global rate limits with slowapi, key by IP or API key, return 429 + Retry-After, and back it with Redis.

12 minRead
PerformanceAdvanced

Caching Responses with Redis

Speed up endpoints with cache-aside, TTLs, and cache invalidation using Redis.

15 minRead
Features & TasksIntermediate

File Uploads

Handle single and multiple file uploads, validation, and storage.

12 minRead
Features & TasksIntermediate

Background Tasks

Run lightweight work after the response using FastAPI BackgroundTasks.

10 minRead
Features & TasksAdvanced

Long-Running Tasks

Patterns for kicking off and tracking long-running jobs from your API.

14 minRead
Features & TasksAdvanced

Distributed Task Queue with Celery + Redis

Offload heavy work to a real distributed task queue with Celery and Redis.

18 minRead
Features & TasksAdvanced

WebSockets

Build real-time features with WebSocket connections in FastAPI.

14 minRead
Ops & MetaIntermediate

Structured Logging & Observability

Replace print() with JSON logs, correlate every line with a request ID via contextvars, and tame uvicorn's loggers with dictConfig.

12 minRead
Ops & MetaIntermediate

Unit Testing with pytest

Write fast, reliable unit tests for FastAPI apps using pytest.

14 minRead
Ops & MetaAdvanced

Integration Testing with a Test Database

Test real endpoints against a real Postgres test DB with TestClient, dependency_overrides, pytest fixtures, and per-test isolation — covering CRUD and error paths.

16 minRead
Ops & MetaIntermediate

Dockerizing FastAPI

Containerize FastAPI with a multi-stage Dockerfile and Docker Compose.

16 minRead
Ops & MetaIntermediate

CI/CD with GitHub Actions

Automate lint + pytest (against a Postgres service container) on every push, and build & push a Docker image to GHCR on merge to main.

14 minRead
Ops & MetaAdvanced

Deployment

Ship your FastAPI app to production with a real deployment workflow.

16 minRead
Ops & MetaAdvanced

Health Checks & Prometheus Metrics

Add liveness/readiness probes (and why the difference matters), expose Prometheus /metrics with the RED method, custom business metrics, and Kubernetes probe config.

12 minRead
Ops & MetaAll levels

FastAPI in the Philippines

The local and community angle — why FastAPI fits the PH developer scene.

8 minRead