
Python Best Practices
Type-first Python idioms that make illegal states unrepresentable, plus exception chaining, logging, and type checker choices.
- skills.sh installs
- 1.8K
- GitHub stars
- 51
- last updated
- Jul 14, 2026
What it does
- Covers frozen dataclasses, discriminated unions with
Literal,NewTypedomain primitives, andProtocolstructural typing - Includes exception chaining with
from errto preserve tracebacks, and module-level logging with deferred%sformatting - Provides guidance on choosing among
ty,pyright, andmypy, withuvx ty checkusage and[tool.ty]configuration - Designed for Python files such as
.py,pyproject.toml, andrequirements.txtwhere language-specific idioms apply
Install
$ npx -y skills add 0xbigboss/claude-code --skill python-best-practices -yInstalls into .agents/skills for every agent it finds here, and .claude/skills for Claude Code.
Files
Python Best Practices
Follows type-first, functional, and error handling patterns from CLAUDE.md. This skill covers language-specific idioms only.
Make Illegal States Unrepresentable
Use Python's type system to prevent invalid states at type-check time.
Frozen dataclasses for immutable domain models:
from dataclasses import dataclass
from datetime import datetime
@dataclass(frozen=True)
class User:
id: str
email: str
name: str
created_at: datetime
# Frozen dataclasses are immutable — no accidental mutation
Discriminated unions with Literal:
from dataclasses import dataclass
from typing import Literal
@dataclass
class Success:
status: Literal["success"] = "success"
data: str
@dataclass
class Failure:
status: Literal["error"] = "error"
error: Exception
RequestState = Success | Failure
def handle_state(state: RequestState) -> None:
match state:
case Success(data=data):
render(data)
case Failure(error=err):
show_error(err)
NewType for domain primitives:
from typing import NewType
Details
- Repository
- github.com/0xbigboss/claude-code
- Category
- Python
More from 0xbigboss/claude-code
All 8Similar to Python Best Practices
More Python
fastapi-patternsaffaan-m/everything-claude-code1.8K installsfastapi patterns
python-patternssickn33/antigravity-awesome-skills1.1K installspython patterns
pythonmindrally/skills1.1K installsExpert in Python development with best practices across web, data science, and automation
python-uvmindrally/skills1K installsGuidelines for Python dependency management using uv, the fast Python package installer and resolver.
python-prosickn33/antigravity-awesome-skills747 installspython pro
fastapi-prosickn33/antigravity-awesome-skills676 installsfastapi pro