PythonRule
by DUOMReport
Rules for Python projects: virtual environments, type hints, pathlib, tests with pytest, and no bare except.
Developer toolsLicense: CC0-1.0Updated yesterdayrule/python
Install
Run in your project folder (DuoM CLI: risk check, then write; undo with npx duom@1 undo)
npx duom@1 add rule/python --client claude-code
Writes to CLAUDE.md in your project (where Claude Code reads it). If the project has an AGENTS.md but no CLAUDE.md, DuoM creates CLAUDE.md starting with @AGENTS.md so Claude Code keeps reading it. Only the marked block is added; the rest of the file is left alone, and remove takes out only that block.
Manual: paste into CLAUDE.md
CLAUDE.md
<!-- duom:rule/python --> ## Python - Use the project's environment tool (uv, poetry or venv) and add dependencies through it, never with a global pip install. - Add type hints to function signatures. Use pathlib for paths and f-strings for formatting. - Catch specific exceptions; never use a bare except: or swallow errors silently. - Do not put secrets in code; read them from environment variables. - Write tests with pytest next to the change, and run them (plus the linter, e.g. ruff) before calling it done. <!-- /duom:rule/python -->
The rule
Python
- Use the project's environment tool (uv, poetry or venv) and add dependencies through it, never with a global pip install.
- Add type hints to function signatures. Use pathlib for paths and f-strings for formatting.
- Catch specific exceptions; never use a bare except: or swallow errors silently.
- Do not put secrets in code; read them from environment variables.
- Write tests with pytest next to the change, and run them (plus the linter, e.g. ruff) before calling it done.