Comprehensive FastAPI development skill for building APIs from hello world to production-ready applications. Use when building REST APIs, microservices, ML/AI APIs, or full-stack applications with FastAPI. Covers project scaffolding, database integration (PostgreSQL, MySQL, MongoDB, SQLite), testing, Docker deployment, background tasks, file uploads, and production best practices.
Build production-ready APIs with FastAPI, from simple hello world to complex microservices.
This skill provides everything needed to build FastAPI applications:
Choose your starting point based on what you're building:
First time with FastAPI?
→ Use assets/hello-world/main.py template (5 minutes)
→ Run fastapi dev main.py and explore
Building a simple CRUD API?
→ Use assets/crud-api-template/ (15 minutes)
→ Modify schemas in schemas.py for your data model
Starting a new project from scratch?
→ Use scripts/scaffold_project.py to generate full project structure
→ Choose project type: simple-api, microservice, fullstack, or ml-api
Adding specific features to existing project?
→ Database: See references/databases.md
→ Testing: See references/testing.md
→ Docker: See references/docker.md
→ Background tasks: See references/background_tasks.md
→ File uploads: See references/file_uploads.md
Copy assets/hello-world/main.py to your project:
cp assets/hello-world/main.py .
pip install -r assets/hello-world/requirements.txt
fastapi dev main.py
Copy the CRUD template for a complete REST API:
cp -r assets/crud-api-template/* .
pip install -r requirements.txt
fastapi dev main.py
This gives you:
Generate a complete project structure:
python scripts/scaffold_project.py my-api --type simple-api --database postgresql
Project types:
simple-api - Basic REST API with CRUDmicroservice - Microservice with health checksfullstack - Full-stack with frontend integrationml-api - ML/AI API with model servingOptions:
--database - postgresql, mysql, sqlite, mongodb--docker - Include Docker configuration--testing - Include pytest setupFor PostgreSQL, MySQL, or SQLite (SQL databases):
references/databases.md for your database typeFor MongoDB (NoSQL):
references/databases.md MongoDB sectionpip install motor beanie# 1. Configure database (references/databases.md)
# 2. Define models
# 3. Create CRUD service functions
# 4. Use in endpoints with Depends(get_db)
The scaffolding script (scripts/scaffold_project.py) automatically generates this structure when you specify --database.
To add comprehensive testing to your project:
references/testing.mdpip install pytest pytest-asyncio httpxtests/conftest.py with test client fixturetests/ directorypytest --cov=app tests/Key patterns from testing.md:
To containerize your application:
references/docker.mddocker-compose up --buildFor production:
For async job processing:
Simple tasks (same process):
BackgroundTasksreferences/background_tasks.md → FastAPI Background TasksProduction tasks (distributed):
references/background_tasks.md → Celery sectionModern async tasks:
references/background_tasks.md → ARQ sectionTo handle file uploads:
references/file_uploads.mdKey patterns:
Before deploying to production:
Database
Security
Performance
Monitoring
Docker
references/docker.md)See references/docker.md → Production Optimization for:
# app/core/config.py
from pydantic_settings import BaseSettings
class Settings(BaseSettings):
DATABASE_URL: str
REDIS_URL: str
SECRET_KEY: str
class Config:
env_file = ".env"
settings = Settings()
scaffold_project.py - Generate complete project structures
python scripts/scaffold_project.py --helpdatabases.md - Complete database integration guide
testing.md - Comprehensive testing patterns
docker.md - Docker deployment guide
background_tasks.md - Async job processing
file_uploads.md - File handling patterns
hello-world/ - Minimal FastAPI application
crud-api-template/ - Complete CRUD API
cp -r assets/crud-api-template/* .schemas.py with your data modelmain.py with your business logicfastapi dev main.pypython scripts/scaffold_project.py myapi --database postgresql.env with database credentialsapp/models/app/schemas/app/services/app/api/endpoints/alembic upgrade headAdd Database:
references/databases.md for your DB typeapp/core/database.py with configurationget_db dependency to endpointsAdd Testing:
references/testing.mdtests/conftest.pytests/pytestAdd Docker:
references/docker.mddocker-compose upreferences/docker.md)docker-compose -f docker-compose.prod.yml up -d