py-patterns

Design and refactor Python architecture using Protocols and dependency injection.

1|1|Updated Mar 28, 2026
One-click install
npx skills add https://github.com/stevenke1981/python_skills --skill py-patterns
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: py-patterns
Source: https://github.com/stevenke1981/python_skills/tree/main/py-patterns
Command: npx skills add https://github.com/stevenke1981/python_skills --skill py-patterns

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill addresses code complexity, tight coupling, and testing difficulties by providing a structured approach to implementing design patterns and architectural boundaries in Python projects.

Core Features & Use Cases

  • Architectural Decoupling: Uses Protocols and dependency injection to separate business logic from infrastructure and frameworks.
  • Pattern Implementation: Provides guidance on Strategy, Factory, Adapter, Repository, Unit of Work, and State Machine patterns.
  • Use Case: When a growing codebase becomes difficult to test or modify due to framework-specific dependencies, use this Skill to refactor the system into a clean, testable architecture using domain-driven design principles.

Quick Start

Apply the py-patterns skill to refactor the current module by introducing a Protocol for the external service dependency and implementing constructor injection.

Frequently Asked Questions about py-patterns

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

FAQPage Schema
How do I decouple business logic from infrastructure in Python?

To decouple business logic from infrastructure in Python, use Protocols and dependency injection to separate core domain operations from framework-specific dependencies, improving overall modularity and testability.

What design patterns help refactor a complex Python codebase for better testability?

Design patterns that improve testability in a complex Python codebase include Strategy, Factory, Adapter, Repository, Unit of Work, and State Machine patterns, which establish clear architectural boundaries and separation of concerns.

How do I implement dependency injection using Python Protocols?

Implement dependency injection using Python Protocols by defining structural subtyping for external service dependencies, then applying constructor injection to refactor the current module and isolate domain logic.

Can I apply domain-driven design principles to an existing Python project?

You can apply domain-driven design principles to an existing Python project by refactoring it with architectural boundaries, utilizing the Unit of Work and Repository patterns for robust transaction management and state handling.

When should I refactor Python code to use standard architectural patterns?

Refactor Python code to use standard architectural patterns when tight coupling and framework-specific dependencies make the codebase difficult to test or modify, requiring clear separation of concerns.