python-patterns
Skill15 starsChanged 2 months agoMITView on GitHub
Python backend patterns: layered architecture, async I/O, dependency injection, repository/service separation. TRIGGER when: creating routes, models, schemas, or services in a Python backend. SKIP: REST contract design (use api-design); schema/index tuning (use database-optimization). (Examples: FastAPI + SQLAlchemy + Pydantic.)
- Reads credentials
38 other projects use a version of this.
Adopted by
Most recently taken up by
- ku5ic/claude-kittheir own version, first seen Oct 6, 2026
- Lukk17/agent-standardstheir own version, first seen Oct 5, 2026
- templetongroup/radianttheir own version, first seen Sep 17, 2026
- IAbuElRuzz/AgentSkillstheir own version, first seen Sep 16, 2026
- MortuisVMain/ai-agent-superpowerstheir own version, first seen Sep 15, 2026
- Benkapner/claude-code-basecamptheir own version, first seen Sep 14, 2026
Used with
Projects with it also use kotlin-testing, nuxt4-patterns and 10 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
tpavanipradeepSkillkotlin-testing
Kotlin testing patterns with Kotest, MockK, coroutine testing, property-based testing, and Kover coverage. Follows TDD methodology with idiomatic Kotlin practices.
Also in 6 projects that use this
mryeastcodeSkillnuxt4-patterns
Nuxt 4 app patterns for hydration safety, performance, route rules, lazy loading, and SSR-safe data fetching with useFetch and useAsyncData.
Also in 5 projects that use this
InfopibeSkillralphinho-rfc-pipeline
RFC-driven multi-agent DAG execution pattern with quality gates, merge queues, and work unit orchestration.
Also in 9 projects that use this
FaisalAlqarniSkillspringboot-security
Spring Security best practices for authn/authz, validation, CSRF, secrets, headers, rate limiting, and dependency security in Java Spring Boot services.
Also in 16 projects that use this
saxon-ySkillconfigure-ecc
Interactive installer for Everything Claude Code — guides users through selecting and installing skills and rules to user-level or project-level directories, verifies paths, and optionally optimizes installed files.
Also in 11 projects that use this
InfopibeSkillswift-protocol-di-testing
Protocol-based dependency injection for testable Swift code — mock file system, network, and external APIs using focused protocols and Swift Testing.
Also in 9 projects that use this
- +1 more from Infopibe
Other versions38 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 38
- xu-xiang/everything-claude-code-zh★ 2ksame name
- loulanyue/awesome-claude-notes★ 272same name
- tpavanipradeep/everything-claude-code★ 134same name
- templetongroup/radiant★ 113same name
- Jamkris/everything-gemini-code★ 87same name
- codelably/harmony-claude-code★ 43same name
- kumaran-is/claude-code-onboarding★ 36same name
- VoDaiLocz/kilo-kit-mcp★ 27same name
- Benkapner/claude-code-basecamp★ 17same name
- noah-sheldon/ai-dev-kit★ 13same name
28 more not listed
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository38 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- agent-commsSkill
- agent-memorySkill
- api-designSkill
- context-engineeringSkill
- database-optimizationSkill
- distillSkill
- docker-templatesSkill
- error-handlingSkill
- github-actions-templateSkill
- git-operationsSkill
- logging-standardsSkill
- mcp-toolsSkill
- memorySkill
- monitoring-observabilitySkill
- mui-stylingSkill
- pattern-recognitionSkill
- planning-methodologySkill
- quality-validationSkill
- react-patternsSkill
- research-methodologySkill
- security-review-checklistsSkill
- semantic-memory-mcpSkill
- semantic-memory-storeSkill
- skill-authoringSkill
- sofa-searchSkill
- spec-designSkill
- spec-developSkill
- spec-researchSkill
- spec-reviewSkill
- spec-workflowSkill
- state-managementSkill
- systematic-debuggingSkill
- testing-strategySkill
- ui-ux-pro-maxSkill
- verification-before-completionSkill
- watch-patternsSkill
- worktree-managementSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
20 rules. 0 are common, 8 are distinctive, and 12 are very specific to this project.
0
Common
Most of the 35 edited versions we read keep these.
8
Distinctive
This author's own choices. Worth a look.
12
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 65
Use async_sessionmaker for async sessions
- Distinctive: line 66
Use dependency injection for session
- Distinctive: line 67
Commit in dependency, rollback on exception
- Very specific: line 68
Use expire_on_commit=False for response data
- Very specific: line 71
Use select() statements (SQLAlchemy 2.0 style)
- Very specific: line 72
Prefer scalar_one_or_none() for single items
- Very specific: line 73
Use scalars().all() for lists
- Very specific: line 90
Use model_config = ConfigDict(from_attributes=True) for ORM
- Very specific: line 91
Use Field() for validation constraints
- Very specific: line 92
Use field_validator for custom validation
- Very specific: line 151
Use pydantic-settings for env loading
- Very specific: line 152
Use @lru_cache for singleton
- Very specific: line 154
Use @property for computed values
- Very specific: line 173
Use pytest.mark.asyncio for async tests
- Distinctive: line 182
Use async/await consistently
- Distinctive: line 183
Use type hints everywhere
- Distinctive: line 184
Use Pydantic for all validation
- Distinctive: line 186
Use repository pattern for data access
- Distinctive: line 191
Put business logic in routes
- Distinctive: line 192
Use raw SQL without parameters
“Common” is measured: kept by at least 6 in 10 of the 35 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Python Backend Patterns Skill
Purpose
Best practices for Python backend development: layered architecture, async I/O, dependency injection, and clear separation between HTTP handling, business logic, and data access. The concrete examples below use FastAPI, SQLAlchemy, and Pydantic, but the patterns apply to any Python web framework, ORM, and validation library.
Auto-Invoke Triggers
- Creating backend routes / endpoints
- Working with ORM models
- Implementing async operations
- Creating request/response validation schemas
Layer Responsibilities
| Layer | Responsibility |
| Endpoints | HTTP handling, request/response |
| Services | Business logic, orchestration |
| Repositories | Data access, queries |
| Models | Database schema |
| Schemas | Data validation, serialization |
These layers are framework-agnostic — keep HTTP concerns, business rules, and data access in separate modules regardless of which framework/ORM you use.
Example: FastAPI + SQLAlchemy + Pydantic (illustrative)
Illustrative — this is one concrete stack shown as an example. Substitute your framework's equivalents (any ASGI/WSGI framework, ORM, and validation library). The layering and separation-of-concerns patterns above are the reusable part.
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.txtAsync Database Patterns
Session Management
- Use
async_sessionmakerfor async sessions - Use dependency injection for session
- Commit in dependency, rollback on exception
- Use
expire_on_commit=Falsefor response data
Query Patterns
- Use
select()statements (SQLAlchemy 2.0 style) - Prefer
scalar_one_or_none()for single items - Use
scalars().all()for lists - Eager load relationships with
selectinorjoinedload
Pydantic Schema Patterns
Schema Types
| Type | Purpose | Example |
| Base | Shared fields | UserBase(email, username) |
| Create | POST request | UserCreate(Base + password) |
| Update | PATCH request | UserUpdate(all optional) |
| Response | API response | UserResponse(Base + id, created_at) |
| InDB | Internal with secrets | UserInDB(Response + hashed_password) |
Best Practices
- Use
model_config = ConfigDict(from_attributes=True)for ORM - Use
Field()for validation constraints - Use
field_validatorfor custom validation - Separate request and response schemas
Repository Pattern
Base Repository Methods
get_by_id(id)- Single item by primary keyget_all(skip, limit)- Paginated listcreate(**kwargs)- Insert new recordupdate(id, **kwargs)- Update existingdelete(id)- Remove record
Specific Repositories
- Extend base with domain-specific queries
- Example:
get_by_email(),get_active_users()
Service Layer
Responsibilities
- Validate business rules
- Coordinate multiple repositories
- Transform data between layers
- Raise domain exceptions
Pattern
- Inject repository via constructor
- Return Pydantic schemas, not models
- Raise specific exceptions (NotFoundError, ConflictError)
Dependency Injection
Common Dependencies
get_db- Database sessionget_current_user- Authenticated userget_current_superuser- Admin user- Service factories -
get_user_service(session)
Pattern
# Endpoint receives dependencies, passes to service
async def create_user(
data: UserCreate,
session: AsyncSession = Depends(get_db)
):
service = UserService(session)
return await service.create(data)Configuration
Settings Class
- Use
pydantic-settingsfor env loading - Use
@lru_cachefor singleton - Define defaults for optional settings
- Use
@propertyfor computed values
Environment Variables
DATABASE_URL- Database connectionSECRET_KEY- JWT signingDEBUG- Development modeCORS_ORIGINS- Allowed origins
Testing Patterns
Fixtures
db_session- In-memory SQLite sessionclient- AsyncClient with app- Override
get_dbdependency for tests
Test Structure
- One test file per module
- Use
pytest.mark.asynciofor async tests - AAA pattern: Arrange, Act, Assert
- Mock external services
Best Practices
DO
- Use async/await consistently
- Use type hints everywhere
- Use Pydantic for all validation
- Use dependency injection
- Use repository pattern for data access
- Separate business logic into services
DON'T
- Mix sync and async database calls
- Put business logic in routes
- Use raw SQL without parameters
- Catch generic Exception
- Store secrets in code
- Skip server-side validation
Code Quality
| Tool | Purpose |
| black | Code formatting |
| ruff | Linting |
| mypy | Type checking |
| pytest | Testing |
| pytest-cov | Coverage |
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

