python-design-patterns
Skill11 starsChanged 8 days agoMITView on GitHub
Python design pattern guidance. Use when choosing, implementing, or reviewing idiomatic Python patterns such as dataclasses, value objects, protocols, context managers, dependency injection, adapters, repositories, factories, CLI/service boundaries, async resource handling, pytest fixtures, or Clean/Hexagonal/Onion expression in Python. Use python-antipatterns for smell-focused audits and python-engineering for broader Python workflow.
15 other projects use a version of this.
Adopted by
Most recently taken up by
- zebbern/pocmaptheir own version, first seen Nov 8, 2026
- delorenj/skillstheir own version, first seen Nov 7, 2026
- scwf/feishuai-skillstheir own version, first seen Oct 25, 2026
- anton-karlovskiy/deal-hunter-agentstheir own version, first seen Oct 13, 2026
- enes9103/my-claude-agents-skillstheir own version, first seen Sep 28, 2026
- roshankodi/agent-skillstheir own version, first seen Sep 22, 2026
Used with
Projects with it also use python-type-safety, python-error-handling and 7 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.
CodeWithBehnamSkillpython-type-safety
Python type safety with type hints, generics, protocols, and strict type checking. Use when adding type annotations, implementing generic classes, defining structural interfaces, or configuring mypy/pyright.
Also in 5 projects that use this
justanestaSkillpython-error-handling
Python error handling and debugging. Use this skill when implementing error handling, designing exception hierarchies, debugging issues, or adding logging. Covers exception patterns, custom exceptions, logging with structlog, debugging tools, and error recovery.
Also in 4 projects that use this
CodeWithBehnamSkillpython-anti-patterns
Common Python anti-patterns to avoid. Use as a checklist when reviewing code, before finalizing implementations, or when debugging issues that might stem from known bad practices.
Also in 4 projects that use this
xfstudioSkillpython-testing-patterns
Implement comprehensive testing strategies with pytest, fixtures, mocking, and test-driven development. Use when writing Python tests, setting up test suites, or implementing testing best practices.
Also in 6 projects that use this
nilecuiSkillasync-python-patterns
Master Python asyncio, concurrent programming, and async/await patterns for high-performance applications. Use when building async APIs, concurrent systems, or I/O-bound applications requiring non-blocking operations.
Also in 4 projects that use this
xfstudioSkilljavascript-testing-patterns
Implement comprehensive testing strategies using Jest, Vitest, and Testing Library for unit tests, integration tests, and end-to-end testing with mocking, fixtures, and test-driven development. Use when writing JavaScript/TypeScript tests, setting up test infrastructure, or implementing TDD/BDD workflows.
Also in 3 projects that use this
- +1 more from CodeWithBehnam
- +2 more from xfstudio
Other versions15 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 15
- delorenj/skills★ 17same name
- zebbern/pocmap★ 7same name
- GPTtang/skill-atlas★ 4same name
- scwf/feishuai-skills★ 4same name
- zebbern/termstack★ 4same name
- Aver005/agent-skills★ 2same name
- CodeWithBehnam/cc-docs★ 2same name
- NorkzYT/claude-code-autopilot★ 2same name
- roshankodi/agent-skills★ 2same name
- anton-karlovskiy/deal-hunter-agents★ 1same name
5 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 repository70 other files it gives its agents.
- AGENTS.mdAGENTS.md
- adversarial-reviewSkill
- api-designSkill
- architecture-reviewSkill
- behavior-driven-developmentSkill
- brainstormingSkill
- ci-release-engineeringSkill
- clean-architectureSkill
- code-reviewSkill
- container-engineeringSkill
- create-agent-skillSkill
- csharp-dotnet-engineeringSkill
- css-scss-stylingSkill
- data-platform-engineeringSkill
- dependency-supply-chain-reviewSkill
- digital-asset-managementSkill
- documentation-engineeringSkill
- domain-driven-designSkill
- domain-modelingSkill
- donsetch-web-researchSkill
- gherkinSkill
- git-commitSkill
- git-workflowsSkill
- hexagonal-architectureSkill
- impeccableSkill
- internationalization-localizationSkill
- javascript-typescript-engineeringSkill
- justfilesSkill
- mcp-server-engineeringSkill
- mysql-mariadb-sql-engineeringSkill
- observability-engineeringSkill
- onion-architectureSkill
- parallelism-engineeringSkill
- performance-reviewSkill
- playwright-e2eSkill
- postgresql-sql-engineeringSkill
- prompt-engineering-reviewSkill
- python-antipatternsSkill
- python-engineeringSkill
- random-data-identifiersSkill
- release-readinessSkill
- review-verification-protocolSkill
- root-cause-analysisSkill
- ruby-engineeringSkill
- rust-antipatternsSkill
- rust-async-webSkill
- rust-code-reviewSkill
- rust-design-patternsSkill
- rust-desktop-guiSkill
- rust-engineeringSkill
- rust-persistence-sqlSkill
- rust-testing-qualitySkill
- script-engineeringSkill
- security-review-evidenceSkill
- security-reviewSkill
- semantic-versioningSkill
- sql-engineeringSkill
- sqlite-sql-engineeringSkill
- suggest-lucide-iconsSkill
- svelte-sveltekit-engineeringSkill
- The first 60 shown.
The file
Show its rules and text
We split this skill into the rules it gives an agent
17 rules. 0 are common, 17 are distinctive, and 0 are very specific to this project.
0
Common
Most of the 14 edited versions we read keep these.
17
Distinctive
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 8
Use this skill to choose Python patterns that fit the codebase, runtime, and domain.
- Distinctive: line 35
Prefer plain functions and cohesive modules until identity, lifecycle, invariants, substitution, or state justify classes or protocols.
- Distinctive: line 37
Use structural typing and dependency injection at real boundaries, not for every collaborator.
- Distinctive: line 39
Keep framework, ORM, request, response, serializer, and SDK types at adapters unless the project intentionally centers that framework.
- Distinctive: line 41
Test domain rules with ordinary unit tests.
- Distinctive: line 46
Dataclasses and frozen dataclasses: use for explicit data shapes, value objects, and immutable domain values.
- Distinctive: line 49
Enums and literal types: use for small closed sets and states where string values would otherwise drift.
- Distinctive: line 51
Protocols: use for outbound ports, plugin surfaces, or collaborators where structural substitution matters.
- Distinctive: line 53
Context managers: use for resources that need reliable setup and teardown: files, locks, transactions, temporary directories, spans, and …
- Distinctive: line 55
Factories and constructors: use factory functions or classmethods when creation has validation, defaults, environment lookup, or dependency …
- Distinctive: line 57
Adapter modules: put HTTP clients, database access, queues, filesystems, CLIs, and framework handlers behind boundary modules that …
- Distinctive: line 60
Repository pattern: use only when persistence shape should be hidden from domain/application policy.
- Distinctive: line 62
Functional core, imperative shell: keep parsing, validation, decisions, and transformations pure where practical.
- Distinctive: line 64
Pytest fixtures/builders: use fixtures for resource setup and builders for readable test data, with explicit cleanup and deterministic …
- Distinctive: line 69
Prefer a supervised task group when sibling tasks share a lifetime: the parent creates them, observes failures, propagates shutdown, and …
- Distinctive: line 82
DDD: use value objects, entities with identity, domain services, policies, and explicit state transitions where they protect real rules.
- Distinctive: line 89
TDD: write focused tests for parsers, validators, policies, state changes, and error mapping before wiring broad integrations.
“Common” is measured: kept by at least 6 in 10 of the 14 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 Design Patterns
Use this skill to choose Python patterns that fit the codebase, runtime, and domain. Prefer simple modules, functions, data types, protocols, and explicit boundaries over pattern catalogs copied from class-heavy languages.
Use When
- Python code needs a domain model, adapter boundary, test seam, construction pattern, resource-lifetime pattern, or API structure.
- A refactor should make behavior easier to test without real frameworks, databases, filesystems, or services.
- Clean, Hexagonal, Onion, DDD, BDD, or TDD guidance needs Python-specific expression.
- Review feedback asks for a more idiomatic Python design.
For smell-focused review, use
python-antipatterns. For package, uv,
typing, test, and command workflow, use
python-engineering.
Advice-only pattern choice may use this skill independently. When applying or
implementing a pattern, load
python-engineering.
Selection Rules
- Inspect local Python version, package layout, tests, framework conventions, typing policy, and existing data-model choices.
- Prefer plain functions and cohesive modules until identity, lifecycle, invariants, substitution, or state justify classes or protocols.
- Use structural typing and dependency injection at real boundaries, not for every collaborator.
- Keep framework, ORM, request, response, serializer, and SDK types at adapters unless the project intentionally centers that framework.
- Test domain rules with ordinary unit tests; test adapters with real framework, database, filesystem, or service contracts.
Patterns To Prefer
- Dataclasses and frozen dataclasses: use for explicit data shapes, value objects, and immutable domain values. Add validation constructors when invalid states matter.
- Enums and literal types: use for small closed sets and states where string values would otherwise drift.
- Protocols: use for outbound ports, plugin surfaces, or collaborators where structural substitution matters. Keep protocols small and behavior-oriented.
- Context managers: use for resources that need reliable setup and teardown: files, locks, transactions, temporary directories, spans, and test fixtures.
- Factories and constructors: use factory functions or classmethods when creation has validation, defaults, environment lookup, or dependency wiring.
- Adapter modules: put HTTP clients, database access, queues, filesystems, CLIs, and framework handlers behind boundary modules that translate to domain concepts.
- Repository pattern: use only when persistence shape should be hidden from domain/application policy. Do not create generic CRUD repositories by default.
- Functional core, imperative shell: keep parsing, validation, decisions, and transformations pure where practical; keep I/O at the edges.
- Pytest fixtures/builders: use fixtures for resource setup and builders for readable test data, with explicit cleanup and deterministic values.
Async Ownership Patterns
- Prefer a supervised task group when sibling tasks share a lifetime: the parent creates them, observes failures, propagates shutdown, and awaits every child before leaving its resource scope.
- Give each queue, finite worker set, and the resources those workers use one explicit lifecycle owner. A task that must outlive a caller needs a named, longer-lived supervisor rather than becoming detached work.
Route cancellation, backpressure, overload, retry, ordering, recovery, and test
workflow to python-engineering and its
asyncio concurrency reference.
Architecture And Methods
- DDD: use value objects, entities with identity, domain services, policies, and explicit state transitions where they protect real rules.
- Clean / Hexagonal / Onion: represent use cases as functions or application service classes; use protocols for outbound ports when tests or adapters need substitution; keep framework handlers thin.
- BDD: express externally observable workflows with domain language before choosing pytest, behave, pytest-bdd, or plain test names.
- TDD: write focused tests for parsers, validators, policies, state changes, and error mapping before wiring broad integrations.
Review Checklist
- Does the pattern solve a current behavior, boundary, or testing problem?
- Are type hints meaningful without replacing runtime validation at trust boundaries?
- Are exceptions specific and preserved with
raise ... from excwhere useful? - Are resources closed deterministically through context managers, fixtures, or framework lifecycle hooks?
- Are framework and persistence models kept out of core domain APIs where that boundary matters?
- Are mocks limited to external, slow, nondeterministic, or infrastructure boundaries?
Common Mistakes
- Adding abstract base classes or protocols for one concrete implementation.
- Turning simple functions into manager/service classes with no state or boundary.
- Treating Pydantic, ORM, or serializer models as domain objects by default.
- Hiding environment, filesystem, network, or database access in import-time side effects.
- Using fixtures or monkeypatching to replace the behavior being specified.
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.

