Python Standards¶
Consistency matters more than personal preference. The goal is a codebase that anyone on the team can read and modify safely.
Principles¶
- Prefer explicit over implicit
- Favour readability over brevity
- Use type hints — they document intent and catch errors early
- Keep functions small and focused on one thing
Suggested Tooling¶
These are recommendations, not mandates. Choose what fits the team and enforce it consistently.
| Tool | Purpose |
|---|---|
ruff |
Fast linting and formatting (can replace black + isort + flake8) |
black |
Opinionated code formatter |
isort |
Import sorting |
mypy |
Static type checking |
flake8 |
Style and error checking |
Pick one formatting approach and stick to it. Mixing tools that do overlapping things creates friction.
Style Guidance¶
- Use descriptive names —
get_active_customers()overget_data() - Avoid magic numbers — assign them to named constants
- Document the why when behaviour is non-obvious, not the what
- Avoid deeply nested logic — extract to functions
Type Hints¶
def calculate_revenue(orders: list[Order], currency: str = "GBP") -> Decimal:
...
Type hints are especially valuable at function boundaries and in shared libraries.