Python Patterns

Python best practices including type hints, async patterns, testing, and project structure

492 stars 68 forksSoftware Development

Install

skills CLI (Claude Code, Cursor, Codex and more)
npx skills add cosmicstack-labs/mercury-agent-skills --skill python-patterns
Manual install
git clone --depth 1 https://github.com/cosmicstack-labs/mercury-agent-skills.git /tmp/mercury-agent-skills
mkdir -p ~/.claude/skills
cp -r /tmp/mercury-agent-skills/categories/backend/python-patterns ~/.claude/skills/python-patterns

Personal skills live in ~/.claude/skills. Use .claude/skills in a project folder to share a skill with your team.

From the SKILL.md

# Python Patterns

Write Python that is type-safe, testable, and a joy to maintain.

## Core Principles

### 1. Explicit Over Implicit
Use type hints. Avoid `*args` and `**kwargs` when named parameters work. Favor clear interfaces over dynamic flexibility.

### 2. Composition Over Inheritance
Python's multiple inheritance is powerful but dangerous. Prefer composition and protocols over deep class hierarchies.

### 3. Async Done Right
Async is a tool for I/O-bound workloads, not a universal default. Use synchronous code for CPU-bound tasks, async for network calls and file I/O.

### 4. Test-First for Critical Paths
Your business logic should be testable without mocks. Use dependency injection. Keep I/O at the boundaries.

---

## Python Maturity Model

| Level | Typing | Async | Testing | Structure |
|-------|--------|-------|---------|-----------|
| **1: Script** | No type hints | sync only | Manual testing | Single file |
| **2: Module** | Basic types (str, int) | Basic asyncio | pytest, some coverage | Package with `__init__.py` |
| **3: Package** | Full type hints with mypy | Async with proper patterns | pytest + fixtures + mocking | src-layout, entry points |
| **4: Service** | Generics, Protocols, TypedDict | Structured concurrency | Property-based, integration tests | Domain-driven structure |
| **5: Library** | Precise types, variance annotations | Trio / anyio | Fuzzing, benchmark tests | Public API surface explicit |

Target: **Level 3+** for production services.
Read the full skill on GitHub

Details

Skill name
python-patterns
Path
categories/backend/python-patterns/SKILL.md
License
MIT
Repo updated
25 August 2026

FAQ

What does the Python Patterns skill do?

Python best practices including type hints, async patterns, testing, and project structure

How do I install the Python Patterns skill?

skills CLI (Claude Code, Cursor, Codex and more): npx skills add cosmicstack-labs/mercury-agent-skills --skill python-patterns. Skills go in ~/.claude/skills (personal) or .claude/skills (project), and Claude loads them automatically when a task matches the description.

Is Python Patterns popular?

It lives in cosmicstack-labs/mercury-agent-skills, which has 492 GitHub stars and 68 forks.

Related skills

Browse the most popular Claude skills, all software development skills, or write your own with the skills generator.