python-patterns

python-patterns is a skill for Claude Code from loulanyue/awesome-claude-notes. It costs 53 tokens per session (4,683 once invoked), scanned A, original, MIT.

A guide to common Python coding patterns, style rules, type hints, and practices for writing code that is readable, robust, efficient, and easier to maintain.

In plain words
What is it for?
It is for creating, reviewing, refactoring, and structuring Python applications and packages.
Why use it?
It helps avoid unclear Python code, hidden side effects, and inconsistent design choices when writing or changing an application.

Skill for Claude Code

Written for Claude Code: shipped in a Claude Code plugin.

Part of the awesome-claude-notes plugin — 106 skills, 61 commands, 29 agents shipped together

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.

agentmods
npx agentmods add skills/loulanyue/awesome-claude-notes/python-patterns
Any agent
npx skills add loulanyue/awesome-claude-notes --skill python-patterns
Clone the repo
git clone --depth 1 https://github.com/loulanyue/awesome-claude-notes

Made for: Claude Code.

Or install awesome-claude-notes, the plugin that ships this one along with the rest of its 106 skills, 61 commands, 29 agents.

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/loulanyue/awesome-claude-notes/python-patterns.svg)](https://agentmods.dev/skills/loulanyue/awesome-claude-notes/python-patterns)
Your own site
<a href="https://agentmods.dev/skills/loulanyue/awesome-claude-notes/python-patterns"><img src="https://agentmods.dev/badge/skills/loulanyue/awesome-claude-notes/python-patterns.svg" alt="Measured on agentmods" height="20"></a>
Per session 53 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 4,683 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 1 finding. Scan, not verified.
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.00053 $0.04683
Opus 5 $0.00026 $0.02341
Sonnet 5 $0.00011 $0.00937
Haiku 4.5 $0.00005 $0.00468

Measured 2d ago against content hash 6f7895da2ccb, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-06, 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 2d 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.

import urllib.request
docs/ja-JP/skills/python-patterns/SKILL.md · 759 lines

How it starts

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

Python開発パターン

堅牢で効率的かつ保守可能なアプリケーションを構築するための慣用的なPythonパターンとベストプラクティス。

いつ有効化するか

  • 新しいPythonコードを書くとき
  • Pythonコードをレビューするとき
  • 既存のPythonコードをリファクタリングするとき
  • Pythonパッケージ/モジュールを設計するとき

核となる原則

1. 可読性が重要

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. 明示的は暗黙的より良い

魔法を避け、コードが何をしているかを明確にしましょう。

# 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 - 許可を求めるより許しを請う方が簡単

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

型ヒント

基本的な型アノテーション

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)

モダンな型ヒント(Python 3.9+)

# 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}

型エイリアスとTypeVar

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

Read the full file on GitHub · 759 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. 2d ago First seen · 759 lines · 53 tokens per session scan A 6f7895da2ccb

Subscribe to this mod's changes

python-patterns is a skill published in the GitHub repository loulanyue/awesome-claude-notes (270 stars, last pushed 2d ago), licensed MIT. It adds 53 tokens to every session and 4,683 once invoked, about $0.0003 per session on Opus 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-09-03.