1 / 11
A complete, practical guide to building production APIs with FastAPI: Pydantic v2, dependency injection, SQLAlchemy 2.0, security, async performance, testing, and deployment. 28 chapters, 4 appendices, 525 pages (PDF).
The Complete Practical Guide
Read before you buy: the PDF here is a free sample — the first 20 pages of the 525-page book (payments, sales and reviews on this demo site are sample data). Get the full e-book at thenexbooks on Gumroad.
Build FastAPI services the way production teams do — fast to write, safe to change, and ready to scale.
FastAPI makes the first endpoint effortless: type hints become validation, serialization, and interactive docs. The hard part comes later. Real APIs need a structure that survives dozens of endpoints, database access that stays correct under concurrent requests, authentication and authorization that cannot be bypassed, async code that never quietly blocks the event loop, tests you can trust, and a deployment you can observe and scale.
This book covers that whole journey, from the fundamentals of ASGI and Pydantic to a production deployment.
What's inside
- How FastAPI, Starlette, ASGI, and Pydantic fit together; a modern setup with uv and Ruff
- Path operations, parameters, request and response models, and validation with Pydantic v2
- Dependency injection with Annotated, consistent error handling with problem details, and a project structure that scales
- Pagination, filtering, file uploads, and streaming responses
- SQLAlchemy 2.0 (sync and async), Alembic migrations, transactions, and preventing double bookings
- Caching and rate limiting with Redis
- CORS, secrets, password hashing, OAuth2, JWT, scopes, and resource ownership
- Versioning, idempotency keys, ETags, and OpenAPI customization and generated clients
- Async done right, performance tuning with profiling and load testing, workers, and Uvicorn
- Background tasks, task queues, outbound HTTP with httpx, signed webhooks, WebSockets, and Server-Sent Events
- Testing with pytest, dependency overrides, async tests, and Testcontainers
- Structured logging, metrics, health checks, OpenTelemetry, Docker, Kubernetes, and CI/CD
One running example, start to finish. You build Stayloft, a fictional vacation-rental booking platform: listing search, availability without double bookings, money in integer cents, hosts vs. guests vs. admins, photo uploads, payment webhooks, and live chat.
Practical and honest. Every chapter includes realistic code, Tips, Notes, and Warnings, and ends with Key Takeaways. No invented benchmarks; performance advice explains mechanisms and shows you how to measure.
Format: PDF, 525 pages (A4), linked table of contents and bookmarks. English. First Edition, 2026. Published by thenexbooks.
Table of Contents
Part I — Foundations
- Ch 1 · Why FastAPI: The Big Picture, ASGI, and How FastAPI Works
- Ch 2 · Setting Up: Python, Virtual Environments, uv, and Project Structure
- Ch 3 · Modern Python for FastAPI: Type Hints, async/await, and Pydantic Basics
- Ch 4 · Your First API: Path Operations, Parameters, and the Interactive Docs
- Ch 5 · Request Bodies and Response Models with Pydantic v2
Part II — Building the API
- Ch 6 · Validation in Depth: Field Constraints, Custom Validators, and Settings
- Ch 7 · Dependency Injection: Depends, Sub-Dependencies, and Yield Dependencies
- Ch 8 · Error Handling: HTTPException, Custom Handlers, and Problem Details
- Ch 9 · Structuring Larger Applications: Routers, Layers, Lifespan, and Configuration
- Ch 10 · Resource Design: Pagination, Filtering, Sorting, File Uploads, and Streaming
Part III — Data and Persistence
- Ch 11 · Databases with SQLAlchemy 2.0: Models, Sessions, and Queries
- Ch 12 · Async Database Access: AsyncSession, asyncpg, and Connection Pools
- Ch 13 · Schema Migrations with Alembic and Working Well with PostgreSQL
- Ch 14 · Transactions, Concurrency, and Data Integrity
- Ch 15 · Caching with Redis: Response Caching, Rate Limiting, and Distributed Locks
Part IV — Security and API Evolution
- Ch 16 · Security Fundamentals: CORS, HTTPS, Secrets, and Safe Input Handling
- Ch 17 · Authentication: Password Hashing, the OAuth2 Password Flow, and JWT
- Ch 18 · Authorization: Roles, Scopes, and Resource Ownership
- Ch 19 · API Versioning, Idempotency, and Backward Compatibility
- Ch 20 · OpenAPI in Depth: Documenting, Customizing, and Generating Clients
Part V — Performance, Integration, and Testing
- Ch 21 · Async Done Right: The Event Loop, Blocking Code, and Concurrency
- Ch 22 · Performance Tuning: Profiling, Serialization, Workers, and Uvicorn
- Ch 23 · Background Tasks, Task Queues, Outbound HTTP, and Webhooks
- Ch 24 · Real-Time APIs: WebSockets and Server-Sent Events
- Ch 25 · Testing FastAPI: pytest, TestClient, Async Tests, Dependency Overrides, and Testcontainers
Part VI — Production and Case Study
- Ch 26 · Observability: Structured Logging, Metrics, Health Checks, and OpenTelemetry
- Ch 27 · Deployment: Docker, Process Managers, Kubernetes, and CI/CD
- Ch 28 · Case Study: Taking Stayloft to Production
Appendices
A · FastAPI Cheat Sheet
B · Templates and Reference
C · Production Checklist
D · Glossary
Book details
| Detail | |
|---|---|
| Pages | 525 |
| Format | PDF (A4) |
| Language | English |
| Level | Beginner to Advanced |
| Edition | 1st Edition (2026) |
| Download on this site | Free sample, first 20 pages (PDF) |
| Publisher | thenexbooks |
Files you get
No reviews yet. Only buyers can review.
More from thenexbooks