python-design-patterns

Applies Python design principles like KISS, single responsibility, and composition to structure maintainable code.

Updated Apr 13, 2026
One-click install
npx skills add https://github.com/scoots31/engineering-playbook --skill python-design-patterns-scoots31
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: python-design-patterns
Source: https://github.com/scoots31/engineering-playbook/tree/main/references/python-design-patterns
Command: npx skills add https://github.com/scoots31/engineering-playbook --skill python-design-patterns-scoots31

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Python codebases often grow into tangled God classes, monolithic functions, and tightly coupled layers that are hard to test and modify. This Skill provides concrete patterns and decision rules for structuring Python code so responsibilities stay separated and components remain testable. ## Core Features & Use Cases - Fundamental Design Principles: Apply KISS, Single Responsibility, Separation of Concerns, and composition over inheritance with before-and-after code examples. - Layered Architecture Guidance: Organize code into API, service, and repository layers with correct dependency direction. - Refactoring Decision Rules: Use the Rule of Three, function size guidelines, and dependency injection to decide when to abstract, split, or leave duplication alone. - Use Case: When reviewing a pull request where a handler mixes HTTP parsing, SQL queries, and business rules, use this Skill to restructure it into a handler, service, and repository with injected dependencies that can each be tested in isolation. ## Quick Start Ask the AI to review this Python class using the design patterns skill and suggest how to split its responsibilities.

Frequently Asked Questions about python-design-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I refactor a Python class that does too many things?

Apply the Single Responsibility Principle by listing every change that could require editing the class. If changes come from different domains like HTTP parsing and business rules, split the class into focused units such as a handler, service, and repository.

When should I use composition instead of inheritance in Python?

Prefer composition when building behavior from interchangeable parts, such as notification channels or formatters. Passing dependencies through the constructor makes classes flexible and easy to test with fakes, while inheritance creates rigid hierarchies.

How do I structure a Python project into layers?

Organize code into an API layer for request parsing, a service layer for business logic, and a repository layer for data access. Dependencies should only point downward, so services never import from handlers.

When should I abstract duplicated code in Python?

Follow the Rule of Three: wait until a pattern appears three times before abstracting, since premature abstraction often creates the wrong interface. However, if duplicated copies are already diverging and causing bugs, extract the shared behavior immediately.

Why does dependency injection produce constructors with too many parameters?

Constructors with seven or more parameters signal that the class has too many responsibilities, not that injection is wrong. Split the class into smaller units first, and each constructor naturally becomes smaller.