Python style rules
Standing rules for Python an assistant writes, covering type hints, pathlib, logging over print, explicit exceptions, safe subprocess calls, project layout and the project's own tooling.
When you write or change Python code in this project:
Version and tooling
- Target the Python version declared in
pyproject.toml(requires-python). Do not use syntax or standard-library features newer than that. - Use the formatter, linter and type checker the project already configures (for example ruff, black, mypy or pyright) with its settings. Do not add new tools or reformat code you did not change.
- Add or change dependencies only through the project's tool (uv, poetry, pip-tools or similar) so the lock file stays in sync. Never install packages globally.
Types
- Annotate every function and method signature, including return types. Use built-in generics (
list[str],dict[str, int]) andX | Nonewhere the target version allows. - Avoid
Any. Model structured data withdataclass,TypedDict,NamedTupleor the project's validation library instead of loose dictionaries, and useProtocolfor duck-typed interfaces.
Files, paths and resources
- Use
pathlib.Path, not string concatenation oros.pathjoins. - Open text files with an explicit
encoding="utf-8", and manage files, locks and connections withwithblocks. - Use timezone-aware datetimes (
datetime.now(tz=UTC)); never mix naive and aware values.
Logging and output
- In library and service code, log through
logger = logging.getLogger(__name__), neverprint. Useprintonly for a command-line program's intended output. - Pass values as logging arguments (
logger.info("loaded %d rows", n)) instead of formatting the string yourself, and never log secrets, tokens or personal data.
Errors
- Catch the narrowest exception that you can handle. Never write a bare
except:orexcept Exception: pass. - Re-raise with context (
raise ConfigError("missing DB_URL") from err) and give messages that say what failed and what to do. - Validate input at the boundaries (CLI arguments, HTTP handlers, file parsing), not deep inside the code.
Safety
- Call
subprocess.runwith a list of arguments andcheck=True. Never useshell=Truewith interpolated input. - Never use
eval,execorpickleon untrusted data. Build SQL with parameters, never with f-strings. - Never use mutable default arguments. Use
Noneand create the value inside the function.
Layout and style
- Follow the existing package layout. For new projects, use a
src/layout withpyproject.tomland tests undertests/. - Keep
__init__.pyto imports and exports. Guard script entry points withif __name__ == "__main__":. - Use f-strings for formatting. Keep comprehensions to one level of nesting; use a loop when the logic needs more.
- Write docstrings for public modules, classes and functions that say what they do and what they raise, not how.
details
- kind
- Rule: standing instructions for everything the assistant does
- domain
- Software engineering
- category
- Conventions
- made for
- Software engineer, Backend engineer, Data engineer, ML / AI engineer
- risk
- read-only
- version
- v1.0.0 · experimental
- reviewed
- 2026-10-02
- works in
- Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Antigravity, OpenCode, Windsurf, Zed, Continue, AGENTS.md, ChatGPT, claude.ai
use in
npx @hermes-hq/hodios install python-style-rules --target claude-codenpx skills add hermes-hq/hodios-dist --skill python-style-rules -a claude-codeRules are always-on instructions, so they are not in the plugins: add the skill, or paste the text into CLAUDE.md.
pairs well with
All of ConventionsTest-writing rules
Standing rules for tests an assistant writes, covering behaviour over implementation, no sleeps, deterministic data, mocks only at boundaries and one reason to fail per test.
test-writing-rulesHTTP API design rules
Rules for HTTP APIs covering resource naming, status codes, problem+json errors, cursor pagination, idempotency keys and versioning. Load when designing or changing HTTP endpoints.
api-design-rulesC# style rules
Standing rules for C# an assistant writes, covering nullable reference types, async all the way with cancellation tokens, records and pattern matching, dependency injection and xUnit tests.
csharp-style-rulesGo style rules
Standing rules for Go an assistant writes, covering wrapped errors, context propagation, small consumer-side interfaces, table-driven tests and no goroutines without an owner.
go-style-rulesJava style rules
Standing rules for Java an assistant writes, covering modern language features, immutability, Optional and null handling, exceptions, restrained streams, records and JUnit 5 tests.
java-style-rulesReact component rules
Standing rules for React code an assistant writes, covering function components, the rules of hooks, colocated state, stable list keys, accessible markup and no effect-driven derived state.
react-component-rules