python-patterns

python-patterns is a skill for Claude Code, Codex from cosmicstack-labs/mercury-agent-skills. It costs 19 tokens per session (1,955 once invoked), scanned A, original, MIT.

A guide to writing maintainable Python, including type hints, asynchronous code for waiting on external work, automated tests, and project organization.

In plain words
What is it for?
Use it when designing Python modules or services, adding types, choosing between synchronous and asynchronous code, structuring dependencies, and testing important behavior.
Why use it?
It helps avoid unclear interfaces, unsuitable use of asynchronous code, hard-to-test business logic, and disorganized Python projects.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit Use it when designing Python modules or services, adding types, choosing between synchronous and asynchronous code, structuring dependencies, and testing important behavior.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/cosmicstack-labs/mercury-agent-skills/python-patterns
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add cosmicstack-labs/mercury-agent-skills --skill python-patterns
Clone the repo
git clone --depth 1 https://github.com/cosmicstack-labs/mercury-agent-skills

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for python-patterns

README.md
[![agentmods](https://agentmods.dev/badge/skills/cosmicstack-labs/mercury-agent-skills/python-patterns/github.svg)](https://agentmods.dev/skills/cosmicstack-labs/mercury-agent-skills/python-patterns)
Your own site
<a href="https://agentmods.dev/skills/cosmicstack-labs/mercury-agent-skills/python-patterns"><img src="https://agentmods.dev/badge/skills/cosmicstack-labs/mercury-agent-skills/python-patterns/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for python-patterns

Your own site · 80×15
<a href="https://agentmods.dev/skills/cosmicstack-labs/mercury-agent-skills/python-patterns"><img src="https://agentmods.dev/badge/skills/cosmicstack-labs/mercury-agent-skills/python-patterns.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 19 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,955 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 1 finding. A grade says what 26 rules found in the file — not that it is safe. Third-party audits
  • NVIDIA SkillSpector pass 7 Sept 2026
How audits are shown
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00019 $0.01955
Opus 5.5 $0.00008 $0.00782
Sonnet 5.5 $0.00004 $0.00391
Haiku 4.5 $0.00002 $0.00196

Measured 1mo ago against content hash 0928e724b152, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

python-patterns scanned grade A with 1 finding against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 1mo ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Makes network callslowCapability

Not a fault in itself. Listed so you know the mod talks to something, and to what.

return await fetch(url)
categories/backend/python-patterns/SKILL.md · 282 lines

How it starts

The opening of the file, as written. The whole thing — 282 lines — stays where its author put it; the contents beside it link to each section on GitHub.

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.


Actionable Guidance

Type Hints

Basic Patterns
from typing import Optional, Union, Sequence, TypeVar, Protocol, Any
from datetime import datetime

# Function signatures
def process_user(
    user_id: int,
    name: str,
    email: Optional[str] = None,
    tags: list[str] | None = None,  # Python 3.10+ union syntax
) -> dict[str, Any]:
    ...

# TypedDict for structured dicts
class UserData(TypedDict, total=False):
    id: int
    name: str
    email: str
    created_at: datetime

# Protocols (structural subtyping)
class Drawable(Protocol):
    def draw(self, context: Any) -> None: ...

def render(item: Drawable) -> None:
    item.draw(...)  # Any object with draw() method works

Read the full file on GitHub · 282 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 1mo ago First seen · 282 lines · 19 tokens per session scan A 0928e724b152

Subscribe to this mod's changes

python-patterns is a skill published in the GitHub repository cosmicstack-labs/mercury-agent-skills (485 stars, last pushed 1mo ago), licensed MIT. It adds 19 tokens to every session and 1,955 once invoked, about $0.0001 per session on Opus 5.5. A static security scan graded it A with 1 finding (makes network calls). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories

cardputer-buddy

Iterate on the Cardputer-Adv MicroPython app bundle (Claude Buddy, Snake, Hello) after the device is already provisioned via m5-onboard. Use when the user wants to add a new app, push a single changed .py without re-flashing, watch device serial logs, or run a one-shot REPL command. Trigger on "add an app", "push to…

anthropics/claude-plugins-official · 109 tokens

developing-genkit-python

Develop AI-powered applications using Genkit in Python. Use when the user asks about Genkit, AI agents, flows, or tools in Python, or when encountering Genkit errors, import issues, or API problems.

google/skills · 49 tokens

hypothesis-testing

Property-based testing with Hypothesis for discovering edge cases and validating invariants. Use when implementing comprehensive test coverage, testing complex logic with many inputs, or validating mathematical properties and invariants across input domains. Triggered by: hypothesis, property-based testing, @given…

foryourhealth111-pixel/Vibe-Skills · 62 tokens

gh-address-comments

Help address review/issue comments on the open GitHub PR for the current branch using gh CLI; verify gh auth first and prompt the user to authenticate if not logged in.

foryourhealth111-pixel/Vibe-Skills · 39 tokens

authoring-dags

Workflow and best practices for writing Apache Airflow DAGs. Use when creating a new DAG, write pipeline code, handling questions about DAG patterns and conventions or extending an existing DAG with a follow-up/downstream task. ANY request shaped like 'add a DAG named X', 'write a pipeline', 'add a task that runs…

astronomer/agents · 93 tokens

test-harness

Generates pytest test suites with happy path, edge cases, error conditions, fixture scaffolding, mocks, async patterns. Triggers on: "generate tests", "write tests for", "test this function", "create test suite", "pytest for", "unit tests for", "mock strategy for".

Mathews-Tom/armory · 65 tokens