Skip to content
Back to skills

Python

ASecurity

This skill should be used when the user works with Python files (.py), asks about "type hints", "protocols", "dataclasses", "async/await", or discusses Pythonic patterns.

  • 23 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added September 3, 2026
developmentpythongoapi

Works with

  • api

Security analysis

A100/100

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

Scanned November 9, 2026

npx -y skills add dean0x/devflow --skill python --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Python?

Add the live security badge to your README. It updates with every re-scan.

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

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

Download with Pro
SKILL.md
---
name: python
description: This skill should be used when the user works with Python files (.py), asks about "type hints", "protocols", "dataclasses", "async/await", or discusses Pythonic patterns.
user-invocable: false
allowed-tools: Read, Grep, Glob
activation:
  file-patterns:
    - "**/*.py"
  exclude:
    - "venv/**"
    - ".venv/**"
    - "**/__pycache__/**"
---

# Python Patterns

## Iron Law

> **EXPLICIT IS BETTER THAN IMPLICIT** [3]
>
> Type-hint every function signature. Name every exception. Use dataclasses over raw
> dicts. Python's flexibility is a strength only when boundaries are explicit.

## Type Safety

- Annotate every parameter and the return: `def process(data: list[dict[str, Any]], config: AppConfig) -> ProcessResult`, not `def process(data, config)`.
- Use `from __future__ import annotations` for forward references, not string annotations (`x: "MyClass"`).
- Use `Protocol` for structural typing, over ABC: any class with matching methods satisfies it, with no `implements`.
- Write optionals as `User | None` (PEP 604), not `Optional[User]`, and handle `None` explicitly.

## Error Handling

- Define custom exception types: a base `AppError(Exception)` and subclasses (`NotFoundError`) that carry structured fields (`entity`, `id`).
- Catch named exceptions, `except (ValueError, KeyError):`. Never a bare `except:`: it catches `SystemExit`.
- Use context managers for resource cleanup and the unit of work: commit on success, roll back and re-raise on error.

## Data Modeling

- Use `@dataclass(frozen=True)` for internal value objects, with `field(default_factory=...)` for computed defaults.
- Use Pydantic models at API boundaries: they validate on instantiation (`EmailStr`, `Field(ge=0, le=150)`).
- Use `@dataclass` for domain objects and Pydantic for API models — not interchangeably, and not raw dicts.

## Pythonic Patterns

- Comprehensions over loops: `[u.name for u in users if u.active]`.
- `enumerate(items)`, not `range(len(items))`.
- EAFP over LBYL: `try: value = mapping[key]` with `except KeyError`.
- No mutable default arguments: `def fn(items: list | None = None)`, not `def fn(items=[])`.
- Compose smaller focused classes, not a 50-method god class.
- Tests use pytest fixtures, no repeated setup.

## Extended References

- `references/sources.md` — Full bibliography
- `references/patterns.md` — Extended patterns: DI, decorators, fixtures
- `references/violations.md` — Violation examples with citations
- `references/detection.md` — Grep patterns for Python issues
- `references/async.md` — Async patterns: gather, TaskGroup, generators

Files in this skill

  • SKILL.md4.5 KB
  • references/async.md7.9 KB
  • references/detection.md2.6 KB
  • references/patterns.md7.6 KB
  • references/sources.md4 KB
  • references/violations.md7.1 KB

Attribution

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

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.