This repository documents my learning journey while studying FastAPI. I followed a FastAPI tutorial series and implemented the concepts step-by-step while making small adjustments of my own to better understand how things work.
The goal of this repository is simply to practice and understand FastAPI fundamentals, not to build a production application.
The lessons gradually introduce core FastAPI concepts such as:
- Basic API routes
- Query parameters
- Path parameters
- Request validation
- Pydantic models
- Nested models
- SQLModel for database models
- Database sessions
- One-to-many relationships
- Alembic migrations
- Using FastAPI's built-in Swagger and ReDoc documentation
The project is organized into lesson folders. When a major change was introduced in the tutorial (for example switching from simple schemas to database models), I created a new folder rather than constantly editing previous code. This made it easier to track my progress.
learning-fastapi
│
├── lesson2/
│ ├── main.py
│ └── schemas.py
│
├── lesson3/
│ ├── main.py
│ ├── schemas.py
│ └── api.http
│
├── lesson4/
│ ├── main.py
│ └── schemas.py
│
├── lesson5/
│ ├── main.py
│ ├── models.py
│ ├── db.py
│ ├── api.http
│ └── LEARNING_NOTES.md
│
├── data/
│ └── books.py
│
├── migration/
│ └── Alembic migration files
│
├── db.sqlite
├── requirements.txt
└── main.py
As the tutorial progressed and introduced more advanced topics, I created separate lesson folders instead of constantly rewriting earlier code. This helped me preserve each stage of learning and made it easier to compare simpler implementations with later database-backed versions.
- Basic FastAPI routes
- Path parameters
- Query parameters
- Initial schema definitions using Pydantic
- Request bodies
- POST requests
- API testing using .http files
- Improved schema validation
- Nested models
- Data validation improvements
- Organizing endpoints and schemas
- Transition from Pydantic schemas → SQLModel database models
- SQLite database integration
- One-to-many relationship between Books and Editions
- Database sessions
- Alembic migrations
- Creating and updating database schema
Some additional notes and observations from the tutorial are documented in: lesson5/LEARNING_NOTES.md
These notes helped reinforce concepts such as database sessions, model relationships, and Alembic migrations while working through the lessons.
This project is mainly for learning and practice.
Some parts are intentionally simple so I could focus on understanding FastAPI concepts step by step before moving on to larger full-stack projects.
The tutorial originally used bands and albums, but in this project I implemented a books and editions structure.
Each book can have multiple editions, and each edition belongs to a specific book.
The API exposes simple endpoints for creating and retrieving books and their editions:
GET /books
GET /books/{book_id}
POST /books
GET /genres
These endpoints demonstrate filtering, request validation, and database interaction.
The project uses SQLite for simplicity.
Database schema changes are managed using Alembic migrations.
Example migration steps used during learning:
alembic revision --autogenerate -m "initial migration"
alembic upgrade headLater, a new field (pages) was added to the Edition model to test Alembic’s auto-generated migrations.
Depending on the lesson you want to test, you may need to point Uvicorn to a different module.
Examples:
uvicorn lesson2.main:app --reload --port 8080
uvicorn lesson3.main:app --reload --port 8080
uvicorn lesson4.main:app --reload --port 8080
uvicorn lesson5.main:app --reload --port 8080Create a virtual environment:
python -m venv .venv-fastapiActivate the environment:
# Windows (Git Bash)
source .venv-fastapi/Scripts/activateInstall dependencies:
pip install -r requirements.txtRun the API server:
uvicorn lesson4.main:app --reload --port 8080Run database migrations:
alembic upgrade headFastAPI automatically generates interactive documentation.
Swagger UI:
http://localhost:8080/docs
ReDoc:
http://localhost:8080/redoc
These tools were very helpful during development for testing endpoints and understanding request/response structures.