10-python-standards

General rules for writing Python code, covering types, function design, classes, and error handling.

In plain words
What is it for?
Adding type annotations, designing small functions and classes, choosing structured data models, and handling errors in Python projects.
Why use it?
They encourage code that is explicit, maintainable, and easier to check, while discouraging vague names and untyped data.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/pueraeternis/agentic-project-template/10-python-standards
Clone the repo
git clone --depth 1 https://github.com/pueraeternis/agentic-project-template

Made for: Cursor.

Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 590 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.00590
Opus 5 $0.00000 $0.00295
Sonnet 5 $0.00000 $0.00118
Haiku 4.5 $0.00000 $0.00059

Measured yesterday against content hash 5967ec1bf101, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

10-python-standards scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/10-python-standards.mdc · 197 lines

How it starts

The opening of the file, as written. The whole thing — 197 lines — stays where its author put it; the contents beside it link to each section on GitHub.


Python Engineering Standards

These rules apply to Python source code.

Project-specific conventions documented in ENGINEERING.md take precedence over these defaults.


Type Safety

Use type annotations for all public functions, methods, and module-level constants where appropriate.

Prefer explicit types over Any.

Prefer structured domain models over untyped dictionaries.

Prefer:

  • explicit return types;
  • typed collections;
  • dataclasses or Pydantic models where appropriate;
  • Protocol for behavioral interfaces.

Avoid unnecessary use of:

  • Any;
  • dict[str, Any];
  • untyped containers.

Function Design

Functions should:

  • have a single responsibility;
  • have explicit inputs and outputs;
  • minimize side effects;
  • remain reasonably small.

Prefer pure functions whenever practical.

Use descriptive names that express business intent.

Avoid vague names such as:

def process(data):
    ...

Class Design

Classes should have a single responsibility.

Prefer composition over inheritance.

Prefer dependency injection over hidden global state.

Avoid deep inheritance hierarchies unless clearly justified.


Error Handling

Raise exceptions that accurately describe failures.

Catch only exceptions that can be handled meaningfully.

Never silently ignore exceptions.

Avoid:

except Exception:
    pass

Exception messages should help diagnose the problem.


Logging

Use the project's logging framework.

Prefer parameterized logging.

Example:

logger.info("Created task %s", task_id)

Avoid:

logger.info(f"Created task {task_id}")

Never use print() outside CLI utilities or interactive scripts.


Imports

Keep imports at module level.

Avoid:

  • circular dependencies;
  • import-time side effects;
  • unnecessary dynamic imports.

Use TYPE_CHECKING for type-only imports that would otherwise create dependency cycles.

Group imports according to PEP 8.

Read the full file on GitHub · 197 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 197 lines · 0 tokens per session scan A 5967ec1bf101

Subscribe to this mod's changes

10-python-standards is a cursor rule published in the GitHub repository pueraeternis/agentic-project-template (2 stars, last pushed 2mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 590 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.