Skills DirectorySkills Directory
SkillsLearnSecurityCategoriesDocsCommunityBlog
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

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 9/28/2026
developmentpythonrustgoshellbashnodeexpressfastapidjangoflask

Works with

cliapi

Security Analysis

A100/100

Scanned 9/28/2026

Install to Claude Code

$npx -y skills add Nmor/the-claude-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/badge)](https://www.skillsdirectory.com/skills/nmor-python-patterns)

More formats (shields.io, HTML) on the badges page.

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"
---

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

Browser Extension Developer

Use this skill when developing or maintaining browser extension code in the `browser/` directory, including Chrome/Firefox/Edge compatibility, content scripts, background scripts, or i18n updates.

284972 votes

Seo Optimizer

SEO optimization with keyword analysis, readability assessment, technical validation, content quality. Use for search rankings, blog posts, content audits, or encountering keyword density, readability scores, meta tags, schema markup errors.

2222 votes

Google Official Seo Guide

Official Google SEO guide covering search optimization, best practices, Search Console, crawling, indexing, and improving website search visibility based on official Google documentation

1862 votes

Tanstack Start

Build a full-stack TanStack Start app on Cloudflare Workers from scratch — SSR, file-based routing, server functions, D1+Drizzle, better-auth, Tailwind v4+shadcn/ui. Use whenever the user mentions TanStack Start, asks to scaffold a full-stack Cloudflare app with SSR, wants an SSR dashboard, or asks for a React 19 + Cloudflare Workers app with file-based routing and server functions — even if they don't name TanStack Start specifically. No template repo — Claude generates every file fresh per ...

10311 votes

Pentest

PTES-aligned adversarial security audit for backend, frontend, and mobile applications. Produces a CVSS-scored Hacker Report with verified PoCs and phased remediation.

5491 votes
View all in development →