agentleFS
harshadmadayeharshadmadaye/OPM/skills/python-patterns/SKILL.md

python-patterns

Skill4 starsChanged 56 days agoMITView on GitHub

Provides idiomatic modern Python (3.11+) patterns covering type hints, dataclasses and pydantic at boundaries, pathlib, context managers, generators, async basics, explicit error handling, and a uv/ruff/pytest project layout. Use when writing, reviewing, or refactoring Python code or setting up a Python project.

76 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use upstash-qstash, nuxt4-patterns and 10 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • xfstudioSkill

    upstash-qstash

    Upstash QStash expert for serverless message queues, scheduled jobs, and reliable HTTP-based task delivery without managing infrastructure. Use when: qstash, upstash queue, serverless cron, scheduled http, message queue serverless.

    Also in 5 projects that use this

  • loulanyueSkill

    nuxt4-patterns

    Nuxt 4 app patterns for hydration safety, performance, route rules, lazy loading, and SSR-safe data fetching with useFetch and useAsyncData.

    Also in 14 projects that use this

  • RojiosSkill

    dart-flutter-patterns

    Production-ready Dart and Flutter patterns covering null safety, immutable state, async composition, widget architecture, popular state management frameworks (BLoC, Riverpod, Provider), GoRouter navigation, Dio networking, Freezed code generation, and clean architecture.

    Also in 10 projects that use this

  • royaluniondesign-sysSkill

    content-hash-cache-pattern

    Cache expensive file processing results using SHA-256 content hashes — path-independent, auto-invalidating, with service layer separation.

    Also in 23 projects that use this

  • TironFoxSkill

    agent-payment-x402

    Add x402 payment execution to AI agents — per-task budgets, spending controls, and non-custodial wallets via MCP tools. Use when agents need to pay for APIs, services, or other agents.

    Also in 8 projects that use this

  • junimnjwSkill

    ralphinho-rfc-pipeline

    RFC-driven multi-agent DAG execution pattern with quality gates, merge queues, and work unit orchestration.

    Also in 17 projects that use this

The file

We split this skill into the rules it gives an agent

6 rules. 0 are common, 1 is distinctive, and 5 are very specific to this project.

  • 0

    Common

    Most of the 73 edited versions we read keep these.

  • 1

    Distinctive

    This author's own choices. Worth a look.

  • 5

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Always-true conventions (PEP 8, annotations, immutability, specific exceptions, config and secrets, FastAPI) live in OPM's rules …

    line 11
  2. Distinctive:

    Explicit over implicit: No import-time side effects, no hidden global configuration.

    line 25
  3. Very specific:

    Read references/typing-and-data.md when annotating code or modelling data (dataclass, pydantic, Protocol).

    line 38
  4. Very specific:

    Read references/files-iteration-async.md when touching files, writing context managers or generators, or writing async code.

    line 39
  5. Very specific:

    Read references/errors-and-logging.md when designing exceptions, logging, or config, or reviewing for anti-patterns.

    line 40
  6. Very specific:

    Read references/project-and-testing.md when setting up a project (uv, ruff, pyright, pytest) or writing tests.

    line 41

“Common” is measured: kept by at least 6 in 10 of the 73 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Python Patterns

Readable, explicit, typed. These patterns target Python 3.11 or newer with uv for environments, ruff for lint and format, and pytest for tests.

Always-true conventions (PEP 8, annotations, immutability, specific exceptions, config and secrets, FastAPI) live in OPM's rules python/coding-style.md and python/testing.md (.claude/rules/opm/python/ once installed, rules/python/ in the plugin). This skill keeps the patterns and worked examples.

When to use

  • Writing new Python modules, packages, scripts, or services.
  • Reviewing Python diffs for idiom, typing, and error handling.
  • Setting up or modernising a Python project's tooling.

Core principles

  • Readability over cleverness. Names say what things hold; comprehension over a three-line loop, a function over a three-clause comprehension.
  • Explicit over implicit. No import-time side effects, no hidden global configuration.
  • EAFP where the exception is the normal control flow (try: d[key] except KeyError), LBYL where a check is cheaper and clearer (if path.exists() before a destructive operation).
  • Immutability by default: rule python/coding-style.md (Immutability).

Decision rules

  • dataclass for internal data you construct yourself; pydantic.BaseModel at system boundaries. Never pass raw dict[str, Any] deeper than the boundary.
  • pathlib everywhere, always encoding="utf-8".
  • Anything that acquires must release, and with is how Python says so.
  • asyncio for I/O-bound concurrency, a thread pool for blocking libraries, processes for CPU-bound work.

References

  • Read references/typing-and-data.md when annotating code or modelling data (dataclass, pydantic, Protocol).
  • Read references/files-iteration-async.md when touching files, writing context managers or generators, or writing async code.
  • Read references/errors-and-logging.md when designing exceptions, logging, or config, or reviewing for anti-patterns.
  • Read references/project-and-testing.md when setting up a project (uv, ruff, pyright, pytest) or writing tests.

Review checklist

  • Every public function is annotated; Any appears only at a justified boundary.
  • External input is validated into a model at the edge.
  • Files, sockets, locks, and transactions are opened with with.
  • No bare except; exceptions are chained; errors are logged once.
  • pathlib and encoding="utf-8" for all file access.
  • Async code has no blocking calls and bounds its concurrency.
  • ruff check, ruff format --check, pyright, and pytest all pass.

Related skills

  • opm:tdd-workflow - pytest RED/GREEN cycle with uv run pytest.
  • opm:verification-before-completion (full gate) - the uv/ruff/pytest gate sequence.
<!-- Adapted from affaan-m/ecc (MIT) -->

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.