Skills python-design-patterns
📦

python-design-patterns

Safe

Apply Python Design Patterns

Write maintainable Python code using proven design patterns like KISS, Single Responsibility, and Composition over Inheritance to build systems that are easy to understand, test, and modify.

Supports: Claude Codex Code(CC)
🥉 74 Bronze
1

Download the skill ZIP

2

Upload in Claude

Go to Settings → Capabilities → Skills → Upload skill

3

Toggle on and start using

Test it

Using "python-design-patterns". Show me how to refactor a class that handles user registration, sends emails, logs activity, and saves to database

Expected outcome:

A refactored example splitting into UserService (business logic), UserRepository (data access), EmailNotifier (notifications), and ActivityLogger (logging) - each with single responsibility.

Using "python-design-patterns". I need to add payment processing to my order system. Should I inherit from a base Order class or use composition?

Expected outcome:

Explanation of why composition is preferred - you can swap payment providers, test with fakes, and avoid inheritance hierarchies. Example showing PaymentProcessor injected into OrderService.

Using "python-design-patterns". I have three similar functions that process data slightly differently. Should I create an abstraction?

Expected outcome:

Apply Rule of Three - wait until you see a clear pattern emerge. Show example of when duplication is better than wrong abstraction, and when to abstract.

Security Audit

Safe
v1 • 2/15/2026

All 35 static findings are false positives. The skill is a documentation file containing Python code examples for educational purposes. Python dictionary syntax was misidentified as shell backticks, email examples as network calls, and code examples as cryptographic algorithms or reconnaissance. No actual security risks present.

1
Files scanned
412
Lines analyzed
0
findings
1
Total audits
No security issues found
Audited by: claude

Quality Score

38
Architecture
100
Maintainability
85
Content
50
Community
100
Security
91
Spec Compliance

What You Can Build

Architecting new Python services

When starting a new service, use these patterns to create a clean, maintainable architecture from the beginning.

Refactoring tangled code

When faced with complex, coupled code, apply SRP and Separation of Concerns to untangle dependencies.

Evaluating abstraction decisions

When deciding whether to create an abstraction, use the Rule of Three to avoid premature generalization.

Try These Prompts

Apply KISS to a problem
I need to solve [describe problem]. What is the simplest solution that works? Show me an example.
Refactor using SRP
Here is my class [paste code] that does multiple things. How can I split it into classes with single responsibilities?
Composition vs Inheritance
I have a base class with shared behavior and want to extend it. How can I use composition instead of inheritance? Show an example.
Apply layered architecture
How should I organize [describe your application] into layers? Show me the separation of concerns with example code.

Best Practices

  • Start with the simplest solution and add complexity only when justified by concrete requirements
  • Keep functions focused to 20-50 lines with a single purpose
  • Separate I/O operations from business logic into different layers
  • Inject dependencies through constructors for testability

Avoid

  • Creating abstractions too early before understanding the domain
  • Using inheritance for code reuse instead of composition
  • Mixing concerns like HTTP handling, validation, and database access in one class
  • Making code clever instead of readable

Frequently Asked Questions

What is the Rule of Three in Python?
Wait until you have three similar instances before creating an abstraction. Two similar pieces of code may not actually share a pattern - wait for the third to confirm.
When should I use composition over inheritance?
Always prefer composition unless you need true polymorphism. Inheritance creates tight coupling and makes testing harder.
How big should a function be?
Keep functions to 20-50 lines depending on complexity. Extract when it serves multiple purposes or has deeply nested logic (3+ levels).
What is Separation of Concerns?
Organize code into distinct layers (API, Service, Repository) where each layer has a clear responsibility and only depends on layers below it.
What is Dependency Injection?
Pass dependencies through constructors rather than creating them inside the class. This makes code testable by allowing fake implementations.
When should I apply the KISS principle?
Always start with the simplest solution that works. Only add complexity when concrete requirements justify it. Simple code is easier to maintain.

Developer Details

File structure

📄 SKILL.md