Guide Python development with greenfield defaults and brownfield flexibility. Apply when writing, maintaining, or reviewing Python code to ensure consistency with modern tooling (uv, ruff, ty, pytest, pre-commit) and patterns (CLI separation, type safety, error handling).
make install && make check passes before first commit
pre-commit install enabled
See tooling.md for copy-paste templates.
1---2name: python-development3description: Guide Python development with greenfield defaults and brownfield flexibility. Apply when writing, maintaining, or reviewing Python code to ensure consistency with modern tooling (uv, ruff, ty, pytest, pre-commit) and patterns (CLI separation, type safety, error handling).4---56# Python Development78Apply this skill when writing, maintaining, or reviewing Python code.910---1112## Supporting Files1314- **[tooling.md](tooling.md)** — Copy-paste templates for greenfield project setup (pyproject.toml, Makefile, .pre-commit-config.yaml)15- **[code-style.md](code-style.md)** — Style rules and conventions (naming, formatting, type hints, imports)16- **[patterns.md](patterns.md)** — Architecture patterns (CLI/core separation, exception hierarchy, error handling)1718---1920## Mode Detection2122Detect the mode from the user's request before acting:2324| Signal | Mode |25|---|---|26| "write", "create", "add", "scaffold", "implement", "new" | **WRITE** |27| "fix", "refactor", "update", "change", "migrate", "improve" | **MAINTAIN** |28| "review", "check", "audit", "look at", "what do you think" | **REVIEW** |2930---3132## WRITE Mode3334### Step 1: Greenfield or brownfield?3536**Greenfield** (new project or new module in a greenfield project):37- Use templates from [tooling.md](tooling.md) verbatim — don't approximate38- Apply src/ layout, hatchling build system, full tooling stack39- Apply all rules below from the start4041**Brownfield** (inheriting existing code):42- Read existing code first with Read/Grep before writing anything43- Match existing patterns — don't retrofit greenfield defaults44- Use the brownfield decision tree at the bottom of this file4546### Step 2: Apply these rules when writing any code4748**Functions and modules:**49- Every function and module gets a docstring summary (one line is enough; add more lines only when behavior is non-obvious)50- Every function gets full type hints using modern syntax (`str | None`, `list[str]`, not `Optional`, not `Union`)51- See [code-style.md](code-style.md) for all style rules5253**Error handling:**54- Raise domain exceptions in core logic, catch at the CLI layer — never both55- Always chain exceptions: `raise AppError("msg") from e`56- See [patterns.md](patterns.md) for exception hierarchy and CLI/core separation5758**Structure:**59- Separate CLI layer (parse args + display output) from core layer (pure logic, no CLI imports)60- Use `pathlib.Path` for all file operations — never `os.path` or string concatenation61- Use `@dataclass` for any domain model with 2+ fields6263**Output:**64- Default to `typer.echo` — don't add Rich or logging unless the user asks for a `--verbose` flag6566**Config:**67- Use `tomllib` (stdlib) + TOML file — not Pydantic, not env vars68- Env vars only for secrets or CI overrides6970**Tests:**71- Class-based: `class TestFoo`, `def test_scenario`72- `conftest.py` for shared fixtures73- `tmp_path` for filesystem, `monkeypatch` for env vars74- Test core logic directly; test CLI only for argument parsing and exit codes7576---7778## MAINTAIN Mode79801. **Read before writing** — use Read/Grep to understand the existing code812. **Match existing patterns** — preserve the style even if it differs from greenfield defaults823. **Run checks after editing** — ask the user to run `make check` to validate834. **Don't change tooling** unless the user explicitly asks8485For brownfield codebases: apply only the brownfield decision tree below.8687---8889## REVIEW Mode9091Go through the code and report findings in two categories:9293### Blockers (must fix)94- [ ] Bare `except:` or `except Exception` without re-raising95- [ ] Unused imports or dead code96- [ ] Secrets or credentials hardcoded in source9798### Nits (suggest, don't block)99- [ ] Missing type hints on function signatures100- [ ] Missing docstrings on functions or modules101- [ ] Hardcoded values that should be module-level constants or config102- [ ] Exception not chained with `from e` when re-raising103- [ ] `os.path` or string paths instead of `pathlib.Path`104- [ ] Mutable default arguments (`def f(x=[])`)105- [ ] Wrong exception type (raising base `Exception` instead of domain-specific)106- [ ] Tests touching real filesystem or env vars without `monkeypatch`/`tmp_path`107108When a blocker is found, grep for the same pattern across the codebase and report all instances.109110---111112## Brownfield Decision Tree113114**Build system?**115- Exists (Poetry, setup.cfg, etc.) → keep it116- Missing → migrate to hatchling117118**Python version?**119- 3.11 or older → keep it, don't force upgrade120- 3.12+ → align with greenfield defaults121122**CLI framework?**123- Click or Typer → already aligned, keep it124- argparse or custom → refactor only if actively developing125- No CLI → leave as-is126127**Type hints?**128- 80%+ coverage → run `ty check --strict`129- <80% → run `ruff check` only, skip ty130- 0% → run tests only131132**Test count?**133- 50+ tests → consider unit/cli split134- <50 → keep flat `tests/` directory135136**Minimal acceptable setup for any brownfield project:**137```makefile138make install # install deps139make test # run tests140make lint # check style141make check # all of the above142```143144---145146## Greenfield Checklist147148- [ ] `.python-version` set to `3.12`149- [ ] `pyproject.toml` with hatchling, `requires-python = ">=3.12"`, `[dependency-groups] dev`150- [ ] `Makefile` with: `install`, `test`, `test-v`, `lint`, `format`, `fix`, `typecheck`, `check`, `clean`151- [ ] `.pre-commit-config.yaml` with ruff + ty hooks152- [ ] `src/my_project/` with `cli.py`, `commands/`, `core/`153- [ ] `tests/` with `conftest.py`154- [ ] `make install && make check` passes before first commit155- [ ] `pre-commit install` enabled156157See [tooling.md](tooling.md) for copy-paste templates.
Run npx skillmds@latest add jmlrt/python-development in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
Guide Python development with greenfield defaults and brownfield flexibility. Apply when writing, maintaining, or reviewing Python code to ensure consistency with modern tooling (uv, ruff, ty, pytest, pre-commit) and patterns (CLI separation, type safety, error handling). It is listed under Coding & Dev Tools on SkillMD.
This skill has not completed SkillMD's automated safety review yet. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
jmlrt (@jmlrt) published this skill. Their other Agent Skills are listed on their SkillMD profile.