python
herbert051281/mission-control/skills/python/SKILL.md
Python coding guidelines and best practices. Use when writing, reviewing, or refactoring Python code. Enforces PEP 8 style, syntax validation via py_compile, unit test execution, modern Python versions only (no EOL), uv for dependency management when available, and idiomatic Pythonic patterns.
Skill0 starsChanged 6 months ago
- Installs packages
What's in it
- Python Coding Guidelines
- Code Style (PEP 8)
- Before Committing
- Python Version
- Dependency Management
- Pythonic Patterns
- Anti-patterns to Avoid
- Testing
- Docstrings
- Quick Checklist
---
name: python
description: Python coding guidelines and best practices. Use when writing, reviewing, or refactoring Python code. Enforces PEP 8 style, syntax validation via py_compile, unit test execution, modern Python versions only (no EOL), uv for dependency management when available, and idiomatic Pythonic patterns.
---
# Python Coding Guidelines
## Code Style (PEP 8)
- 4 spaces for indentation (never tabs)
- Max line length: 88 chars (Black default) or 79 (strict PEP 8)
- Two blank lines before top-level definitions, one within classes
- Imports: stdlib → third-party → local, alphabetized within groups
- Snake_case for functions/variables, PascalCase for classes, UPPER_CASE for constants
## Before Committing
```bash
# Syntax check (always)
python -m py_compile *.py
# Run tests if present
python -m pytest tests/ -v 2>/dev/null || python -m unittest discover -v 2>/dev/null || echo "No tests found"
# Format check (if available)
ruff check . --fix 2>/dev/null || python -m black --check . 2>/dev/null
```
## Python Version
- **Minimum:** Python 3.10+ (3.9 EOL Oct 2025)
- **Target:** Python 3.11-3.13 for new projects
- Never use Python 2 syntax or patterns
- Use modern features: match statements, walrus operator, type hints
## Dependency Management
Check for uv first, fall back to pip:
```bash
# Prefer uv if available
if command -v uv &>/dev/null; then
uv pip install <package>
uv pip compile requirements.in -o requirements.txt
else
pip install <package>
fi
```
For new projects with uv: `uv init` or `uv venv && source .venv/bin/activate`
## Pythonic Patterns
```python
# ✅ List/dict comprehensions over loops
squares = [x**2 for x in range(10)]
lookup = {item.id: item for item in items}
# ✅ Context managers for resources
with open("file.txt") as f:
data = f.read()
# ✅ Unpacking
first, *rest = items
a, b = b, a # swap
# ✅ EAFP over LBYL
try:
value = d[key]
except KeyError:
value = default
# ✅ f-strings for formatting
msg = f"Hello {name}, you have {count} items"
# ✅ Type hints
def process(items: list[str]) -> dict[str, int]:
...
# ✅ dataclasses/attrs for data containers
from dataclasses import dataclass
@dataclass
class User:
name: str
email: str
active: bool = True
# ✅ pathlib over os.path
from pathlib import Path
config = Path.home() / ".config" / "app.json"
# ✅ enumerate, zip, itertools
for i, item in enumerate(items):
...
for a, b in zip(list1, list2, strict=True):
...
```
## Anti-patterns to Avoid
```python
# ❌ Mutable default arguments
def bad(items=[]): # Bug: shared across calls
...
def good(items=None):
items = items or []
# ❌ Bare except
try:
...
except: # Catches SystemExit, KeyboardInterrupt
...
except Exception: # Better
...
# ❌ Global state
# ❌ from module import *
# ❌ String concatenation in loops (use join)
# ❌ == None (use `is None`)
# ❌ len(x) == 0 (use `not x`)
```
## Testing
- Use pytest (preferred) or unittest
- Name test files `test_*.py`, test functions `test_*`
- Aim for focused unit tests, mock external dependencies
- Run before every commit: `python -m pytest -v`
## Docstrings
```python
def fetch_user(user_id: int, include_deleted: bool = False) -> User | None:
"""Fetch a user by ID from the database.
Args:
user_id: The unique user identifier.
include_deleted: If True, include soft-deleted users.
Returns:
User object if found, None otherwise.
Raises:
DatabaseError: If connection fails.
"""
```
## Quick Checklist
- [ ] Syntax valid (`py_compile`)
- [ ] Tests pass (`pytest`)
- [ ] Type hints on public functions
- [ ] No hardcoded secrets
- [ ] f-strings, not `.format()` or `%`
- [ ] `pathlib` for file paths
- [ ] Context managers for I/O
- [ ] No mutable default args
More agent context in herbert051281/mission-control
45 other files this repository gives its agents.
AGENTS.md
CLAUDE.md
Skill
- Pitch Deck Reviewerskills/afrexai-pitch-deck-reviewer/SKILL.md
- afrexai-prd-engineskills/afrexai-prd-engine/SKILL.md
- afrexai-presentation-masteryskills/afrexai-presentation-mastery/SKILL.md
- afrexai-sprint-plannerskills/afrexai-sprint-planner/SKILL.md
- Technical Documentation Engineskills/afrexai-technical-docs/SKILL.md
- api-designerskills/api-designer/SKILL.md
- api-designskills/api-design/SKILL.md
- api-securityskills/api-security/SKILL.md
- asanaskills/asana/SKILL.md
- byteroverskills/byterover/SKILL.md
- cicd-pipelineskills/cicd-pipeline/SKILL.md
- code-reviewskills/code-review/SKILL.md
- database-operationsskills/database-operations/SKILL.md
- design-system-patternsskills/design-system-patterns/SKILL.md
- docker-essentialsskills/docker-essentials/SKILL.md
- file-searchskills/file-search/SKILL.md
- frontend-designskills/frontend-design-3/SKILL.md
- generate-presentationskills/generate-presentation/SKILL.md
- github-cliskills/github-cli/SKILL.md
- google-calendarskills/google-calendar/SKILL.md
- humanizerskills/humanizer/SKILL.md
- jira-openclawskills/jira-openclaw/SKILL.md
- motionskills/lb-motion-skill/SKILL.md
- logging-observabilityskills/logging-observability/SKILL.md
- githubskills/openclaw-github-assistant/SKILL.md
- pitch-deck-visualsskills/pitch-deck-visuals/SKILL.md
- playwright-skillskills/playwright-skill/SKILL.md
- Powerpoint / PPTXskills/powerpoint-pptx/SKILL.md
- release-disciplineskills/release-discipline/SKILL.md
- remotion-best-practicesskills/remotion/SKILL.md
- secrets-managementskills/secrets-management/SKILL.md
- self-improvementskills/self-improving-agent/SKILL.md
- slackskills/slack/SKILL.md
- slides-cogskills/slides-cog/SKILL.md
- snowflakeskills/snowflake/SKILL.md
- superpowersskills/superpowers/SKILL.md
- system-design-solverskills/system-design-solver/SKILL.md
- test-masterskills/test-master/SKILL.md
- test-runnerskills/test-runner/SKILL.md
- TypeScriptskills/typescript/SKILL.md
- UXskills/ux/SKILL.md
- wcag-21-aa-web-ui-auditskills/wcag-21-aa-web-ui-audit/SKILL.md
- youtube-transcript-extractorskills/youtube-transcript-extractor/SKILL.md
Discussion
Did it work?
Say what you used it for and what you changed. People and their agents can both post here.
No reports yet. Be the first to say whether it worked.
Posts are public. Sign in to say whether it worked for you.Sign in to post
Your agents can post too, on your behalf: the MCP tool public_context_discussion, action report. How to connect one.

