Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Learning FastAPI

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.


What This Project Covers

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

Project Structure

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

Why I Structured It This Way

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.

Lessons Overview

Lesson 2

  • Basic FastAPI routes
  • Path parameters
  • Query parameters
  • Initial schema definitions using Pydantic

Lesson 3

  • Request bodies
  • POST requests
  • API testing using .http files
  • Improved schema validation

Lesson 4

  • Nested models
  • Data validation improvements
  • Organizing endpoints and schemas

Lesson 5

  • 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

Learning Notes

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.

Notes

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.


Example Data Model

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.


Example API Endpoints

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.


Database

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 head

Later, 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 8080

Installation and Running the Project

Create a virtual environment:

python -m venv .venv-fastapi

Activate the environment:

# Windows (Git Bash)
source .venv-fastapi/Scripts/activate

Install dependencies:

pip install -r requirements.txt

Run the API server:

uvicorn lesson4.main:app --reload --port 8080

Run database migrations:

alembic upgrade head

API Documentation

FastAPI 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.

About

FastAPI learning project covering routes, validation, SQLModel, relationships, and Alembic migrations.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages