conventions-python
MANDATORY for any work on Python files (*.py). Load this before editing, reviewing, or creating any *.py file. House Python 3.12+ conventions covering…
by Integralist★ 31 GitHub stars
Install conventions-python in Claude Code & Claude Desktop
Sign up to install this skill
Create a free account to reveal the install command and save the skill to your library.
- Reveal the one-line install command
- Save skills to your synced library
- Get notified when skills update
About this skill
[!NOTE] If invoked directly with no specific task, load these conventions and stop.
House deltas for Python. Target Python 3.12+ unless pyproject.toml or
.python-version pins an older runtime. In an established repo, match its
existing patterns.
Tooling
Use uv for environments/dependencies (uv sync, uv add, uv run). Before
finishing Python changes, run (or use the repo's Make/lint targets):
ruff format .
ruff check --fix .
uv run mypy . # or `uv run pyright .` where the repo uses it
uv run pytest # narrow with path or -k when iterating
Fix root causes over suppressions; if needed, name exact codes
(# noqa: F401, # type: ignore[assignment]). For new projects, configure
pyproject.toml with ruff (line-length = 88, rules
E, W, F, I, B, UP, RUF), mypy (strict = true, warn_return_any = true,
warn_unused_configs = true), and pytest (testpaths = ["tests"]).
Comments and docstrings
Give every module, class, function, and method (public or private) a docstring, and put a comment above every module-level constant and every dataclass or Pydantic field. State what it is or does and why it exists (constraint, policy, invariant, or caller need), describing observable effect rather than steps, and never restating the name.
Types and data
- Annotate all function parameters and return types. Use modern 3.12+ syntax:
X | Y, built-in generics (list[str]),collections.abcabstractions (Sequence,Mapping,Callable), PEP 695 type parameters (def first[T](items: Sequence[T]) -> T) andtype UserID = str,Self, andProtocol. AvoidAny; use a precise type, type param, orobject. - Data structures:
@dataclass(frozen=True, slots=True)for internal values; PydanticBaseModelfor boundaries, JSON, and settings;StrEnum(orEnum) for fixed sets.
Idioms, errors, async, and logging
- Export explicit public APIs via
__all__in__init__.pyand multi-module packages; nofrom x import *. - Use
pathlib.Path(passingencoding="utf-8"for text), context managers for resources, and guard clauses to keep nesting shallow. - Give each module/service a base exception inheriting
Exception(neverBaseException), chain withraise ... from err, and avoid bareexcept:. - Use
asyncio.TaskGroup(notgather),asyncio.timeout(notwait_for), andasyncio.to_threadfor blocking work. - Log via
logging.getLogger(__name__)orstructlog(neverprint()) with lazy%sarguments rather than f-strings.
Testing
- Use
pytest(test_*.py,test_*),@pytest.fixture,@pytest.mark.parametrize,pytest.raises(..., match=...), andunittest.mock/pytest-mock. Add a brief docstring on each test stating what it proves. - Test through public APIs—don't import
_-prefixed internals or assert on private attributes. Extract complex internal logic into a focused submodule with a public API if needed. - Put integration tests in
tests/integration/ortests/e2e/against a real app instance (e.g.httpx.AsyncClient+ASGITransport), overriding only at wire/storage boundaries.
Allowed tools
Tools this skill is permitted to call.
No restriction — this skill can use any tool.
FAQ
What does the conventions-python skill do?
MANDATORY for any work on Python files (*.py). Load this before editing, reviewing, or creating any *.py file. House Python 3.12+ conventions covering uv/ruff/mypy tooling, typing, data models, async, logging, and pytest.
How do I install the conventions-python skill?
Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.
Does the conventions-python skill run scripts?
No, this skill is instructions only (SKILL.md) with no executable scripts.
Related skills
skill-creator
AnthropicCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
discernment-nudge
AnthropicAfter you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
data-consolidate
AnthropicJoins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
inspection-to-capa
AnthropicRuns the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…