Skip to content
Back to skills

Python Style Rules

ASecurity

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.

  • 2 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added November 26, 2026
ai-agentspythonrustgoshellsql

Works with

  • cli

Security analysis

A100/100

Pro scans all 2 files and shows the line behind each finding

Scanned November 26, 2026

npx -y skills add hermes-hq/hodios-dist --skill python-style-rules --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Python Style Rules?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Python Style Rules
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/hermes-hq-python-style-rules/badge)](https://www.skillsdirectory.com/skills/hermes-hq-python-style-rules)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: python-style-rules
description: 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.
license: CC0-1.0
metadata:
  version: 1.0.0
  kind: rule
  category: conventions
  source: https://hermes-ide.com/prompts/python-style-rules
  catalog: 2026.1014.1
---

# Python style rules

Apply these rules to files matching: `**/*.py`.

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.

Files in this skill

  • SKILL.md3.2 KB
  • agents/openai.yaml297 B

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.