Python Conventions
Apply these conventions when Python work is the primary workstream.
Dispatch
| $ARGUMENTS |
Action |
| Active (auto-invoked when Python work is primary) |
Apply the operator contract below |
| Empty |
Display the convention summary and routing guidance |
check |
Verify tooling compliance only |
Reference File Index
| File |
Purpose |
references/tooling-contract.md |
Required command sequence for install, run, lint, type-check, and test flows |
references/redirection-boundaries.md |
When Python conventions should yield to shell, JS/TS, or domain-specific skills |
references/exceptions.md |
When to break conventions (legacy, corporate) |
references/library-preferences.md |
Guided library defaults for new Python work |
references/performance-tips.md |
Profiling tools, optimization patterns quick-reference |
references/testing-patterns.md |
Fixture scopes, markers, conftest skeleton |
Operator Contract
Active
- Apply this skill only when Python files, Python tooling, or
pyproject.toml are the primary surface of the task.
- Read
references/redirection-boundaries.md when Python appears alongside shell, JS/TS, or other dominant workstreams.
- Enforce the hard requirements in
references/tooling-contract.md for package management, command execution, linting, type checking, and tests.
- Check
references/exceptions.md before recommending any legacy or constrained-environment deviation.
- Read
references/library-preferences.md only when choosing libraries for new Python work.
Empty / Help
- Summarize the hard requirements:
uv, uv run, uv add, ty, ruff, pytest, and pyproject.toml.
- Show the difference between hard requirements and guided preferences.
- Point to the exact reference files for tooling, exceptions, libraries, testing, performance, and mixed-language routing.
check
- Verify tooling compliance only; do not widen into full implementation advice unless the user asks.
- Report whether the project uses
uv, uv run, ty, ruff, pytest, and pyproject.toml in the expected ways.
- Flag legacy or exception-path deviations and require the reason to match
references/exceptions.md.
- Reject recommendations that replace repo-required tooling with
mypy, pip install, or bare python.
Hard Requirements
- Package manager: use
uv for all Python package operations
- Dependencies: use
uv add, uv add --group dev, uv remove, and uv lock --upgrade-package <pkg> as appropriate
- Reproducible installs: use
uv sync --locked when validating an existing lockfile workflow
- Project config: keep Python project configuration in
pyproject.toml
- Type checking: use
uv run ty check, not mypy
- Linting: use
uv run ruff check and uv run ruff format
- Testing: use
uv run pytest
- Task running: use
uv run <command> for Python command execution
Virtual Environments
- Let
uv manage virtual environments automatically
- Never manually create or activate
.venv directories
- Use
uv run to execute within the project environment
Guided Preferences
Guided library preferences apply only when starting new Python work and no stronger local constraint already exists. Read references/library-preferences.md before recommending replacements for an established stack.
Project Structure
- Use
pyproject.toml for all project metadata and dependencies
- Place source code in a package directory matching the project name
- Use
uv workspace members for monorepo sub-packages
- Run the required lint, format, type-check, and test sequence from
references/tooling-contract.md before considering Python work complete
Performance Conventions
- Profile before optimizing.
- Use
references/performance-tips.md for quick Python profiling and optimization patterns.
- Route broad profiling, regression analysis, or performance investigation to
performance-profiler.
Testing Conventions
- Use pytest for Python tests and configure project test defaults in
pyproject.toml.
- Use
references/testing-patterns.md for fixtures, markers, tmp_path, monkeypatch, parametrization, and coverage policy.
- Route test strategy, suite design, fixture architecture, or cross-language test plans to
test-architect.
Validation Contract
Run from this skill directory before declaring changes complete:
python scripts/check.py
git diff --check
Completion criteria:
scripts/check.py exits 0.
git diff --check exits 0.
- No portable-CLI violations remain under this skill directory.
After changing skill definitions, public descriptions, reference files, or eval behavior, invoke docs-steward if available.
Critical Rules
- Reject Python setup advice that uses
pip install, uv pip install, or bare python when the task is not explicitly on an approved exception path.
- Require
uv add for runtime dependencies and uv add --group dev for development-only dependencies unless references/exceptions.md justifies a legacy or constrained-environment deviation.
- Require
uv run ty check for type checking; do not recommend mypy or bare ty check as the default path in this repo.
- Treat
uv run ruff check, uv run ruff format, uv run ty check, and uv run pytest as the default completion gate for Python changes unless an exception is documented.
- Do not edit
uv.lock by hand; use uv lock, uv sync, or dependency commands.
- Do not present guided library preferences as mandatory replacements for an already-established local stack.
- Read
references/exceptions.md before approving a legacy toolchain, alternate environment manager, or alternate library path.
- Redirect mixed-language or non-Python-primary work through
references/redirection-boundaries.md instead of force-fitting this skill onto the whole task.
Canonical terms (use these exactly):
uv -- the required package manager and task runner
ty -- the required type checker (not mypy)
uv run ty check -- the required type-check command
ruff -- the required linter and formatter
pyproject.toml -- the single source of project configuration
uv run -- prefix for all Python command execution
uv sync --locked -- default reproducible install check for lockfile-backed workflows
Scaling Strategy
- Incidental Python file in a broader non-Python task: enforce only the hard requirements that touch the Python-owned surface, then route mixed-workflow questions through
references/redirection-boundaries.md.
- Python-primary feature or refactor work: apply the full operator contract, including tooling, testing, and guided preferences where relevant.
- Repo-wide Python tooling or migration work: use
check, references/tooling-contract.md, and references/exceptions.md to separate hard violations from documented transition paths.
Progressive Disclosure
- Do not load every reference by default.
- Read
references/tooling-contract.md first for command-sequence questions.
- Read
references/redirection-boundaries.md when shell, JS/TS, CI, or framework-specific work is mixed into the request.
- Read
references/exceptions.md only when the task appears to require legacy, corporate, or constrained-environment exceptions.
- Read
references/library-preferences.md only when selecting libraries for new Python work.
- Read performance or testing references only when the active task actually touches those areas.
Scope Boundaries
IS for: Python tooling conventions, command selection, dependency-management rules, type/lint/test gates, and exception-aware repo guidance.
NOT for: JS/TS conventions, shell conventions, CI pipeline design, profiling investigations, test architecture, or framework/domain-specific implementation strategy.
1---2name: python-conventions3description: Enforce Python tooling conventions for uv, ty, Ruff, pytest, and pyproject.toml. Use when working on .py files or Python project config. NOT for JS/TS, shell scripts, CI design, profiling, or test architecture.4license: MIT5---67# Python Conventions89Apply these conventions when Python work is the primary workstream.1011## Dispatch1213| $ARGUMENTS | Action |14|------------|--------|15| Active (auto-invoked when Python work is primary) | Apply the operator contract below |16| Empty | Display the convention summary and routing guidance |17| `check` | Verify tooling compliance only |1819## Reference File Index2021| File | Purpose |22|------|---------|23| `references/tooling-contract.md` | Required command sequence for install, run, lint, type-check, and test flows |24| `references/redirection-boundaries.md` | When Python conventions should yield to shell, JS/TS, or domain-specific skills |25| `references/exceptions.md` | When to break conventions (legacy, corporate) |26| `references/library-preferences.md` | Guided library defaults for new Python work |27| `references/performance-tips.md` | Profiling tools, optimization patterns quick-reference |28| `references/testing-patterns.md` | Fixture scopes, markers, conftest skeleton |2930## Operator Contract3132### Active33341. Apply this skill only when Python files, Python tooling, or `pyproject.toml` are the primary surface of the task.352. Read `references/redirection-boundaries.md` when Python appears alongside shell, JS/TS, or other dominant workstreams.363. Enforce the hard requirements in `references/tooling-contract.md` for package management, command execution, linting, type checking, and tests.374. Check `references/exceptions.md` before recommending any legacy or constrained-environment deviation.385. Read `references/library-preferences.md` only when choosing libraries for new Python work.3940### Empty / Help41421. Summarize the hard requirements: `uv`, `uv run`, `uv add`, `ty`, `ruff`, `pytest`, and `pyproject.toml`.432. Show the difference between hard requirements and guided preferences.443. Point to the exact reference files for tooling, exceptions, libraries, testing, performance, and mixed-language routing.4546### `check`47481. Verify tooling compliance only; do not widen into full implementation advice unless the user asks.492. Report whether the project uses `uv`, `uv run`, `ty`, `ruff`, `pytest`, and `pyproject.toml` in the expected ways.503. Flag legacy or exception-path deviations and require the reason to match `references/exceptions.md`.514. Reject recommendations that replace repo-required tooling with `mypy`, `pip install`, or bare `python`.5253## Hard Requirements5455- **Package manager**: use `uv` for all Python package operations56- **Dependencies**: use `uv add`, `uv add --group dev`, `uv remove`, and `uv lock --upgrade-package <pkg>` as appropriate57- **Reproducible installs**: use `uv sync --locked` when validating an existing lockfile workflow58- **Project config**: keep Python project configuration in `pyproject.toml`59- **Type checking**: use `uv run ty check`, not `mypy`60- **Linting**: use `uv run ruff check` and `uv run ruff format`61- **Testing**: use `uv run pytest`62- **Task running**: use `uv run <command>` for Python command execution6364### Virtual Environments6566- Let `uv` manage virtual environments automatically67- Never manually create or activate `.venv` directories68- Use `uv run` to execute within the project environment6970## Guided Preferences7172Guided library preferences apply only when starting new Python work and no stronger local constraint already exists. Read `references/library-preferences.md` before recommending replacements for an established stack.7374## Project Structure7576- Use `pyproject.toml` for all project metadata and dependencies77- Place source code in a package directory matching the project name78- Use `uv` workspace members for monorepo sub-packages79- Run the required lint, format, type-check, and test sequence from `references/tooling-contract.md` before considering Python work complete8081## Performance Conventions82831. Profile before optimizing.842. Use `references/performance-tips.md` for quick Python profiling and optimization patterns.853. Route broad profiling, regression analysis, or performance investigation to `performance-profiler`.8687## Testing Conventions88891. Use pytest for Python tests and configure project test defaults in `pyproject.toml`.902. Use `references/testing-patterns.md` for fixtures, markers, `tmp_path`, `monkeypatch`, parametrization, and coverage policy.913. Route test strategy, suite design, fixture architecture, or cross-language test plans to `test-architect`.9293## Validation Contract9495Run from this skill directory before declaring changes complete:9697```bash98python scripts/check.py99git diff --check100```101102Completion criteria:1031041. `scripts/check.py` exits 0.1052. `git diff --check` exits 0.1063. No portable-CLI violations remain under this skill directory.107108After changing skill definitions, public descriptions, reference files, or eval behavior, invoke `docs-steward` if available.109110## Critical Rules1111121. Reject Python setup advice that uses `pip install`, `uv pip install`, or bare `python` when the task is not explicitly on an approved exception path.1132. Require `uv add` for runtime dependencies and `uv add --group dev` for development-only dependencies unless `references/exceptions.md` justifies a legacy or constrained-environment deviation.1143. Require `uv run ty check` for type checking; do not recommend `mypy` or bare `ty check` as the default path in this repo.1154. Treat `uv run ruff check`, `uv run ruff format`, `uv run ty check`, and `uv run pytest` as the default completion gate for Python changes unless an exception is documented.1165. Do not edit `uv.lock` by hand; use `uv lock`, `uv sync`, or dependency commands.1176. Do not present guided library preferences as mandatory replacements for an already-established local stack.1187. Read `references/exceptions.md` before approving a legacy toolchain, alternate environment manager, or alternate library path.1198. Redirect mixed-language or non-Python-primary work through `references/redirection-boundaries.md` instead of force-fitting this skill onto the whole task.120121**Canonical terms** (use these exactly):122- `uv` -- the required package manager and task runner123- `ty` -- the required type checker (not mypy)124- `uv run ty check` -- the required type-check command125- `ruff` -- the required linter and formatter126- `pyproject.toml` -- the single source of project configuration127- `uv run` -- prefix for all Python command execution128- `uv sync --locked` -- default reproducible install check for lockfile-backed workflows129130## Scaling Strategy131132- Incidental Python file in a broader non-Python task: enforce only the hard requirements that touch the Python-owned surface, then route mixed-workflow questions through `references/redirection-boundaries.md`.133- Python-primary feature or refactor work: apply the full operator contract, including tooling, testing, and guided preferences where relevant.134- Repo-wide Python tooling or migration work: use `check`, `references/tooling-contract.md`, and `references/exceptions.md` to separate hard violations from documented transition paths.135136## Progressive Disclosure137138- Do not load every reference by default.139- Read `references/tooling-contract.md` first for command-sequence questions.140- Read `references/redirection-boundaries.md` when shell, JS/TS, CI, or framework-specific work is mixed into the request.141- Read `references/exceptions.md` only when the task appears to require legacy, corporate, or constrained-environment exceptions.142- Read `references/library-preferences.md` only when selecting libraries for new Python work.143- Read performance or testing references only when the active task actually touches those areas.144145## Scope Boundaries146147**IS for:** Python tooling conventions, command selection, dependency-management rules, type/lint/test gates, and exception-aware repo guidance.148149**NOT for:** JS/TS conventions, shell conventions, CI pipeline design, profiling investigations, test architecture, or framework/domain-specific implementation strategy.