FastAPI in Production

Production FastAPI

This article summarizes a tutorial on best practices for setting up a production-sound FastAPI service. Find the tutorial here. This is an overview on the product structure.

├── app
│  ├── __init__.py
│  ├── api                     
│  │  ├── __init__.py
│  │  ├── api_v1               
│  │  │  ├── __init__.py
│  │  │  ├── api.py            
│  │  │  └── endpoints         
│  │  │     ├── __init__.py
│  │  │     └── recipe.py      
│  │  └── deps.py
│  ├── backend_pre_start.py
│  ├── core                    
│  │  ├── __init__.py
│  │  └── config.py            
│  ├── crud
│  │  ├── __init__.py
│  │  ├── base.py
│  │  ├── crud_recipe.py
│  │  └── crud_user.py
│  ├── db
│  │  ├── __init__.py
│  │  ├── base.py
│  │  ├── base_class.py
│  │  ├── init_db.py
│  │  └── session.py
│  ├── initial_data.py
│  ├── main.py
│  ├── models
│  │  ├── __init__.py
│  │  ├── recipe.py
│  │  └── user.py
│  ├── schemas
│  │  ├── __init__.py
│  │  ├── recipe.py
│  │  └── user.py
│  └── templates
│     └── index.html
├── poetry.lock
├── prestart.sh
├── pyproject.toml
├── README.md
└── run.sh

A Key Data Flow Example

API Directory - Error Handling (Part 5)

Schemas Directory - Pydantic (Part 4)

Key benefits include eliminating the need to learn a specialized syntax (making it IDE-friendly), validating both request/response data and configuration settings, customizable data types, integration with Python dataclasses, and exceptional performance.

DB Directory - SQLAlchemy (Part 6)

Directory CRUD - CRUD Utilities (Part 6)

Diretory Alembic: Managing Change (Part 6)

API Versioning: Why It Matters (Part 8)

Understanding Asynchronous Code (Part 9)

Authentication and Authorization (Part 10)

Practical Implementation

  1. Signup Endpoint
  1. Password Handling
  1. Login Endpoint
  1. Authentication Middleware

Areas for Further Exploration

Dependency Injection (Part 11)

Examples: Learning by Doing

You guide us through a series of excellent examples:

Testing Power Unleashed