← ClaudeAtlas

python-patternslisted

Python backend patterns: FastAPI, async SQLAlchemy, Pydantic. TRIGGER when: creating routes, models, schemas, or services in Python. SKIP: REST contract design (use api-design); schema/index tuning (use database-optimization).
komluk/scaffolding · ★ 1 · API & Backend · score 74
Install: claude install-skill komluk/scaffolding
# Python Backend Patterns Skill ## Purpose Best practices for Python backend development with FastAPI, SQLAlchemy, and async programming. ## Auto-Invoke Triggers - Creating FastAPI routes - Working with SQLAlchemy models - Implementing async operations - Creating Pydantic schemas --- ## Project Structure ``` app/ └── backend/ ├── app/ │ ├── main.py # FastAPI app initialization │ ├── config.py # Settings (pydantic-settings) │ ├── api/v1/endpoints/ # Route handlers │ ├── core/ # Security, exceptions │ ├── models/ # SQLAlchemy models │ ├── schemas/ # Pydantic schemas │ ├── services/ # Business logic │ ├── repositories/ # Data access │ └── db/session.py # Database session ├── tests/ ├── alembic.ini └── requirements.txt ``` --- ## Layer Responsibilities | Layer | Responsibility | |-------|----------------| | **Endpoints** | HTTP handling, request/response | | **Services** | Business logic, orchestration | | **Repositories** | Data access, queries | | **Models** | Database schema | | **Schemas** | Data validation, serialization | --- ## Async Database Patterns ### Session Management - Use `async_sessionmaker` for async sessions - Use dependency injection for session - Commit in dependency, rollback on exception - Use `expire_on_commit=False` for response data ### Query Patterns - Use `select()` statements (SQLA