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
Install Python, create a virtual environment, and build your very first FastAPI app with auto docs.
How FastAPI compares to Flask and Django — speed, typing, and auto-generated docs.
Validate input and shape output with Pydantic models the FastAPI way.
When to reach for Python dataclasses and when Pydantic is the right tool.
Wire up a Postgres database connection and run your first queries from FastAPI.
Use SQLModel to combine SQLAlchemy and Pydantic into one clean ORM layer.
Make multi-step writes atomic with commit/rollback and session.begin(), use savepoints, and tune the connection pool for production load.
Go fully async with SQLAlchemy 2.0 sessions and async CRUD operations.
Version and evolve your database schema safely using Alembic migrations.
Clean, reusable Create/Read/Update/Delete patterns for FastAPI endpoints.
Add limit/offset pagination and flexible query filtering to list endpoints.
Manage environment variables and typed app settings with pydantic-settings.
Understand FastAPI's dependency injection to share logic, auth, and DB sessions.
Raise clean custom exceptions and handle them globally for consistent error responses.
Organize routers, services, and repositories for a maintainable FastAPI codebase.
Build middleware for timing, request IDs, and logging — plus ordering rules.
Control exactly what your API returns with response_model — separate input/output schemas, exclude fields, nested models, and aliases.
Implement JWT authentication with access and refresh tokens in FastAPI.
Add 'Sign in with Google' with Authlib — the authorization code flow, callback handling, user upsert, and issuing your own JWT session securely.
Protect routes by role and permission using FastAPI dependencies.
Harden JWT auth with rotating refresh tokens and reuse detection — hashed tokens, token families, and automatic session revocation when a stolen token is replayed.
The big picture of authentication and security options in FastAPI.
Read, set, and secure cookies for sessions and auth in FastAPI.
Configure CORS correctly so your frontend can call your API safely.
Defend cookie-based auth against cross-site request forgery attacks.
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.
Speed up endpoints with cache-aside, TTLs, and cache invalidation using Redis.
Handle single and multiple file uploads, validation, and storage.
Run lightweight work after the response using FastAPI BackgroundTasks.
Patterns for kicking off and tracking long-running jobs from your API.
Offload heavy work to a real distributed task queue with Celery and Redis.
Build real-time features with WebSocket connections in FastAPI.
Replace print() with JSON logs, correlate every line with a request ID via contextvars, and tame uvicorn's loggers with dictConfig.
Write fast, reliable unit tests for FastAPI apps using pytest.
Test real endpoints against a real Postgres test DB with TestClient, dependency_overrides, pytest fixtures, and per-test isolation — covering CRUD and error paths.
Containerize FastAPI with a multi-stage Dockerfile and Docker Compose.
Automate lint + pytest (against a Postgres service container) on every push, and build & push a Docker image to GHCR on merge to main.
Ship your FastAPI app to production with a real deployment workflow.
Add liveness/readiness probes (and why the difference matters), expose Prometheus /metrics with the RED method, custom business metrics, and Kubernetes probe config.
The local and community angle — why FastAPI fits the PH developer scene.