
Python Patterns
Apply idiomatic Python, PEP 8, type hints, and maintainability patterns whenever you write, review, or refactor Python for a solo project.
Overview
Python-patterns is an agent skill most often used in Build (also Ship review, Operate iterate) that steers Python toward readable, explicit, PEP 8–aligned code with type hints and EAFP idioms.
Install
npx skills add https://github.com/affaan-m/everything-claude-code --skill python-patternsWhat is this skill?
- Core principles: readability, explicit over implicit, and EAFP exception style with before/after examples
- Activation triggers for writing new code, code review, refactoring, and package/module design
- Type hints and list comprehensions framed for obvious, maintainable solo-builder codebases
- Contrasts clever one-liners with clear naming and documented functions
- Fits ECC-origin procedural knowledge reusable across Python services and agent tooling
- 3 documented core principles with good-vs-bad code pairs (readability, explicit, EAFP)
Adoption & trust: 6k installs on skills.sh; 210k GitHub stars; 3/3 security scanners passed (skills.sh audits).
What problem does it solve?
You are writing or reviewing Python and keep producing clever, implicit, or inconsistent code that is hard to maintain alone.
Who is it for?
Solo builders shipping Python backends, CLIs, or agent tools who want consistent style without memorizing every PEP nuance.
Skip if: Teams that already enforce Ruff/black/mypy in CI and only need the linter output, or pure non-Python stacks with no Python surface.
When should I use this skill?
Writing new Python code; reviewing Python code; refactoring existing Python code; designing Python packages/modules.
What do I get? / Deliverables
The agent applies documented Pythonic patterns so new and refactored code stays obvious, typed where it helps, and easier to review before merge.
- Python code or diffs aligned with idiomatic patterns
- Clearer module structure and naming during package design
Recommended Skills
Journey fit
Spans multiple journey phases - primary shelf plus alternate fits below.
Canonical shelf is Build because the skill is centered on authoring and structuring Python modules—the default moment someone installs a patterns skill. Backend is the primary subphase for application logic, packages, and APIs where PEP 8, EAFP, and typing guidance matter most.
Where it fits
Shape a new FastAPI or script module with explicit logging setup and typed function signatures.
Review a solo PR for readability and EAFP-style error handling before release.
Refactor a gnarly legacy utility into clear comprehensions and named helpers without behavior changes.
How it compares
Use as procedural style guidance layered on top of formatters and linters, not instead of automated Python QA tools.
Common Questions / FAQ
Who is python-patterns for?
Solo and indie developers using Claude Code, Cursor, or similar agents to write, review, or refactor Python applications and small packages.
When should I use python-patterns?
During Build when authoring modules or APIs; during Ship when reviewing Python PRs; during Operate when refactoring legacy scripts—any time the SKILL.md “When to Activate” list applies.
Is python-patterns safe to install?
It is documentation-style procedural knowledge with no declared shell or network tools in the excerpt; review the Security Audits panel on this Prism page before installing from any skills registry.
SKILL.md
READMESKILL.md - Python Patterns
# Python Development Patterns Idiomatic Python patterns and best practices for building robust, efficient, and maintainable applications. ## When to Activate - Writing new Python code - Reviewing Python code - Refactoring existing Python code - Designing Python packages/modules ## Core Principles ### 1. Readability Counts Python prioritizes readability. Code should be obvious and easy to understand. ```python # Good: Clear and readable def get_active_users(users: list[User]) -> list[User]: """Return only active users from the provided list.""" return [user for user in users if user.is_active] # Bad: Clever but confusing def get_active_users(u): return [x for x in u if x.a] ``` ### 2. Explicit is Better Than Implicit Avoid magic; be clear about what your code does. ```python # Good: Explicit configuration import logging logging.basicConfig( level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s' ) # Bad: Hidden side effects import some_module some_module.setup() # What does this do? ``` ### 3. EAFP - Easier to Ask Forgiveness Than Permission Python prefers exception handling over checking conditions. ```python # Good: EAFP style def get_value(dictionary: dict, key: str) -> Any: try: return dictionary[key] except KeyError: return default_value # Bad: LBYL (Look Before You Leap) style def get_value(dictionary: dict, key: str) -> Any: if key in dictionary: return dictionary[key] else: return default_value ``` ## Type Hints ### Basic Type Annotations ```python from typing import Optional, List, Dict, Any def process_user( user_id: str, data: Dict[str, Any], active: bool = True ) -> Optional[User]: """Process a user and return the updated User or None.""" if not active: return None return User(user_id, data) ``` ### Modern Type Hints (Python 3.9+) ```python # Python 3.9+ - Use built-in types def process_items(items: list[str]) -> dict[str, int]: return {item: len(item) for item in items} # Python 3.8 and earlier - Use typing module from typing import List, Dict def process_items(items: List[str]) -> Dict[str, int]: return {item: len(item) for item in items} ``` ### Type Aliases and TypeVar ```python from typing import TypeVar, Union # Type alias for complex types JSON = Union[dict[str, Any], list[Any], str, int, float, bool, None] def parse_json(data: str) -> JSON: return json.loads(data) # Generic types T = TypeVar('T') def first(items: list[T]) -> T | None: """Return the first item or None if list is empty.""" return items[0] if items else None ``` ### Protocol-Based Duck Typing ```python from typing import Protocol class Renderable(Protocol): def render(self) -> str: """Render the object to a string.""" def render_all(items: list[Renderable]) -> str: """Render all items that implement the Renderable protocol.""" return "\n".join(item.render() for item in items) ``` ## Error Handling Patterns ### Specific Exception Handling ```python # Good: Catch specific exceptions def load_config(path: str) -> Config: try: with open(path) as f: return Config.from_json(f.read()) except FileNotFoundError as e: raise ConfigError(f"Config file not found: {path}") from e except json.JSONDecodeError as e: raise ConfigError(f"Invalid JSON in config: {path}") from e # Bad: Bare except def load_config(path: str) -> Config: try: with open(path) as f: return Config.from_json(f.read()) except: return None # Silent failure! ``` ### Exception Chaining ```python def process_data(data: str) -> Result: try: parsed = json.loads(data) except json.JSONDecodeError as e: