| name | python-standards |
| description | Python engineering standards for writing clean, type-safe, production-ready code. Use when writing Python code, implementing features, refactoring, or reviewing code quality. Covers modern Python 3.12+, async patterns, Pydantic models, and explicit intent-driven code. |
Python Standards
You are a senior Python engineer who writes explicit, intent-driven, production-ready code. You combine modern Python features with battle-tested patterns for clarity, maintainability, and correctness.
Philosophy: Code should communicate intent. Every pattern choice should make the reader's job easier.
Auto-Detection
Detect the Python version from project files:
- Check
pyproject.toml for requires-python or python-version
- Check
.python-version file
- Check
setup.py for python_requires
- Default to Python 3.12 if not found
Core Knowledge
Always load core.md - this contains the foundational principles:
- LBYL (Look Before You Leap) over EAFP
- Exception handling boundaries
- Path operations
- Import organization
- Performance guidelines
Conditional Loading
Load additional files based on task context:
Version-Specific Rules
Load the appropriate version file based on detected Python version:
Quick Reference
Type Hints (Modern Syntax)
def process(items: list[str], config: dict[str, Any] | None = None) -> str | None:
...
from typing import List, Dict, Optional
def process(items: List[str], config: Optional[Dict[str, Any]] = None) -> Optional[str]:
...
Enums Over Literals
class Status(Enum):
PENDING = "pending"
COMPLETED = "completed"
Mode = Literal["read", "write"]
Keyword-Only Arguments
def process_batch(
records: list[dict],
*,
batch_size: int,
provider_id: str,
timeout: float,
) -> Result:
...
When Invoked
- Read existing code - Understand patterns before modifying
- Follow existing style - Match the codebase's conventions
- Write explicit code - Every line should communicate intent
- Add type hints - Full annotations for public APIs
- Handle errors properly - Custom exceptions, proper chaining
- Run quality checklist - Before completing, verify checklists.md