This is a comprehensive FastAPI course that takes you from the basics to building full-fledged web applications with authentication.
- Python 3.12 or higher
- Basic understanding of Python
- Familiarity with HTTP and REST APIs (helpful but not required)
The course is organized into daily lessons, each building upon the previous one. Each day contains:
- Code examples in
main.pyand other relevant files - Templates (for days involving HTML rendering)
- A
pyproject.tomlfile with dependencies - A
README.mdwith specific topics covered that day
- Introduction to client-server model
- Basic FastAPI setup
- Creating API endpoints
- Basic routing
- Path parameters with validation
- Query parameters
- POST method with JSON and form data
- Swagger UI introduction
- Updating resources with PUT
- Deleting resources with DELETE
- Enhanced Swagger UI with tags and examples
- Building a complete Product API
- Using slugs
- HTTP exceptions and status codes
- Type validation and conversion
- Field validation
- Default values and optional fields
- Nested models and validators
- Model inheritance and aliases
- Request and response models
- JSONResponse and HTMLResponse
- Introduction to Jinja2 templating
- Building web interfaces with templates
- Complete CRUD operations with HTML forms
- Database setup with PostgreSQL
- SQLAlchemy ORM
- Combining FastAPI with databases and templates
- Full blog application
- Jinja2 templates with PostgreSQL
- Foreign keys
- One-to-many relationships
- Response models
- Error handling with try-except
- Splitting code into modules
- Environment variables
- JWT overview
- Password hashing
- JSON Web Tokens (JWT)
- User authentication and authorization
Each day is self-contained with its own dependencies. To run a specific day's code:
-
Navigate to the day's directory:
cd dayX -
Install dependencies using uv (recommended):
uv sync
Or using pip:
pip install -r requirements.txt # if present # or pip install -e .
-
Run the application:
uv run uvicorn main:app --reload
Or if using pip:
uvicorn main:app --reload
-
Open your browser to
http://127.0.0.1:8000to see the API documentation.
For days 12-14, you'll need PostgreSQL:
- Install PostgreSQL
- Create a database
- Update the connection string in the code (usually in
database.py)
Feel free to submit issues or pull requests if you find any errors or have suggestions for improvements.
This course is provided as-is for educational purposes.