hermes

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]) and X | None where the target version allows.
  • Avoid Any. Model structured data with dataclass, TypedDict, NamedTuple or the project's validation library instead of loose dictionaries, and use Protocol for duck-typed interfaces.

Files, paths and resources

  • Use pathlib.Path, not string concatenation or os.path joins.
  • Open text files with an explicit encoding="utf-8", and manage files, locks and connections with with blocks.
  • 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__), never print. Use print only 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: or except 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.run with a list of arguments and check=True. Never use shell=True with interpolated input.
  • Never use eval, exec or pickle on untrusted data. Build SQL with parameters, never with f-strings.
  • Never use mutable default arguments. Use None and create the value inside the function.

Layout and style

  • Follow the existing package layout. For new projects, use a src/ layout with pyproject.toml and tests under tests/.
  • Keep __init__.py to imports and exports. Guard script entry points with if __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

Edit on GitHubReport a problem

use in

Hodios CLI
npx @hermes-hq/hodios install python-style-rules --target claude-code
Agent Skills
npx skills add hermes-hq/hodios-dist --skill python-style-rules -a claude-code

Rules 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 Conventions
RuleTesting

Test-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-rules
RuleConventions

HTTP 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-rules
RuleConventions

C# 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-rules
RuleConventions

Go 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-rules
RuleConventions

Java 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-rules
RuleConventions

React 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