A hands-on, beginner-to-production path for learning Python + FastAPI. You start from Python basics and finish with a real server-side application: database, authentication, background jobs, caching, tests, Docker, and CI/CD.
Everything is built around one example app that grows lesson by lesson. The finished version lives in app/ so you can always peek ahead or check your work.
- You know little or no Python and want a clear route to shipping backend APIs.
- You learn best by running code, breaking it, and fixing it.
No prior web or backend experience assumed.
A small "notes" API where users can register, log in, and manage their own private items. Along the way it gains:
- A SQL database via SQLModel (SQLAlchemy + Pydantic in one)
- Schema migrations with Alembic
- Token auth with JWT / OAuth2 password flow
- Background jobs with Celery + Redis, plus response caching
- A pytest suite, a Dockerfile + docker-compose, and a GitHub Actions CI pipeline
Work through docs/ in order:
| # | Lesson | You'll learn |
|---|---|---|
| 00 | Setup | Install Python, create a virtual environment, run the project |
| 01 | Python fundamentals | Variables, types, functions, classes, type hints, async |
| 02 | Your first FastAPI app | Routes, path/query params, auto docs |
| 03 | Pydantic & validation | Request/response models, settings from env |
| 04 | Database with SQLModel | Models, sessions, CRUD, dependencies |
| 05 | Migrations with Alembic | Evolving your schema safely |
| 06 | Auth: JWT & OAuth2 | Hashing, tokens, protected routes |
| 07 | Background tasks: Redis & Celery | Offloading slow work |
| 08 | Caching with Redis | Faster responses, cache invalidation |
| 09 | Testing with pytest | Fixtures, the test client, isolation |
| 10 | Docker | Containerizing the app and its services |
| 11 | CI/CD with GitHub Actions | Automated tests on every push |
| 12 | Next steps | Where to go from here |
# 1. Clone and enter the project
git clone <your-fork-url> fastapi-learning-guide
cd fastapi-learning-guide
# 2. Create and activate a virtual environment
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
# 3. Install dependencies
pip install -r requirements.txt
# 4. Copy the example environment file
cp .env.example .env
# 5. Run the API
uvicorn app.main:app --reloadOpen http://127.0.0.1:8000/docs for interactive API documentation. Try it out: register a user, click Authorize, and call the protected endpoints.
Run the tests:
pytestfastapi-learning-guide/
├── app/ # The example application (grows across lessons)
│ ├── main.py # App entrypoint
│ ├── config.py # Settings from environment
│ ├── database.py # Engine + session
│ ├── models.py # Database tables (SQLModel)
│ ├── schemas.py # Request/response shapes
│ ├── security.py # Password hashing + JWT
│ ├── deps.py # Reusable dependencies
│ ├── cache.py # Redis cache (with in-memory fallback)
│ ├── tasks.py # Celery background jobs
│ └── routers/ # Route modules: auth, users, items
├── tests/ # pytest suite
├── alembic/ # Database migrations
├── docs/ # The lessons
├── Dockerfile
├── docker-compose.yml
└── .github/workflows/ci.yml
Each lesson explains a concept, points at the relevant file(s) in app/, and gives commands to run. You don't have to type everything from scratch — read the code, run it, then change something and see what happens. That loop is where the learning happens.
MIT — see LICENSE. Free to use, share, and adapt for your own study or teaching.