Help us improve
Share bugs, ideas, or general feedback.
From ai-toolkit
Provides Python/FastAPI best practices: layered architecture, Pydantic v2 schemas, async patterns, SQLAlchemy 2.0, soft deletes, pagination, config. Use for writing code or reviewing FastAPI projects.
How this skill is triggered — by the user, by Claude, or both
Slash command
/ai-toolkit:python-best-practicesThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Router → Service → Repository → Database. Each layer only calls the one below it.
Share bugs, ideas, or general feedback.
Router → Service → Repository → Database. Each layer only calls the one below it.
See code-patterns.md for full project structure and layer examples.
Separate Create/Update/Response schemas. Use ConfigDict(from_attributes=True) for ORM integration. Use str | None syntax (not Optional[str]).
See code-patterns.md for schema examples.
async def for I/O routes, plain def for CPU-bound. Use lifespan context manager (not on_event). Use httpx.AsyncClient for external HTTP calls.
See code-patterns.md for async examples.
Use a SoftDeleteMixin on SQLAlchemy models. Filter where(Model.deleted_at.is_(None)) in all queries.
See code-patterns.md for mixin and repository patterns.
Use pydantic-settings for all config. Never hardcode secrets, URLs, or magic numbers.
See code-patterns.md for Settings class pattern.
Use a generic PaginatedResponse[T] for all list endpoints. Always return total, page, limit, has_more.
See code-patterns.md for the pattern.
async def vs def matters for performance. An async def route that calls blocking code (like time.sleep() or sync DB drivers) blocks the entire event loop. Use plain def for CPU-bound work — FastAPI runs it in a threadpool. Use async def only when you await something.
datetime.utcnow() is deprecated since Python 3.12. Use datetime.now(UTC) instead. The old function returns a naive datetime (no timezone), which causes comparison bugs. The new one returns timezone-aware UTC.
Mutable default arguments in Pydantic look safe but have a catch. tags: list[str] = [] works in Pydantic (it copies the default). But tags: list[str] = Field(default_factory=list) is explicit and safer for nested models. For simple fields, either works. For complex nested defaults, always use default_factory.
from_attributes=True replaces orm_mode=True. Pydantic v2 changed the config API. Using the old orm_mode silently does nothing — your ORM objects won't serialize correctly.
SQLAlchemy Column() is legacy. Use Mapped[type] with mapped_column() for SQLAlchemy 2.0. The old Column(String) still works but loses type checker support and IDE autocomplete.
npx claudepluginhub c0x12c/ai-toolkit --plugin ai-toolkitProvides FastAPI patterns and best practices for architecture, SQLAlchemy databases, JWT/OAuth2 security, Pydantic validation, pytest testing, and async performance. Auto-activates on FastAPI projects.
Provides expert Python backend patterns for Django, FastAPI, Flask: Pydantic models, dependency injection, background tasks, exception handling, lifespan events, async programming.
Provides FastAPI best practices for project structure, Pydantic v2 schemas, dependency injection, async handlers, auth, transactional service layers, and testing with httpx and pytest.