# FastAPI From Zero

FastAPI is the framework that made building Python APIs feel modern. You write a function with type
hints, and FastAPI gives you - for free - request parsing, data validation, JSON serialization, and a
complete interactive API documentation page. That "for free" isn't marketing: it falls directly out of
one clever idea, which is that your **Python type hints become the single source of truth** for how the
API behaves. Learn that idea and FastAPI stops being a bag of decorators and becomes predictable.

This guide builds the mental model first the whole way: why type hints drive everything, what Pydantic is
doing under each model, how the `Depends()` system turns dependency injection into plain functions, and
when `async` actually helps (and when it quietly hurts). By the end you'll build a real, validated,
authenticated, tested API and understand every layer.

> 📝 This teaches the **framework**. It assumes you know **Python** - functions, classes, and especially
> **type hints** ([Python From Zero](/guides/python-from-zero) covers them; FastAPI leans on them hard).
> Helpful background: [REST APIs Explained](/guides/rest-apis-explained) and
> [What a Framework Even Is](/guides/what-a-framework-even-is).

## How to read this

Read in order - it builds one API (a small book service) and adds a layer per phase. Many pure-Python
snippets here are **runnable right on the page** (Pydantic models, validation); FastAPI app code that
needs a running server is shown with the commands to run it yourself. Phases carry difficulty badges.

## The phases

**Part 1 - The core (🟢 Basic)**
1. **[What FastAPI Is & Your First App](01-what-fastapi-is.md)** 🟢 - ASGI, your first endpoint, `uvicorn`, and the automatic interactive docs.
2. **[Path Operations & Parameters](02-path-operations-and-parameters.md)** 🟢 - routes, path and query parameters, and how type hints parse and validate them.
3. **[Pydantic Models & Validation](03-pydantic-models-and-validation.md)** 🟢 - request bodies as models, and validation that comes free from your types.

**Part 2 - A real application (🟡 Intermediate)**
4. **[Response Models & Status Codes](04-response-models-and-status-codes.md)** 🟡 - shaping output, hiding internal fields, and correct HTTP statuses.
5. **[Dependency Injection with Depends()](05-dependency-injection.md)** 🟡 - reusable dependencies for auth, DB sessions, and shared logic.
6. **[Async & Concurrency](06-async-and-concurrency.md)** 🟡 - `async def` vs `def`, when async helps, and the trap that blocks the event loop.
7. **[Databases with SQLModel](07-databases-with-sqlmodel.md)** 🟡 - persistence, sessions via dependencies, and CRUD.

**Part 3 - Production (🔴 Advanced → 🟢)**
8. **[Authentication & Security](08-authentication-and-security.md)** 🔴 - OAuth2 password flow, JWT, and security as dependencies.
9. **[Testing & Project Structure](09-testing-and-project-structure.md)** 🟡 - `TestClient`, pytest, and structuring a real project with routers.
10. **[Production & Where to Go Next](10-where-to-go-next.md)** 🟢 - deployment, background tasks, async pitfalls, and what to build.

> The whole framework rests on one idea: **types are the contract.** Once you see that, validation, docs,
> serialization, and DI all stop being separate features and become one coherent thing.
