python-standards
FreeNo executable scriptsNot checkedPython code quality standards covering PEP 8, Black formatting, type hints, Google-style docstrings, and error handling. Use when writing or reviewing Python…
About this skill
Python Standards Skill
Python code quality standards for autonomous-dev project.
When This Activates
- Writing Python code
- Code formatting
- Type hints
- Docstrings
- Keywords: "python", "format", "type", "docstring"
Code Style (PEP 8 + Black)
| Setting | Value |
|---|---|
| Line length | 100 characters |
| Indentation | 4 spaces (no tabs) |
| Quotes | Double quotes |
| Imports | Sorted with isort |
black --line-length=100 src/ tests/
isort --profile=black --line-length=100 src/ tests/
Type Hints (Required)
Rule: All public functions must have type hints on parameters and return.
def process_file(
input_path: Path,
output_path: Optional[Path] = None,
*,
max_lines: int = 1000
) -> Dict[str, any]:
"""Type hints on all parameters and return."""
pass
Docstrings (Google Style)
Rule: All public functions/classes need docstrings with Args, Returns, Raises.
def process_data(data: List[Dict], *, batch_size: int = 32) -> ProcessResult:
"""Process data with validation.
Args:
data: Input data as list of dicts
batch_size: Items per batch (default: 32)
Returns:
ProcessResult with items and metrics
Raises:
ValueError: If data is empty
"""
Error Handling
Rule: Error messages must include context + expected + docs link.
# ✅ GOOD
raise FileNotFoundError(
f"Config file not found: {path}\n"
f"Expected: YAML with keys: model, data\n"
f"See: docs/guides/configuration.md"
)
# ❌ BAD
raise FileNotFoundError("File not found")
Exception Hierarchy
Define a project-level exception hierarchy for structured error handling:
class AppError(Exception):
"""Base exception for the application."""
pass
class ConfigError(AppError):
"""Configuration loading or validation error."""
pass
class ValidationError(AppError):
"""Input or data validation error."""
pass
class ExternalServiceError(AppError):
"""Error communicating with external service."""
pass
When to use custom vs built-in exceptions:
- Use built-in (
ValueError,TypeError,FileNotFoundError) for standard programming errors - Use custom exceptions when callers need to catch specific application-level failures
- Always inherit from a project base exception for catch-all handling
Error Message Format
Every error message should follow this three-part format:
- Context - What happened and where
- Expected - What was expected instead
- Docs link - Where to find more information
raise ValidationError(
f"Invalid config key '{key}' in {config_path}\n"
f"Expected one of: {', '.join(valid_keys)}\n"
f"See: docs/configuration.md#valid-keys"
)
Graceful Degradation
When a non-critical operation fails, log and continue rather than crashing:
try:
optional_result = enhance_with_cache(data)
except CacheError:
logging.warning("Cache unavailable, proceeding without cache")
optional_result = None
Naming Conventions
| Type | Convention | Example |
|---|---|---|
| Classes | PascalCase | ModelTrainer |
| Functions | snake_case | train_model() |
| Constants | UPPER_SNAKE | MAX_LENGTH |
| Private | _underscore | _helper() |
Best Practices
- Keyword-only args - Use
*for clarity - Pathlib - Use
Pathnot string paths - Context managers - Use
withfor resources - Dataclasses - For configuration objects
# Keyword-only args
def train(data: List, *, learning_rate: float = 1e-4):
pass
# Pathlib
config = Path("config.yaml").read_text()
Code Quality Commands
flake8 src/ --max-line-length=100 # Linting
mypy src/[project_name]/ # Type checking
pytest --cov=src --cov-fail-under=80 # Coverage
Key Takeaways
- Type hints - Required on all public functions
- Docstrings - Google style, with Args/Returns/Raises
- Black formatting - 100 char line length
- isort imports - Sorted and organized
- Helpful errors - Context + expected + docs link
- Pathlib - Use Path not string paths
- Keyword args - Use
*for clarity - Dataclasses - For configuration objects
Related Skills
- testing-guide - Testing patterns and TDD methodology
- error-handling-patterns - Error handling best practices
Hard Rules
FORBIDDEN:
- Public functions without type hints on parameters and return values
- Bare
except:orexcept Exception:without re-raising or specific handling - Mutable default arguments (
def f(items=[])) - Using
os.pathwhenpathlib.Pathis available
REQUIRED:
- All public APIs MUST have Google-style docstrings with Args/Returns/Raises
- All code MUST pass black formatting (100 char line length)
- Imports MUST be sorted with isort (profile=blac
Install python-standards 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
Allowed tools
Tools this skill is permitted to call.
ReadFAQ
What does the python-standards skill do?
Python code quality standards covering PEP 8, Black formatting, type hints, Google-style docstrings, and error handling. Use when writing or reviewing Python code. TRIGGER when: python, formatting, type hints, docstrings, PEP 8, black, isort. DO NOT TRIGGER when: non-Python files, markdown, config, shell scripts.
How do I install the python-standards 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 python-standards skill run scripts?
No, this skill is instructions only (SKILL.md) with no executable scripts.
Related skills
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
by Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
by Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
by Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
by Anthropic