Skills DirectorySkills Directory
SkillsLearnSecurityCategoriesDocsBlogPro
Sign InSubmit Skill
Skills Directory

Security-tested agent skills for Claude, coding agents, and AI workflows.

Directory

  • Browse Skills
  • All Skills A–Z
  • Claude Skills
  • Claude Code Skills
  • Agent Skills
  • Categories
  • Authors
  • Submit a Skill

Learn

  • Learn Hub
  • Install Claude Skills
  • Write SKILL.md
  • Skills vs MCP
  • Directories Compared

Security

  • Security
  • Methodology
  • Secure Claude Skills
  • Security Badges
  • Chrome Extension
  • Skill Manager

Company

  • About
  • Community
  • Blog
  • API Docs
  • Advertise

2026 Skills Directory. All rights reserved.

ProTermsPrivacyRefunds
Back to skills

Python Patterns

ASecurity

Pythonic idioms, PEP 8 standards, type hints, and best practices for building robust, efficient, and maintainable Python applications.

12 stars
0 votes
0 copies
0 views
Added 10/6/2026
ai-agentspythonrustgoshellbashnodeexpressfastapidjangoflask

Works with

cliapi

Security Analysis

A100/100

Pro scans all 20 files and shows the line behind each finding

Scanned 10/6/2026

$npx -y skills add Nmor/the-council --skill python-patterns --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Python Patterns?

Add the live security badge to your README — it updates automatically with every re-scan.

