Coding Standards & Style Guides
Fleet-wide Python standards extend PEP 8 with typing rules, project layout, error handling, and review expectations - enforced by Ruff 0.9+, pyright on changed paths, and templates new repos copy.
Search across all documentation pages
Fleet-wide Python standards extend PEP 8 with typing rules, project layout, error handling, and review expectations - enforced by Ruff 0.9+, pyright on changed paths, and templates new repos copy.
Quick-reference recipe card - copy-paste ready.
# pyproject.toml (fleet baseline)
[tool.ruff]
line-length = 100
target-version = "py314"
select = ["E", "F", "I", "UP", "B", "ASYNC", "S"]
[tool.pyright]
pythonVersion = "3.14"
typeCheckingMode = "standard"src/<package>/
api/ # HTTP only
domain/ # no FastAPI/Django imports
infra/ # DB, queues, external IOWhen to reach for this:
"""domain/orders.py - meets fleet standards."""
from __future__ import annotations
from dataclasses import dataclass
from decimal import Decimal
@dataclass(frozen=True)
class OrderTotal:
subtotal: Decimal
tax: Decimal
@property
def grand_total(self) -> Decimal:
return self.subtotal + self.tax
def compute_total(subtotal: Decimal, tax_rate: Decimal) -> OrderTotal:
tax = (subtotal * tax_rate).quantize(Decimal("0.01"))
return OrderTotal(subtotal=subtotal, tax=tax)# api/routes/orders.py - thin boundary
from fastapi import APIRouter
from pydantic import BaseModel
from domain.orders import compute_total
router = APIRouter()
class TotalRequest(BaseModel):
subtotal: float
tax_rate: float
@router.post("/total")
def total(body: TotalRequest) -> dict[str, float]:
result = compute_total(body.subtotal, body.tax_rate)
return {"grand_total": float(result.grand_total)}What this demonstrates:
Any requires comment justification.except.| Topic | Fleet rule |
|---|---|
| Async | No blocking I/O in async def without to_thread |
| SQL | Parameterized queries; ORM preferred |
| Logging | structlog JSON; no f-string in log message |
| Tests | pytest; fixtures over global state |
| Config | pydantic-settings; no raw os.environ scatter |
uv run ruff check .
uv run ruff format --check .
uv run pyright src/| Alternative | Use When | Don't Use When |
|---|---|---|
| Black only (no Ruff) | Legacy | New fleet (Ruff replaces both) |
| strict mypy entire repo | Greenfield tiny | Large legacy monolith |
| Google style guide verbatim | Need external reference | Fleet has custom layout |
| No standards | Imminent shutdown | Active multi-squad fleet |
PEP 8 baseline; fleet adds layout, typing, async, security rules.
This fleet uses 100; pick one org-wide.
Allow Django imports in apps/ and services/ layers per Django template ADR.
Notebooks not in prod path; promoted code must pass same lint in modules.
Yes; new modules typed; changed-path gate in CI.
Platform guild quarterly; RFC for controversial changes.
Recommended; CI is source of truth.
Exclude in ruff per-file-ignores; document paths.
Google or NumPy style one choice; enforced in new code optionally.
Stack versions: This page was written for Python 3.14.0 (stable 3.14, maintenance 3.13), FastAPI 0.115+, Django 5.2, Flask 3.1, Pydantic 2, PyTorch 2.6+, pandas 2.2+, Polars 1.x, ruff 0.9+, and uv 0.6+.
Reviewed by Chris St. John·Last updated Jul 16, 2026