python-patterns

Provide idiomatic Python patterns for writing, reviewing, and refactoring code.

Updated Mar 24, 2026
One-click install
npx skills add https://github.com/Oruga420/claude-code-skills --skill python-patterns-oruga420
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: python-patterns
Source: https://github.com/Oruga420/claude-code-skills/tree/main/python-patterns
Command: npx skills add https://github.com/Oruga420/claude-code-skills --skill python-patterns-oruga420

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Reduce inconsistent, hard-to-maintain, and non-idiomatic Python code by providing clear patterns, conventions, and practical guidance that improve readability, safety, and long-term maintainability.

Core Features & Use Cases

  • Idiomatic Patterns: Guidelines for readability, explicit behavior, EAFP, comprehensions, and when to prefer generators or context managers.
  • Typing & Validation: Recommendations for modern type hints, Protocol-based duck typing, TypeVar usage, and integrating mypy or other type checkers.
  • Error Handling & Tooling: Best practices for specific exception handling, exception chaining, custom exception hierarchies, and integration with black, ruff, isort, pytest, and CI workflows.
  • Performance & Concurrency: Patterns for memory efficiency (slots), generator-based streaming, threading vs multiprocessing, and async/await for concurrent I/O.
  • Use Case: Refactor a legacy module to adopt type hints, improve error handling, add tests, and align formatting and linting for a production codebase.

Quick Start

Use the python-patterns skill to refactor a function for readability, add type hints, and suggest unit tests.

Frequently Asked Questions about python-patterns

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

FAQPage Schema
What are the best practices for adding type hints and Protocol-based duck typing in Python?▼

Best practices for Python type hints involve using modern syntax, Protocol for duck typing, and TypeVar for generics, integrated with mypy to statically validate code and improve safety.

How do I refactor Python code to use idiomatic patterns like EAFP and context managers?▼

Refactoring Python code for idiomatic patterns involves applying EAFP principles, replacing explicit checks with try/except blocks, and using context managers and generators for readable resource management.

How do I structure exception handling hierarchies and integrate ruff or black for Python code style?▼

Exception handling hierarchies are structured using custom exception classes and exception chaining, while code style is maintained by integrating black, ruff, isort, and pytest within CI workflows.

When should I use threading vs multiprocessing vs async await for Python concurrency?▼

Python concurrency patterns dictate using async/await for concurrent I/O-bound tasks, threading for legacy I/O, and multiprocessing for CPU-bound workloads to maximize performance.

Does Python support memory efficiency patterns like __slots__ and generator-based streaming?▼

Python supports memory efficiency through __slots__ to reduce instance footprint and generator-based streaming to process large datasets lazily without loading everything into memory.