python

python is a cursor rule for coding agents from adonai-labs/agent-runway. It costs 0 tokens per session (635 once invoked), scanned A, original, MIT.

A set of Python coding guidelines covering formatting, type hints, errors, asynchronous code, packaging, and tests. It applies to Python files and common Python project configuration files.

In plain words
What is it for?
Use it when writing or reviewing Python applications, libraries, asynchronous code, packages, and automated tests.
Why use it?
It helps avoid inconsistent style, vague types, swallowed exceptions, resource leaks, and errors that only appear after deployment.

Cursor rule

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/adonai-labs/agent-runway/python
Clone the repo
git clone --depth 1 https://github.com/adonai-labs/agent-runway

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for python

README.md
[![agentmods](https://agentmods.dev/badge/rules/adonai-labs/agent-runway/python.svg)](https://agentmods.dev/rules/adonai-labs/agent-runway/python)
Your own site
<a href="https://agentmods.dev/rules/adonai-labs/agent-runway/python"><img src="https://agentmods.dev/badge/rules/adonai-labs/agent-runway/python.svg" alt="Measured on agentmods" height="20"></a>
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 635 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.00635
Opus 5 $0.00000 $0.00318
Sonnet 5 $0.00000 $0.00127
Haiku 4.5 $0.00000 $0.00064

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

Security

Grade A, and why

python 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.

src/stacks/python/python.mdc · 64 lines

How it starts

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

Python Development Guidelines

Directives for Python development. Apply when working with .py files, pyproject.toml, or requirements files.


Code Style

  • Follow PEP 8; let black and ruff enforce formatting rather than hand-tuning.
  • Use snake_case for functions and variables, PascalCase for classes, UPPER_SNAKE for constants.
  • Keep functions small and single-purpose; prefer early returns over deep nesting.
  • Prefer comprehensions over manual loops for simple transformations, but not at the cost of readability.

Type Hints

  • Annotate public function signatures (parameters and return types).
  • Use from __future__ import annotations to simplify forward references.
  • Prefer X | None over Optional[X] on modern versions; use Protocol for structural typing.
  • Run a type checker (mypy or pyright) in CI; treat new type errors as failures.

Error Handling

  • Catch specific exceptions — never a bare except:.
  • Define custom exception types for domain errors; do not raise bare Exception.
  • Use context managers (with) for resources (files, sockets, locks, sessions).
  • Add context when re-raising: raise DomainError(...) from err.
  • Do not silently swallow exceptions; log with context or propagate.

Async Patterns

  • Use async/await for I/O-bound work; never call blocking I/O inside an async function.
  • Use asyncio.gather for concurrent awaits; asyncio.create_task to schedule.
  • Do not mix blocking libraries into the event loop — use async clients or run them in an executor.

Packaging and Imports

  • Prefer absolute imports; avoid wildcard from x import *.
  • Pin dependencies in pyproject.toml/lock files; keep runtime and dev dependencies separate.
  • Avoid mutable default arguments — use None and create the value inside the function.

Testing

  • Use pytest; name tests test_*.py.
  • Use fixtures for setup/teardown; mock external dependencies at the boundary.
  • Cover happy path, edge cases (empty, null, boundary), and failure paths.
  • Assert behaviour, not implementation detail.

Read the full file on GitHub · 64 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 · 64 lines · 0 tokens per session scan A 7d2e8f8d0df4

Subscribe to this mod's changes

python is a cursor rule published in the GitHub repository adonai-labs/agent-runway (2 stars, last pushed 15d ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 635 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-09-03.