python-conventions
Skill7 starsChanged 2 days agoMITView on GitHub
Python projects: uv, ruff, typer, pydantic, Pylance, test coverage. TRIGGER when: editing or creating `.py` files; touching `pyproject.toml`, `uv.lock` or `.python-version`; adding a Python dependency; setting up a Python CLI, config layer or data model; measuring test coverage; user asks about Python tooling, types or env vars. SKIP when: no Python is involved. Load `python-async-conventions` alongside for asyncio loops.
9 other projects use a version of this.
Adopted by
Most recently taken up by
- vivienm/skillstheir own version, first seen Nov 29, 2026
- leroyguillaume/skillsword for word, first seen Nov 22, 2026
- NicoGenti/opencode-orchestrator-kittheir own version, first seen Nov 8, 2026
- ek33450505/claude-agent-teamtheir own version, first seen Oct 25, 2026
- andr-ca/agentharnesstheir own version, first seen Oct 15, 2026
- wtsi-hgi/agentskillstheir own version, first seen Oct 4, 2026
Other versions9 projects use a version of this.
Word for word · 1
- leroyguillaume/skills★ 7100% same
Edited · 0
None found.
Wrote their own version · 8
- tae0y/python-project-template★ 14same name
- NicoGenti/opencode-orchestrator-kit★ 9same name
- ek33450505/claude-agent-team★ 8same name
- HermeticOrmus/python-conventions-skills★ 2same name
- andr-ca/agentharness★ 1same name
- wtsi-hgi/agentskills★ 1same name
- techmefr/mentis★ 0same name
- vivienm/skills★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository54 other files it gives its agents.
- adr-conventionsSkill
- api-conventionsSkill
- architecture-conventionsSkill
- argocd-conventionsSkill
- ci-conventionsSkill
- config-conventionsSkill
- contributing-conventionsSkill
- councilSkill
- cryptography-conventionsSkill
- dependency-update-conventionsSkill
- diagram-conventionsSkill
- docker-conventionsSkill
- documentation-conventionsSkill
- frontend-conventionsSkill
- github-actions-conventionsSkill
- github-issue-conventionsSkill
- github-pr-conventionsSkill
- github-repo-settingsSkill
- gitlab-ci-conventionsSkill
- helm-conventionsSkill
- herdr-core-delegationSkill
- herdr-delegationSkill
- herdr-tui-delegationSkill
- kopf-conventionsSkill
- kubernetes-operator-conventionsSkill
- logging-conventionsSkill
- logo-conventionsSkill
- mise-conventionsSkill
- ollama-conventionsSkill
- openssf-conventionsSkill
- pr-conventionsSkill
- pre-commit-conventionsSkill
- project-metadata-conventionsSkill
- python-async-conventionsSkill
- readme-conventionsSkill
- release-script-conventionsSkill
- release-supply-chain-conventionsSkill
- renovate-ci-conventionsSkill
- rest-conventionsSkill
- rust-build-conventionsSkill
- rust-conventionsSkill
- rust-http-conventionsSkill
- security-policy-conventionsSkill
- signal-handling-conventionsSkill
- sql-conventionsSkill
- starlight-conventionsSkill
- systemd-conventionsSkill
- system-user-conventionsSkill
- task-conventionsSkill
- terraform-conventionsSkill
- topic-splittingSkill
- ui-copy-conventionsSkill
- web-layout-conventionsSkill
- yaml-conventionsSkill
The file
We split this skill into the rules it gives an agent
12 rules. 0 are common, 1 is distinctive, and 11 are very specific to this project.
0
Common
Most of the 8 edited versions we read keep these.
1
Distinctive
This author's own choices. Worth a look.
11
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 30
Use pyproject.toml as the single source of truth for metadata, dependencies, and tool configuration (ruff, pytest, etc.).
- Very specific: line 32
Use uv for dependency and environment management: uv init, uv add, uv sync, uv run, uv lock.
- Very specific: line 38
Add astral-sh/ruff-pre-commit to .pre-commit-config.yaml with both ruff-check and ruff-format hooks.
- Distinctive: line 54
When pyright and ruff disagree on a stylistic point, prefer the change that satisfies both.
- Very specific: line 153
Never use pip, poetry, pipenv, or conda.
- Very specific: line 154
Never create a setup.py, setup.cfg, requirements.txt, ruff.toml, or pytest.ini.
- Very specific: line 156
Never hand-edit dependency files.
- Very specific: line 157
Never read config via os.environ.get(...) scattered through the code.
- Very specific: line 159
Never declare typer parameters with the legacy param: T = typer.Option(default, ...) form.
- Very specific: line 161
Never silence a Pylance / pyright diagnostic with # type: ignore, # pyright: ignore, or cast() without a one-line comment explaining why …
- Very specific: line 165
Never pass a dict[str, Any] (or a positional tuple) between functions as a stand-in for a record whose fields are known, and never annotate …
- Very specific: line 169
Never use print() for diagnostics.
“Common” is measured: kept by at least 6 in 10 of the 8 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Python conventions
Always:
- Name every variable, function, method, attribute, and model field in
snake_case(PEP 8). This holds for Pydantic models too — never declare literalcamelCasefield names. When a model serialises to a wire format that wantscamelCase(a Kubernetes CRD, acamelCaseJSON API), keep the Python fieldssnake_caseand let an alias bridge the gap: setalias_generator=to_camel,validate_by_name=Trueandserialize_by_alias=Trueon the base model'sConfigDict(Pydantic ≥ 2.11;populate_by_nameis discouraged there), soendpoint_urlbecomesendpointUrlon the wire while Python stays idiomatic, and either spelling is accepted on the way in. Keep ruff'sN815(mixed-case class variable) enabled — it is the guard that catches a straycamelCasefield. Ruff's default rule set does not includepep8-naming, soselectmust list"N", andN815never goes inignore. - Use
pyproject.tomlas the single source of truth for metadata, dependencies, and tool configuration (ruff,pytest, etc.). - Use
uvfor dependency and environment management:uv init,uv add,uv sync,uv run,uv lock. Commituv.lock. - Pin Python and uv in
mise.toml, never in a.python-version(mise-conventions). - Format and lint with
ruff(ruff format+ruff check --fix). Configure inpyproject.toml. - Add
astral-sh/ruff-pre-committo.pre-commit-config.yamlwith bothruff-checkandruff-formathooks. Type-check with
pyrightas a blocking pre-commit hook, on the same footing asruff:RobertCraigie/pyright-python, hook idpyright, the wrapper pyright's own docs point to. Pylance runs pyright, so it is the editor view of the same diagnostics, not a separate gate. The hook runs in its own virtualenv, so point pyright at the project's inpyproject.toml, or every third-party import is unresolved:[tool.pyright] venvPath = "." venv = ".venv"Fix every reported error and warning before considering a change done. When pyright and ruff disagree on a stylistic point, prefer the change that satisfies both; never silence one to keep the other happy.
Measure test coverage with coverage.py through
pytest-cov(ci-conventions): coverage.py is the reference tool, and the plugin runs it from thepytestcall contributors already make,pytest-xdistworkers included. It is a dev dependency (uv add --dev pytest-cov), souv.lockpins it, notmise.toml. Branch coverage is free here, so on:[tool.coverage.run] branch = true source = ["<package>"]coverage: desc: Run the tests and measure their line and branch coverage cmds: - uv run pytest --cov --cov-report=term --cov-report=html {{.CLI_ARGS}} coverage:summary: desc: Print the summary of the last coverage run cmds: - uv run coverage reportThe HTML report lands in
htmlcov/; gitignore it with.coverageandcoverage.xml. On GitLab, add--cov-report=xml(Cobertura, incoverage.xml); the job's regex is/^TOTAL.*\s(\d+(?:\.\d+)?)%/.- Build CLIs with
typer, every option carrying itsenvvar=..., or usepydantic-settingsfor richer config models (env_prefix="mytool_"for a CLI). Precedence and variable names followconfig-conventions. - Declare
typerparameters withAnnotated[T, typer.Option(...)] = default, notparam: T = typer.Option(default, ...). TheAnnotatedform keeps the default value in the standard Python position and is the formtyperrecommends. Example:from pathlib import Path from typing import Annotated import typer def sync( config_file: Annotated[ Path, typer.Option(envvar="MYTOOL_CONFIG_FILE", help="Config file") ] = Path("mytool.toml"), ) -> None: ... - Apply
logging-conventions. Python mechanics: use the standardloggingmodule (orstructlogwhen the project already does), configured once at process start; the level and the format are options of thetyper/pydantic-settingsconfig layer (names inconfig-conventionsandlogging-conventions), the format choosing the formatter. Log structured key-values (logger.debug("fetched", extra={"url": url, "status": resp.status})), never f-string interpolation of values into the message. The defaultloggingformatter silently dropsextra=fields, so install a structured (JSON or key=value) formatter that renders them; and anextrakey that clashes with aLogRecordattribute (name,message,module, …) raisesKeyError. - In a long-running process, apply
signal-handling-conventions. Python mechanics: Python's defaultSIGTERMaction kills the process with no cleanup, andKeyboardInterruptonly coversSIGINT. In asyncio, register both on the running loop and drive shutdown from one event:
A server or worker loop then exits oncestop = asyncio.Event() loop = asyncio.get_running_loop() for sig in (signal.SIGTERM, signal.SIGINT): loop.add_signal_handler(sig, stop.set)stopis set, after draining. A synchronous loop installssignal.signalfor both and checks a flag between units of work.add_signal_handleris unix-only, which is the right default for a Linux-container target. Model structured data with an explicit type, never a bare
dict/tuplethreaded through the code as an ad-hoc record. As soon as a value has a known, fixed set of fields:- First, reuse the canonical type if one already exists in the
standard library or a dependency you already have (e.g.
kubernetes.client.V1OwnerReference, an SDK's request/response model, a protobuf/dataclassthe API ships). Do not hand-roll a parallel model of something a depended-upon library already defines — convert at the edges with the library's own serializer (ApiClient().sanitize_for_serialization,.model_dump(), …). A request or response body your own API exposes is the exception: it gets a DTO of its own (api-conventions). - Otherwise define one: a
pydantic.BaseModelwhen it crosses an I/O, serialization, or API boundary (parsed from / rendered to JSON, YAML, a request, a manifest, …) — the default in a Pydantic codebase; a@dataclass(frozen=True)for an internal value object that never leaves the process; aTypedDictonly when an external API hands you adictyou do not construct yourself and a model wrapper would be pure overhead.
Reserve
dict[...]/Mappingfor genuinely dynamic maps whose keys are data, not field names. Construct the type at the boundary where the data enters and pass the typed object onward; do not pass the rawdict.- First, reuse the canonical type if one already exists in the
standard library or a dependency you already have (e.g.
Never:
- Never use
pip,poetry,pipenv, orconda. - Never create a
setup.py,setup.cfg,requirements.txt,ruff.toml, orpytest.ini. All config lives inpyproject.toml. - Never hand-edit dependency files; use
uv add/uv remove. - Never read config via
os.environ.get(...)scattered through the code; route everything through thetyper/pydantic-settingslayer. - Never declare
typerparameters with the legacyparam: T = typer.Option(default, ...)form; useAnnotatedinstead. - Never silence a Pylance /
pyrightdiagnostic with# type: ignore,# pyright: ignore, orcast()without a one-line comment explaining why the type checker is wrong and why the cast is safe. If you can fix the underlying type instead, do that. - Never pass a
dict[str, Any](or a positionaltuple) between functions as a stand-in for a record whose fields are known, and never annotate a parameter or return as a broaddict/tuplewhen the shape is fixed and knowable — define the type and use it. - Never use
print()for diagnostics; route everything through the configured logger.
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
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.

