Agent skill
best-practices-python
Repo-specific Python best practices for agentic coding: Loguru + Typer + uv + pyproject.toml, httpx over requests, functions-first, module docstrings, max 800 LOC per file, and non-mocked sanity tests.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/best-practices-python
Metadata
Additional technical details for this skill
- defaults
-
{ "cli": "typer", "http": "httpx", "style": { "module_docstring": "required", "max_lines_per_file": 800, "functions_over_classes": true }, "logging": "loguru", "testing": { "include_sanity_tests": true }, "packaging": "uv + pyproject.toml" } - language
- python
- python versions
-
[ "3.11+", "3.12+" ]
SKILL.md
Python Best Practices (Project Skill)
This skill is a curated set of atomic rules for writing and refactoring Python in this repo.
Project Defaults (apply unless explicitly overridden)
- Logging: Loguru (
from loguru import logger) - CLI: Typer (thin CLI; logic in functions)
- HTTP: httpx (not requests)
- Packaging: uv + pyproject.toml
- Structure: functions over classes unless state is required
- Files: no Python file over 800 lines
- Docs: every module begins with a clear module docstring describing purpose, inputs, outputs, and failure modes
- Tests: include non-mocked sanity tests in addition to unit tests
When to Apply
Use this skill whenever you:
- create or refactor Python modules, CLIs, services, or pipelines
- add network calls, subprocess calls, or IO
- change packaging/tooling (uv, pyproject)
- add tests or fix bugs/flakiness
Categories (priority order)
- Correctness (CRITICAL/HIGH):
correctness- - Security (CRITICAL/HIGH):
security- - Conventions (HIGH):
conventions- - Testing & Sanity (HIGH/MEDIUM):
testing- - Async & Concurrency (HIGH/MEDIUM):
async- - Performance (MEDIUM):
perf- - Packaging (MEDIUM):
packaging- - Logging & Observability (MEDIUM):
logging- - Style & Maintainability (MEDIUM/LOW):
style-
Quick Reference (house rules)
style-max-800-linesstyle-module-docstringconventions-loguruconventions-typer-cliconventions-httpxconventions-uv-pyprojectconventions-functions-over-classesconventions-pyproject-deps-completetesting-non-mocked-sanity
pyproject.toml Dependency Completeness (NON-NEGOTIABLE)
Every import in a skill's .py files MUST have a corresponding entry in pyproject.toml [project.dependencies].
This is a hard gate. Missing dependencies cause ModuleNotFoundError at runtime after uv sync in a clean venv — a silent regression that only surfaces when the skill is invoked by another agent or in CI.
Rule: conventions-pyproject-deps-complete
When creating or modifying a Python skill with a pyproject.toml:
- Scan all
.pyfiles in the skill forimportandfrom X importstatements - Cross-reference each top-level import against
[project.dependencies] - Add any missing third-party packages to dependencies
- Run
uv syncafter adding to verify resolution
Common offenders (imports that look stdlib but aren't)
| Import | Package needed in pyproject.toml |
|---|---|
from loguru import logger |
loguru>=0.7.0 |
import typer |
typer>=0.9.0 |
import httpx |
httpx>=0.24.0 |
from rich import ... |
rich>=13.0.0 |
import pydantic |
pydantic>=2.0 |
from dotenv import ... |
python-dotenv>=1.0.0 |
import pytz |
pytz |
import tenacity |
tenacity>=8.0 |
Verification pattern
# After any pyproject.toml change:
cd /path/to/skill && uv sync && uv run python -c "import <every_module>"
Why this matters
The ops-chutes skill broke (Feb 2026) because loguru was imported by 3 files but
missing from pyproject.toml. After uv sync recreated the venv, loguru vanished
and every downstream skill that called ops-chutes got ModuleNotFoundError. This was
a silent regression — the skill worked in the shared system venv but failed in isolation.
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?