Security grade badge for Python Patterns
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/nmor-python-patterns-the-council/badge)](https://www.skillsdirectory.com/skills/nmor-python-patterns-the-council)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
Files
SKILL.md
---
name: python-patterns
description: Pythonic idioms, PEP 8 standards, type hints, and best practices for building robust, efficient, and maintainable Python applications.
paths:
  - "**/*.py"
  - "**/*.pyi"
  - "pyproject.toml"
  - "**/pyproject.toml"
  - "requirements*.txt"
  - "**/requirements*.txt"
  - "Pipfile"
  - "**/Pipfile"
disable-model-invocation: true
---

# Python Development Patterns

> **Size budget: 25 KB.** Check: wc -c. Gate: node ~/.claude/scripts/token-budget.mjs --check
>
> **Reuse-first** (per `~/.claude/rules-library/common/reuse-first.md`):
> Before creating a new class, function, or module, sweep
> `<pkg>/lib/`, `<pkg>/utils/`, `<pkg>/services/`, `<pkg>/dto/`.
> One source of truth per primitive (one HTTP client, one logger
> config, one Pydantic base model, one validator, one
> serializer). Extend via subclass / Protocol / dependency
> injection — never fork the module into a parallel variant.

Idiomatic Python patterns and best practices for building robust, efficient, and maintainable
applications.

## Purpose

Pythonic idioms and patterns for production code: dataclasses + `__slots__`, type hints under `mypy
--strict`, context managers, async/await with `asyncio`, comprehensions, `pathlib`, `pydantic` for
validation, `pytest` for testing, and dependency management with `uv` / Poetry.

**Negative scope**: NOT framework-specific (Django / FastAPI / Flask have their own skills). NOT
data-science / Jupyter patterns (different concerns). NOT machine-learning pipelines (use
`cost-aware-llm-pipeline`).

## When NOT to use

- Pure Bash / shell scripting tasks
- Performance-critical loops where Cython / Rust extension is the right answer
- Notebooks where reproducibility != production discipline
- Throw-away one-off scripts where mypy strictness is more friction than value

## Reference map

This SKILL.md is a routing table. Every pattern, code example, standard and
anti-pattern lives in `references/` and is read on demand — open only the row
the task actually touches.

| Topic | Read | Covers |
| --- | --- | --- |
| Core principles | [`references/core-principles.md`](references/core-principles.md) | When to activate; readability counts; explicit over implicit; EAFP over LBYL |
| Type hints | [`references/type-hints.md`](references/type-hints.md) | Basic annotations; modern 3.9+ built-in generics; type aliases + TypeVar; Protocol duck typing |
| Error handling | [`references/error-handling.md`](references/error-handling.md) | Specific exception handling; exception chaining with `from`; custom exception hierarchy |
| Context managers | [`references/context-managers.md`](references/context-managers.md) | Resource management; `@contextmanager`; context-manager classes (`__enter__` / `__exit__`) |
| Comprehensions + generators | [`references/comprehensions-generators.md`](references/comprehensions-generators.md) | List comprehensions and when to expand them; generator expressions; generator functions |
| Data classes + named tuples | [`references/dataclasses-namedtuples.md`](references/dataclasses-namedtuples.md) | `@dataclass`; validation via `__post_init__`; `NamedTuple` |
| Decorators | [`references/decorators.md`](references/decorators.md) | Function decorators with `functools.wraps`; parameterized decorators; class-based decorators |
| Concurrency | [`references/concurrency.md`](references/concurrency.md) | Threads for I/O-bound; processes for CPU-bound; `async` / `await` with `asyncio.gather` |
| Package organization | [`references/package-organization.md`](references/package-organization.md) | Standard `src/` layout; import order conventions; `__init__.py` exports and `__all__` |
| Memory + performance | [`references/memory-performance.md`](references/memory-performance.md) | `__slots__`; generators for large data; avoiding O(n^2) string concatenation |
| Tooling | [`references/tooling.md`](references/tooling.md) | black / isort / ruff / mypy / pytest / bandit / pip-audit commands; reference `pyproject.toml` |
| Idioms + anti-patterns | [`references/idioms-and-anti-patterns.md`](references/idioms-and-anti-patterns.md) | Quick-reference idiom table; mutable defaults, `type()` checks, `== None`, `import *`, bare except |
| No-discards (Python) | [`references/no-discards.md`](references/no-discards.md) | The 17 banned patterns, required linter gates, strict `pyproject.toml`, Python verification block |
| Migrated rules | [`references/migrated-rules.md`](references/migrated-rules.md) | Migrated `rules-library/python/` bodies: coding-style, hooks, patterns, security, testing |

## Standards Cited

- **PEP 8** — Style Guide for Python Code
- **PEP 257** — Docstring Conventions
- **PEP 484 / PEP 526 / PEP 604** — Type Hints (variable, parameter, union syntax `X | Y`)
- **PEP 604** — Union types `int | str` (Python 3.10+)
- **PEP 695** — Type Parameter Syntax (Python 3.12+)
- **PEP 8 / PEP 257** — Style + docstrings
- **mypy / pyright** — strict-mode type checkers
- **ruff 0.7+** — linter + formatter (Astral)
- **OWASP ASVS 4.0.3 §5** — validation
- **Effective Python 3e (Slatkin, 2024)** — idiomatic patterns

## Cross-References

- `~/.claude/rules-library/python/no-discards.md` — banned Python patterns (bare except, `# noqa`,
  mutable defaults)
- `~/.claude/rules-library/common/extreme-lint-policy.md` — strict ruff / mypy config
- `~/.claude/rules-library/common/no-discards.md` — universal discards (hardcoded creds, `print()`
  in product code)
- `~/.claude/skills/coding-quality-rules/SKILL.md` — language-agnostic floor
- `~/.claude/skills/django-patterns/SKILL.md` — Django framework specifics
- `~/.claude/skills/python-testing/SKILL.md` — pytest + factories + property-based testing
- `~/.claude/agents/python-reviewer.md` — PEP 8 + type hint + framework review

## Why this skill exists

Python's dynamic nature makes it easy to ship subtle bugs that types would catch. The recurring
failure modes:

- `except:` swallows every error including `KeyboardInterrupt` and `SystemExit` → uninterruptible /
  undebuggable code paths
- Mutable default args (`def f(items=[])`) share state across calls → spooky bugs that look like
  "the function changed itself"
- `Optional[T]` accessed without narrowing → `AttributeError: 'NoneType'` in production
- `print()` debug statements left in product code → no structure, no levels, no correlation
- `subprocess.run(cmd, shell=True)` with user input → command injection

Cost of typed-Python discipline (mypy strict + ruff ALL): minutes per module. Cost of skipping it:
incidents that look like Python bugs but are really developer-discipline gaps.

## Learning hooks

Per `~/.claude/rules/common/continuous-learning-mandate.md`:

**Signals to watch**:

- `except:` / `except Exception:` without specific type + log + rethrow (sister
  `python/no-discards.md` rules 1-2)
- `raise NewErr(...)` without `from err` (loses cause chain — rule 4)
- `logging.error(...)` inside `except` instead of `logging.exception(...)` (rule 5)
- `# noqa` / `# type: ignore` / `# pragma: no cover` introduced (rule 6 violation)
- Mutable default argument (`def f(items=[])`) — rule 7 violation
- `Optional[T]` accessed without narrowing (rule 8)
- `Any` type used where a TypedDict / dataclass / Pydantic model would work (rule 9)
- `print()` in production source (rule 10 — use `logging`)
- `assert` used in production code paths (rule 13 — strips under `python -O`)
- `subprocess.run(..., shell=True)` (rule 14 — command injection)

**Refinement candidates**:

- New per-version idiom row when a new Python release ships (e.g., 3.13 free-threaded, structural
  pattern-matching improvements)
- Tightening of the strict-typing baseline when a Pydantic v3 / mypy improvement ships
- New cross-reference when a sister rule (python/no-discards, security) adds a banned pattern
- New error-handling template when a recurring exception class needs canonical wrapping

Attribution

NmorNmor
View sourceSee grades on GitHubMore from Nmor →
SSkills DirectorySkills Directory

Ship a skill? Prove it's safe.

Free 120-pattern security scan, letter grade, and an embeddable README badge.

Submit a skill

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments (0)

No comments yet. Be the first to comment!

SSkills DirectorySkills Directory

Ship a skill? Prove it's safe.

Free 120-pattern security scan, letter grade, and an embeddable README badge.

Submit a skill

Related Skills

Caveman

Terse caveman voice: answer first, fluff gone, every technical fact kept. Use for /caveman, "caveman mode", "talk like caveman", "be brief", "less tokens". Stays on until "stop caveman" or "normal mode".

1100021 votes

Hyperplan

Adversarial multi-agent planning skill. Self-orchestrates 5 hostile category members (unspecified-low, unspecified-high, deep, ultrabrain, artistry) via team-mode for ruthless cross-critique debate, distills only the defensible insights, then MANDATORILY hands the distilled insight bundle to the `plan` agent for executable plan formalization. Use when planning needs maximum rigor and surfacing of weak assumptions, blind spots, and over-engineering. Triggers: 'hyperplan', 'hpp', '/hyperplan', ...

698621 votes

Writing Skills

Create and manage Claude Code skills in HASH repository following Anthropic best practices. Use when creating new skills, modifying skill-rules.json, understanding trigger patterns, working with hooks, debugging skill activation, or implementing progressive disclosure. Covers skill structure, YAML frontmatter, trigger types (keywords, intent patterns), UserPromptSubmit hook, and the 500-line rule. Includes validation and debugging with SKILL_DEBUG. Examples include rust-error-stack, cargo-dep...

3931 votes

Mcp Code Execution

Routes multi-tool workflows through MCP servers for large datasets and pipelines. Use when Bash tool overhead is limiting throughput on data-heavy tasks.

3421 votes

catchup

Recovers the conversation and failed tool calls of a previous Codex, Amp, Claude Code, Antigravity, Cline, Copilot CLI, Cursor, DeepSeek Harness, Grok Build, Kimi, OpenCode, Pi Agent, or ZCode session. Use when the user says "catch up", "what did the last session do", "get me up to speed", "I switched agents", asks to recover/summarize a previous session before continuing, or asks to diagnose or report a catchup failure. Do NOT use for the current conversation, git history, or any non-agent log.

741 votes
View all in ai-agents →