python-clean-code

Applies Clean Code Developer principles when writing and refactoring Python code.

Updated Jun 13, 2026
One-click install
npx skills add https://github.com/jenreh/project-kit-template --skill python-clean-code-jenreh
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: python-clean-code
Source: https://github.com/jenreh/project-kit-template/tree/main/.agents/agent-skills/skills/python-clean-code
Command: npx skills add https://github.com/jenreh/project-kit-template --skill python-clean-code-jenreh

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Python codebases often accumulate design debt: classes with multiple responsibilities, tangled dependencies, raw SQL mixed with domain logic, and speculative abstractions. This Skill enforces Clean Code Developer (CCD) principles automatically whenever Python code is written, refactored, or reviewed, so the output follows proven architecture rules without the user needing to ask. ## Core Features & Use Cases - Full CCD principle coverage: Enforces all four CCD grades — Orange (SRP, SoC, SLA), Yellow (ISP, DIP, LSP, information hiding, least astonishment), Green (OCP, Tell Don't Ask, Law of Demeter), and Blue (YAGNI, design-first, component orientation) — each with concrete Python before/after examples. - Python-specific idioms: Maps each principle to the right Python tool, such as typing.Protocol for minimal interfaces, constructor injection for dependencies, dict dispatch for the Open/Closed Principle, and all for module contracts. - Self-review checklist: Provides a 13-point checklist to verify non-trivial code before presenting it, covering SRP, DIP, ISP, LSP, LoD, YAGNI, and more. - Use Case: When asked to add a payment feature supporting Stripe, PayPal, and bank transfer, the Skill produces a PaymentProvider Protocol with strategy dict dispatch instead of an if/elif chain, keeping the code open for extension. ## Quick Start Ask the assistant to write or refactor any Python class, service, or module, and it will automatically apply clean code principles such as dependency injection and single responsibility.

Frequently Asked Questions about python-clean-code

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

FAQPage Schema
How do I apply SOLID principles when writing Python classes?

Apply SOLID in Python by defining dependencies as typing.Protocol interfaces, injecting them via the constructor, keeping each class to a single responsibility, and using dict dispatch instead of if/elif chains. This Skill encodes each principle with concrete before-and-after Python examples.

How to refactor a Python class that mixes database and email logic?

Split the class by responsibility: a domain model, a Repository for persistence, and a Notifier for email. Inject the repository and notifier as Protocol-typed constructor parameters so the service never instantiates connections like psycopg2 or smtplib inline.

What Python features support dependency inversion and interface segregation?

typing.Protocol is the primary tool: define narrow protocols per caller need instead of fat ABCs, and type constructor parameters against those protocols. This makes dependencies injectable and unit testing straightforward without mocking concrete classes.

Does this clean code approach work with dataclasses and Pydantic models?

Yes. The Skill recommends @dataclass(frozen=True) or Pydantic BaseModel for pure data containers, keeping domain models free of persistence and notification logic. Behavior and state transitions belong on the domain object, following Tell Don't Ask.

When should I avoid adding abstractions like plugin systems in Python?

Follow YAGNI: implement only what the current requirement demands. Skip abstract base classes with a single implementation, speculative parameters, and dynamic plugin loaders until a real second use case exists, since premature abstraction adds cost without benefit.