agentleFS
HermeticOrmusHermeticOrmus/python-conventions-skills/CLAUDE.md

python-conventions-skills

CLAUDE.md2 starsChanged 6 months agoMITView on GitHub

Python conventions for modern (3.11+) projects. Apply to every .py, pyproject.toml, and requirements*.txt. Tradeoff: bias toward strict-but-modern defaults. For one-off scripts or legacy codebases (3.8-, untyped, old Django), use judgment. A new Python project starts with: License: MIT.

The file

We split this CLAUDE.md into the rules it gives an agent

1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Never time.sleep() in async code — await asyncio.sleep() only

    line 27

≈ “Common” is an estimate: at least 1 in 5 of the 26,980 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
CLAUDE.md

CLAUDE.md

Python conventions for modern (3.11+) projects. Apply to every .py, pyproject.toml, and requirements*.txt.

Tradeoff: bias toward strict-but-modern defaults. For one-off scripts or legacy codebases (3.8-, untyped, old Django), use judgment.

Type discipline

  • Type hints required on every function signature, public attribute, and return value
  • from __future__ import annotations at top of files — gives forward-reference types and PEP 604 union (A | B) on older runtimes
  • Pydantic v2 for any external/IO model — never plain dict[str, Any] at API boundaries
  • TypedDict for internal dict shapes that don't need validation
  • Literal["a", "b"] for string-literal enums (lighter than enum.Enum)

Stdlib preferences

  • pathlib.Path over os.path — composable, type-safe
  • dataclasses (or Pydantic) over manually-written __init__ for data containers
  • subprocess.run() over os.system — actual return-code handling
  • f-strings over % or .format() — except for logging, where lazy formatting matters
  • match statements (3.10+) for tagged-union dispatch — cleaner than chained isinstance

Async

  • async def end-to-end — don't mix sync requests into an async stack; use httpx
  • asyncio.gather for parallel; asyncio.TaskGroup (3.11+) for structured concurrency with proper cancellation
  • Never time.sleep() in async code — await asyncio.sleep() only

Logging

  • structlog if available in the project; else stdlib logging with structured extras
  • Never print() in library code — only allowed in CLIs / scripts where stdout is the deliverable
  • Lazy formatting: logger.info("user %s logged in", user_id) not logger.info(f"user {user_id}...") — avoids string interpolation when log level is filtered

Tooling defaults

  • ruff for lint + format (replaces black + flake8 + isort)
  • mypy --strict for type checking when the codebase tolerates it
  • pytest with fixtures over class-based setup/teardown
  • uv over pip for new projects (faster, lockfile by default)

Anti-patterns

  • Bare except: clauses (catches KeyboardInterrupt, SystemExit — almost never what you want)
  • Mutable default arguments (def f(x=[]): — use None and assign inside)
  • Catching exception just to re-raise (except Exception: raise — pointless)
  • Stringly-typed return contracts (return enum/Literal/dataclass, not arbitrary strings)
  • eval() / exec() on user input
  • from foo import *

Project setup

A new Python project starts with:

# pyproject.toml
[project]
name = "your-project"
version = "0.1.0"
requires-python = ">=3.11"

[tool.ruff]
target-version = "py311"
line-length = 100

[tool.ruff.lint]
select = ["E", "F", "I", "N", "W", "UP", "B", "C4", "SIM", "RET"]
ignore = ["E501"]  # line length — ruff format handles it

[tool.mypy]
strict = true
python_version = "3.11"

[tool.pytest.ini_options]
testpaths = ["tests"]
# Initialize
uv init
uv add ruff mypy pytest
uv add --dev pytest-cov

License: MIT.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.