agentsclimarketplace

Python design principles

Skill JoseVelazcoH/python-skills/skills/python-design-principles

Claude Code Python skills that improve how you write Python: clean code, design, and testing, enforced by a pre-commit review.

Install
npx -y skills add JoseVelazcoH/python-skills --skill python-design-principles

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

What its author says it does

Copied from the file, not written here

Trigger: SOLID, dependency inversion, coupling, cohesion, strategy pattern, open/closed, abstractions, Protocol, ABC, class structure. Shape Python class and module design.

The file declares its own license as Apache-2.0. That is the author’s claim about this one file, and it is not the same thing as the license GitHub reports for the repository, which is listed with the other numbers below.

SKILL.md

3.0 KB, as published. Nobody here has run it

Python Design Principles

Structure-level design: how classes and modules relate: coupling/cohesion, dependency inversion, strategy, and SOLID.

Activation Contract

Apply when designing or refactoring class/module structure: a class does many jobs, high-level code instantiates concretions, a growing if/elif selects behavior, or the user asks about SOLID/coupling/abstractions. For line-level readability use python-clean-code; for system layering use architecture guidance.

Hard Rules

  • One reason to change per class (SRP). High cohesion (related behavior together), low coupling (few cross-dependencies).
  • Depend on abstractions, not concretions (DIP). Inject collaborators via the constructor; never instantiate concrete deps inside a class.
  • Open for extension, closed for modification (OCP): add behavior with a new class, not by editing an if/elif.
  • Replace branching-on-type with the Strategy pattern: interchangeable classes behind a common Protocol/ABC.
  • Prefer small Protocol interfaces (ISP) over fat ones. Subtypes must honor the parent contract (LSP): no raise NotImplementedError overrides.

Decision Gates

SymptomPrincipleFix
Class generates IDs, prices, printsSRP/cohesionSplit into focused classes
self.db = PostgresDB() inside serviceDIPInject a Protocol collaborator
if type == "credit": ... elif ...OCP/StrategyStrategy classes behind one interface
Interface with methods some impls rejectISP/LSPSplit into small Protocols
Module A imports B imports ACouplingInvert dependency via abstraction

Execution Steps

  1. Identify the principle violated from the gate table.
  2. Introduce the smallest abstraction that fixes it: a Protocol or ABC, injected.
  3. Show # Bad# Good; verify the client now depends only on the abstraction.
  4. Do not add patterns the design does not yet need (YAGNI).
from typing import Protocol

# Bad: branch on type, closed to extension
def pay(order, kind):
    if kind == "credit": ...
    elif kind == "debit": ...

# Good: Strategy behind a Protocol (OCP + DIP)
class PaymentProcessor(Protocol):
    def pay(self, order: Order) -> None: ...

class CreditProcessor:
    def pay(self, order: Order) -> None: ...

def checkout(order: Order, processor: PaymentProcessor) -> None:
    processor.pay(order)

Output Contract

Return restructured Python where clients depend on abstractions, plus a one-line note naming each principle applied. Keep the abstraction minimal.

References

  • references/solid.md: the five SOLID principles with Python examples.
  • references/coupling-strategy.md: coupling/cohesion and the Strategy pattern.

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.