| name | fastapi |
| description | FastAPI mastery skill. Covers Pydantic models, DI,
async DB access, background tasks, WebSocket, testing.
Triggers on: /godmode:fastapi, "fastapi", "pydantic",
"async api", "python api".
|
FastAPI — FastAPI Mastery
Activate When
- User invokes
/godmode:fastapi
- User says "build a FastAPI app", "async API"
- User asks about Pydantic, DI, async endpoints
- When working with Python async backend services
- User says "fastapi route", "FastAPI endpoint", "route for orders"
Workflow
Step 1: Project Assessment
grep -l "fastapi" pyproject.toml requirements.txt \
setup.py 2>/dev/null
python3 --version
ls uv.lock poetry.lock Pipfile.lock 2>/dev/null
FASTAPI ASSESSMENT:
FastAPI version: <0.115.x>
Python: <3.12+ recommended>
ORM: SQLAlchemy 2.0 async | Tortoise | SQLModel
Auth: JWT | OAuth2 | API keys
Package manager: uv (preferred) | Poetry | pip
IF Python < 3.12: recommend upgrade for performance
IF using sync psycopg2: must migrate to asyncpg
IF no Alembic: add migration support immediately
PROJECT STRUCTURE:
app/
├── main.py # FastAPI app factory
├── config.py # pydantic-settings
├── dependencies.py # Shared DI (DB, auth)
├── api/v1/
│ ├── router.py # Aggregates all v1 routes
│ ├── orders.py # Order endpoints
│ └── customers.py # Customer endpoints
├── models/ # SQLAlchemy models
├── schemas/ # Pydantic schemas
├── services/ # Business logic
└── tests/
Step 2: Pydantic Model Design
PYDANTIC PATTERNS:
| Pattern | Usage |
|--------------------------|---------------------|
| Separate Create/Update/Resp | Per-operation |
| field_validator | Single-field custom |
| model_validator | Cross-field logic |
| Field(gt=0, max_length) | Declarative limits |
| from_attributes=True | ORM → Pydantic |
| Generic PaginatedResp[T] | Reusable pagination|
THRESHOLDS:
max_length for strings: always set (default 255)
gt=0 for IDs and counts: always set
le=1000 for pagination page_size: prevent abuse
IF no Field() constraints: validation is incomplete