python-best-practices
SolidProvides Python patterns for type-first development with dataclasses, discriminated unions, NewType, and Protocol. Must use when reading or writing Python files.
AI & Automation 11 stars
0 forks Updated today MIT
Install
Quality Score: 79/100
Stars 20%
Recency 20%
Frontmatter 20%
Documentation 15%
Issue Health 10%
License 10%
Description 5%
Skill Content
# Python Best Practices
## Type-First Development
Types define the contract before implementation. Follow this workflow:
1. **Define data models** - dataclasses, Pydantic models, or TypedDict first
2. **Define function signatures** - parameter and return type hints
3. **Implement to satisfy types** - let the type checker guide completeness
4. **Validate at boundaries** - runtime checks where data enters the system
### Make Illegal States Unrepresentable
Use Python's type system to prevent invalid states at type-check time.
**Dataclasses for structured data:**
```python
from dataclasses import dataclass
from datetime import datetime
@dataclass(frozen=True)
class User:
id: str
email: str
name: str
created_at: datetime
@dataclass(frozen=True)
class CreateUser:
email: str
name: str
# Frozen dataclasses are immutable - no accidental mutation
```
**Discriminated unions with Literal:**
```python
from dataclasses import dataclass
from typing import Literal
@dataclass
class Idle:
status: Literal["idle"] = "idle"
@dataclass
class Loading:
status: Literal["loading"] = "loading"
@dataclass
class Success:
status: Literal["success"] = "success"
data: str
@dataclass
class Failure:
status: Literal["error"] = "error"
error: Exception
RequestState = Idle | Loading | Success | Failure
def handle_state(state: RequestState) -> None:
match state:
case Idle():
pass
case Loading():
show_spinne...
Details
- Author
- NoesisVision
- Repository
- NoesisVision/nasde-toolkit
- Created
- 4 months ago
- Last Updated
- today
- Language
- Python
- License
- MIT
Similar Skills
Semantically similar based on skill content — not just same category
Data & Documents Solid
python-best-practices
Use when reading or writing Python files (.py, pyproject.toml, requirements.txt).
402 Updated today
aiskillstore Testing & QA Listed
python-best-practices
Python best practices — PEP 8, type hints, testing, error handling, code quality tools. Use when writing, reviewing, or discussing Python code.
1 Updated today
lklimek AI & Automation Listed
python-patterns
Pythonic idioms, PEP 8 standards, type hints, and best practices for building robust, efficient, and maintainable Python applications.
3 Updated today
uzysjung