python-coding-standards

A set of Python coding rules covering imports, naming, file handling, asynchronous code, and modern Python 3.13 practices.

In plain words
What is it for?
Use it when creating or reviewing Python code that must follow these conventions, including code using pathlib, Celery, and current type-union syntax.
Why use it?
It gives the coding agent consistent project rules, such as keeping imports at the top and using standard modern syntax.

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/technickai/ai-coding-config/python-coding-standards
Clone the repo
git clone --depth 1 https://github.com/TechNickAI/ai-coding-config

Made for: Cursor.

Per session 8 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,255 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 1 finding. Scan, not verified.
Origin 88% copy Near-identical to another mod 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.00008 $0.01255
Opus 5 $0.00004 $0.00628
Sonnet 5 $0.00002 $0.00251
Haiku 4.5 $0.00001 $0.00126

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

Security

Grade A, and why

python-coding-standards scanned grade A with 1 finding 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.

Makes network callslowCapability

Not a fault in itself. Listed so you know the mod talks to something, and to what.

response = requests.get(url)
Origin

This is a copy

88% identical to python-coding-standards — 26 lines differ, which has more behind it and is treated as the original. This page carries a canonical link to it rather than competing with it.

.cursor/rules/python/python-coding-standards.mdc · 170 lines

How it starts

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

Python Guidelines

Imports - NON-NEGOTIABLE

ALL imports go at the top of the file. Every single one. If you're even thinking about putting an import inside a function, stop.

Exception: circular import issues (genuinely rare).

Don't abbreviate packages ("pandas" not "pd", "numpy" not "np").

Modern Python

We use python 3.13+ and follow modern best practices:

  • Use Path lib for files instead of open
  • Use var!s instead of str(var)
  • Prefer walrus operator (:=) to reduce repetition in code
  • Use modern union syntax X | Y instead of Union[X, Y]
  • Use underscore separators in large numbers: Decimal(1_000_000) not Decimal("1000000")

Attribute and Method Naming

We make everything public by default. We're all consenting adults here.

Only use underscore prefix (_internal) when accessing something would genuinely break functionality - like thread locks or internal state that must be accessed through methods. This is extremely rare.

Async vs Sync

Default to synchronous code. We use Celery for background jobs with multiple workers, so we don't need async to free up CPU. Synchronous code is simpler, easier to debug, and easier to maintain.

When given a choice between sync and async, we choose sync.

def fetch_data(url: str) -> dict:
    response = requests.get(url)
    return response.json()

If a library only provides async API, we can wrap it with asyncio.run():

import asyncio

def sync_wrapper(param: str) -> dict:
    """Synchronous wrapper for async-only library"""
    return asyncio.run(async_library_call(param))

Async is appropriate for WebSocket connections, async-only libraries that can't be easily wrapped, or specific performance-critical paths where async provides clear, measured benefits. Ask for confirmation before introducing async patterns.

Exception Handling - READ THIS COMPLETELY

DO NOT SWALLOW ERRORS. This is the hill we die on.

Default: let exceptions bubble up. We use Sentry for centralized error tracking, so exceptions that bubble up get caught and reported automatically - we get alerted and can fix them. Write functions with NO try/except:

Read the full file on GitHub · 170 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 · 170 lines · 8 tokens per session scan A 7ef969c73603

Subscribe to this mod's changes

python-coding-standards is a cursor rule published in the GitHub repository TechNickAI/ai-coding-config (24 stars, last pushed 2mo ago), licensed MIT. It adds 8 tokens to every session and 1,255 once invoked, about $0.0000 per session on Opus 5. A static security scan graded it A with 1 finding (makes network calls). It is 88% identical to python-coding-standards, differing in 26 lines, and is treated as a copy.