Full standards in python-fastapi.md. Always-on summary:
Routing and structure:
- Use
APIRouterwithprefix="/users"(explicitprefix=) andtags; mount routers inmain.pywithapp.include_router() - Return typed response models via
response_model=— never return raw dicts from endpoints - Use
status_code=status.HTTP_201_CREATED(or appropriate) on every route decorator
Pydantic models:
- Separate
CreateSchema,UpdateSchema, andReadSchema; never expose ORM models directly - Use
model_config = ConfigDict(from_attributes=True)for ORM serialization - Validate at the boundary — put business logic in services, not schemas
Dependency injection:
- Inject DB sessions via
Depends(get_db)— never create sessions inside route functions - Use
Annotated[T, Depends(fn)]syntax (FastAPI 0.95+) for cleaner signatures - Raise
HTTPExceptionin dependencies; FastAPI propagates them automatically
Async:
- Use
async deffor all I/O-bound endpoints; usedeffor CPU-bound work (runs in threadpool) - Never call blocking I/O (requests, psycopg2, etc.) from
async def— use async drivers
OpenAPI and error handling:
- Add
summary=,description=, andresponses=to all public endpoints - Define a global exception handler for unhandled errors; return
{"detail": ...}envelopes
Never:
- Never import
appdirectly in sub-modules — useAPIRouterand mount - Never use
Optional[X]without a default; preferX | None = None(Python 3.10+) - Never block the event loop with synchronous sleeps — use
await asyncio.sleep()
Related skills: error-handling, logging-standards, database-sql, api-conventions
Source: manikumarkv/devrunway-claude-plugin — distributed by TomeVault.