python-fastapi
FastAPI conventions: pydantic v2, async-first endpoints, dependency injection, OpenAPI hygiene.
npx rulepack add python-fastapi
What it covers
- Tooling baseline: Python 3.12+,
uv/pdmfor env+lock, type hints everywhere (mypy --strict), Pydantic v2 (model_dump(), not.dict()) - Async-first endpoints:
async defhandlers by default, withasyncio.to_thread()(or a sync route) instead of blocking the event loop with sync I/O - Typed request/response contracts: Pydantic models for bodies plus
response_modelso the generated OpenAPI stays accurate - Explicit parameter and error handling:
Annotated[..., Path(...)]/Annotated[..., Query(...)]over bare defaults, andHTTPExceptionwith explicitstatus_code+detail - A framework-agnostic project shape (
routers/,schemas/,services/,deps.py) with dependency injection instead of mutable global state
Source
Rules align with the official FastAPI documentation: https://fastapi.tiangolo.com/
License
MIT