api-pattern-python

A guide for adding Python modules, command-line commands, services, loaders, and validators by following the project’s existing structure. It is intended for Python projects managed with uv, a Python package and environment tool.

In plain words
What is it for?
Use it when adding a public module, CLI command, data loader, parser, validator, service function, exception, or package entry point to a Python project.
Why use it?
It prevents new code from using a different module layout, error style, or command setup than the rest of the project. It helps the developer locate a tested example before implementing similar work.

Skill for Claude CodeCodex

Part of the claude-code-sdlc plugin — 9 skills, 28 commands, 20 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/mckruz/claude-code-sdlc/api-pattern-python
Any agent
npx skills add MCKRUZ/claude-code-sdlc --skill api-pattern-python
Clone the repo
git clone --depth 1 https://github.com/MCKRUZ/claude-code-sdlc

Made for: Claude Code, Codex.

Or install claude-code-sdlc, the plugin that ships this one along with the rest of its 9 skills, 28 commands, 20 agents.

Per session 106 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 953 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. 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 $0.00106 $0.00953
Opus 5 $0.00053 $0.00477
Sonnet 5 $0.00021 $0.00191
Haiku 4.5 $0.00011 $0.00095

Measured 3d ago against content hash 7182a1c40d8d, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

api-pattern-python scanned grade A with 0 findings 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 3d 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.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

harness/packs/stacks/python/skills/api-pattern-python/SKILL.md · 63 lines

How it starts

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

API pattern — Python

Consistency is the point: the same kind of work looks the same everywhere, so the reviewer and the next agent read it without re-learning. You do not invent structure — you locate the codebase's canonical example and replicate it. The depth is in .claude/rules/project-structure.md.

Procedure

  1. Find the canonical example. If the spec names one under "Reuse this pattern," read it. Otherwise Grep for the nearest sibling of the same shape and pick the most recent, most-tested one — not the oldest. Useful anchors:

    • the package's public surface: src/*/__init__.py (what the codebase chooses to export)
    • a CLI command: Grep for argparse, add_parser(, @click.command, or @app.command
    • a loader/parser of the same input kind: Grep for yaml.safe_load, json.load, Path(
    • the project's exception base: Grep for class .*Error\( / Exception\)
    • the entry-point wiring: [project.scripts] in pyproject.toml
  2. Extract the pattern, don't paraphrase it. Note, from the example:

    • Layering — CLI/entry point (parses args, prints, sets the exit code) → service function (pure logic, returns values, raises domain errors) → I/O or client. Human output lives at the CLI layer only; the layer below it logs and returns.
    • The signature — fully annotated params and return. What typed object it returns (dataclass / TypedDict / model), not a raw dict[str, Any].
    • Validation — where external input is parsed into that typed object, at the boundary, once.
    • Error model — which domain exception it raises and from which base; what it deliberately does not catch. Confirm it never swallows (except: pass) and never bare-excepts.
    • Logginglogging.getLogger(__name__), structured, on failure paths.
    • Naming and placementsnake_case module under the right package, one concern per module.
    • The test shapetests/test_<module>.py, test_scenario_expected_result names, fixtures (tmp_path, monkeypatch) over setup methods, @pytest.mark.parametrize for variant cases.

Read the full file on GitHub · 63 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. 3d ago First seen · 63 lines · 106 tokens per session scan A 7182a1c40d8d

Subscribe to this mod's changes

api-pattern-python is a skill published in the GitHub repository MCKRUZ/claude-code-sdlc (4 stars, last pushed 5d ago), licensed MIT. It adds 106 tokens to every session and 953 once invoked, about $0.0005 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other skills, from other repositories

bump-dependency

Bumps a Python package dependency across Home Assistant Core integrations, regenerates core requirement files, runs verification tests and prek lint, and prepares a pull request with proper release/compare links.

home-assistant/core · 42 tokens

biopython

Comprehensive molecular biology toolkit. Use for sequence manipulation, file parsing (FASTA/GenBank/PDB), phylogenetics, and programmatic NCBI/PubMed access (Bio.Entrez). Best for batch processing, custom bioinformatics pipelines, BLAST automation. For quick lookups use gget; for multi-service integration use…

K-Dense-AI/scientific-agent-skills · 76 tokens

marimo-pair

Work inside the user's live marimo notebook from the code editor: run Python in the same kernel the user does, inspect live notebook state, and commit durable notebook changes through code mode. Use whenever you create, analyze, or improve the user's marimo notebook.

marimo-team/marimo · 57 tokens

adk-style

Python style and codebase conventions for ADK (Agent Development Kit): private-by-default file visibility, imports, type hints, Pydantic v2 models, formatting, docstrings, logging, async I/O, file and test layout, and unit test structure. Use when writing or editing ADK source or tests, deciding whether a new file or…

google/adk-python · 187 tokens

coding

编写并运行 Python 代码,验证脚本逻辑和输出。.

bojieli/ai-agent-book · 18 tokens

ax-python-agent

Use when writing Python code with axllm for agents, child delegation, tools, MCP, citations, persistent playbook learning, stage instructions, runtime state, final typed responses, and direct-respond executor skipping.

ax-llm/ax · 49 tokens