Home / Docs / Reproducible Python
Developer toolchain
Reproducible Python: uv, Lockfiles, Pydantic & CI
"Works on my laptop" fails code review, capstone grading, and production deploys. A clean Python repo starts with a pinned lockfile, typed data contracts, and one-command tests.
1. Fast, lockfile-pinned environments with uv
Avoid global pip install and unpinned requirements.txt files. With uv, both Python version and transitive dependency hashes live in pyproject.toml and uv.lock:
uv init my-project
cd my-project
uv add pydantic rdflib
uv add --dev pytest ruff
uv run pytest
Commit pyproject.toml and uv.lock to Git; ignore .venv/ and .env in .gitignore.
2. Enforce schemas at boundaries with Pydantic
Never parse brittle free-form LLM prose or untrusted JSON dictionaries with nested dict.get() chains. Validate inputs and outputs into explicit models:
from pydantic import BaseModel, Field
class CitationVerdict(BaseModel):
claim: str = Field(min_length=5)
source_id: str
supported: bool
evidence_quote: str
3. Git hygiene & minimum CI checklist
- Never commit secrets: Keep API tokens in gitignored
.envfiles and load via environment variables. - Small, verifiable commits: One logical change per commit with a message explaining why.
- Automated CI gate: Run
uv run ruff check .anduv run pyteston every push via GitHub Actions so broken builds never land onmain.