Setup guide · Essentials
Python with uv
uv installed, Python 3.12 or newer managed by uv, and a project you can add packages to, run and test with pytest.
Every Python exercise and answer project uses uv. It installs Python, creates the virtual environment, resolves dependencies and runs your code, so you never touch pip or venv yourself. Answer projects ship a pyproject.toml, and uv run gives you the same environment every time.
Before you start
- Works on macOS, Linux and Windows. You don't need Python installed already, because uv downloads it.
- Allow about 100 MB for uv and each Python version it installs.
1. Install uv
macOS and Linux
curl -LsSf https://astral.sh/uv/install.sh | shWindows
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"Open a new terminal and check with uv --version. Homebrew works too (brew install uv), but then update it with brew upgrade uv instead of uv self update.
2. Install Python 3.12 or newer
Exercises assume Python 3.12+. Install a version, and optionally make it the default python on your machine:
uv python install 3.12
uv python install --default
uv python listYou can skip this step: uv downloads a suitable Python the first time a project needs one.
3. Create a project
uv init hello-world --python 3.12
cd hello-world--python 3.12 sets requires-python = ">=3.12" and writes .python-version. The current uv release creates this layout:
hello-world/
├── .gitignore
├── .python-version
├── README.md
├── pyproject.toml
└── src/
└── hello_world/
└── __init__.pyThe code lives in a package under src/, and pyproject.toml defines a hello-world command for it. Older uv versions create a flat main.py instead. Run uv self update to get the current behaviour.
4. Add packages and run code
uv add httpx
uv run hello-world
uv run python -c "import httpx; print(httpx.__version__)"uv addrecords the dependency inpyproject.toml, updatesuv.lockand installs it into.venv.uv runsyncs the environment with the lockfile, then runs the command inside it. You never need to activate.venv.uv remove httpxtakes a package out again.
To load secrets from a .env file for one run, pass it to uv run:
uv run --env-file .env python -m hello_worldKeep .env in .gitignore. The .gitignore that uv init writes covers .venv but not .env, so add it yourself:
echo ".env" >> .gitignore5. Test with pytest
Add pytest as a development dependency. It goes in [dependency-groups], so it isn't shipped with the package:
uv add --dev pytestAdd a function and a test:
def greet(name: str) -> str:
return f"Hello, {name}!"
def main() -> None:
print(greet("world"))from hello_world import greet
def test_greet():
assert greet("Ada") == "Hello, Ada!"Run the tests:
uv run pytestBecause the project is a package, uv installs it into .venv, and the test can import hello_world without any path tweaks.
Answer projects use this layout. To run one, cd into it and run uv run pytest. uv creates the environment from pyproject.toml and uv.lock on first use.
Check it works
From inside hello-world:
uv run pytest -qExpected output:
. [100%]
1 passed in 0.01sTroubleshooting
uv: command not found after installing. Open a new terminal. The installer adds ~/.local/bin (or %USERPROFILE%\.local\bin on Windows) to your PATH through your shell profile.
ModuleNotFoundError: No module named 'hello_world' in tests. You're on an older uv that created a flat, unpackaged project. Run uv self update and create the project again, or move the code into src/hello_world/ and add a [build-system] table as in the uv projects guide.
No interpreter found for Python >=3.12. Run uv python install 3.12. If uv is set to use only system Python, unset UV_PYTHON_PREFERENCE or UV_NO_MANAGED_PYTHON.
Windows blocks the install script. Use the exact command above. The -ExecutionPolicy ByPass part allows that one script to run without changing your system policy.
Going further
- Node.js, pnpm and TypeScript for the TypeScript exercises
- OpenRouter or a local model? before running any exercise that calls a model API
Sources
- Installing uvDocs · AstralThe standalone installers for macOS, Linux and Windows, and `uv self update`.
- Working on projectsDocs · AstralWhat `uv init` creates, and how `uv add`, `uv run` and the lockfile fit together.
- Installing PythonDocs · AstralInstalling and pinning Python versions with uv.
- Managing dependenciesDocs · AstralDevelopment dependencies such as pytest, which go in `[dependency-groups]`.
Exercises that use this
- Build a fleet compute and token cost modelInfrastructure for Agents · Where agents run
- Measure active CPU against wall timeInfrastructure for Agents · Where agents run
- Build and attack a local code runnerInfrastructure for Agents · Sandboxes for agent code
- Egress allowlists and credential brokering in a microVMInfrastructure for Agents · Sandboxes for agent code
- Build a toy durable execution engineInfrastructure for Agents · Durable execution engines
- A completion workflow on Temporal with signals and a deadlineInfrastructure for Agents · Durable execution engines
- Simulate leases, redelivery and fairnessInfrastructure for Agents · Queues, schedules and background jobs
- An idempotent consumer against a local queueInfrastructure for Agents · Queues, schedules and background jobs
- Build and test a session store adapterInfrastructure for Agents · State, sessions and checkpoints
- Find every copy: an erasure dry runInfrastructure for Agents · State, sessions and checkpoints
- Row-level security that fails closedInfrastructure for Agents · Secrets, identity and tenant isolation
- A per-firm credential proxyInfrastructure for Agents · Secrets, identity and tenant isolation
- Simulate fallbacks, correlation and budgetsInfrastructure for Agents · AI gateways
- A self-hosted gateway with per-firm keysInfrastructure for Agents · AI gateways
- Build a paired eval gate for CIInfrastructure for Agents · Environments and delivery for agents
- Roll out a prompt by matter, with shadow runsInfrastructure for Agents · Environments and delivery for agents
- Inventory the memory of an agent you useAgent Memory · Memory types for agents
- Measure fact drift across repeated compactionAgent Memory · The context window as working memory
- Re-inject matter state after compaction in Claude CodeAgent Memory · The context window as working memory
- Build and attack a per-matter memory-tool handlerAgent Memory · Files, skills and memory tools
- Build a miniature knowledge-update benchmarkAgent Memory · Memory frameworks and benchmarks
- Build a scoped memory store with provenance-based deletionAgent Memory · Scoping, retention and erasure
- Build the write-update-forget pipeline for a 12-week matterAgent Memory · Write, update and forget
- Design a reviewed consolidation jobAgent Memory · Write, update and forget
- Build shared matter state and attack itAgent Memory · Shared state and memory poisoning
- Red-team persistence across sessionsAgent Memory · Shared state and memory poisoning
- Run a memory ablation on synthetic mattersAgent Memory · Evaluating memory
- Model memory cost for your session patternAgent Memory · Evaluating memory
- Build and tune a page triageDocument Ingestion Pipelines · What a real case file contains
- Unpack and deduplicate a matter's emailDocument Ingestion Pipelines · What a real case file contains
- Run a four-way parser bake-offDocument Ingestion Pipelines · Parsing: text layers to vision models
- Self-host an open parsing modelDocument Ingestion Pipelines · Parsing: text layers to vision models
- Verify tables and plan references in codeDocument Ingestion Pipelines · Tables, plans and handwriting
- Measure two-reader agreement on handwritingDocument Ingestion Pipelines · Tables, plans and handwriting
- Extract lease terms with page-verified evidenceDocument Ingestion Pipelines · Structured extraction at scale
- Compare long-document strategiesDocument Ingestion Pipelines · Structured extraction at scale
- Build a crash-safe ingest workflowDocument Ingestion Pipelines · Durable ingest pipelines
- Simulate retry granularityDocument Ingestion Pipelines · Durable ingest pipelines
- Build incremental re-ingestion with early cutoffDocument Ingestion Pipelines · Re-ingestion, versioning and backfills
- Build and measure a hybrid PII detectorDocument Ingestion Pipelines · PII detection and redaction
- Redact a PDF and prove itDocument Ingestion Pipelines · PII detection and redaction
- Build an ingest eval harnessDocument Ingestion Pipelines · Ingest evals and the hand-off
- Specify and test the retrieval hand-offDocument Ingestion Pipelines · Ingest evals and the hand-off
- Implement and stress-test a byte-level BPE tokenizerLLMs for Engineers · Tokens and embeddings
- Probe embedding geometryLLMs for Engineers · Tokens and embeddings
- Implement attention and verify it against PyTorchLLMs for Engineers · Attention, step by step
- Find an induction head in GPT-2LLMs for Engineers · Attention, step by step
- Build a block and verify parameter counts against real modelsLLMs for Engineers · The transformer block
- Prove RoPE is relative, numericallyLLMs for Engineers · The transformer block
- Fit your own scaling law on a laptopLLMs for Engineers · Pretraining and scaling laws
- Base model versus assistant on conveyancing promptsLLMs for Engineers · Pretraining and scaling laws
- Build a verifiable reward and simulate GRPO advantagesLLMs for Engineers · Post-training an assistant
- Measure and catch hallucinations in lease extractionLLMs for Engineers · Sampling and hallucination
- Simulate decoding strategiesLLMs for Engineers · Sampling and hallucination
- Watch prompt caching hit and missLLMs for Engineers · Context windows, KV cache and caching
- Implement a KV cache and measure the speed-upLLMs for Engineers · Context windows, KV cache and caching
- Run an effort sweep on conveyancing calculationsLLMs for Engineers · Reasoning models and extended thinking
- Self-consistency versus more thinkingLLMs for Engineers · Reasoning models and extended thinking
- Run a model bake-off on title-register extractionLLMs for Engineers · Choosing and comparing models
- Add an open-weight model to the bake-offLLMs for Engineers · Choosing and comparing models
- Build a per-matter cost model from usage logsLLM Cost Engineering · Token economics of an agent fleet
- Calibrate the model against real token countsLLM Cost Engineering · Token economics of an agent fleet
- Simulate cache hits and costs for a matterLLM Cost Engineering · Prompt caching as system design
- Measure warm-then-fan-out on your subscriptionLLM Cost Engineering · Prompt caching as system design
- Simulate context policies with and without cachingLLM Cost Engineering · Trimming and compacting context
- Test what compaction forgetsLLM Cost Engineering · Trimming and compacting context
- Build a resumable batch extraction jobLLM Cost Engineering · Batch, flex and fast tiers
- Measure a cost-quality curve and test a cascadeLLM Cost Engineering · Cost-quality curves, routing and cascades
- Does a learned router beat self-confidence?LLM Cost Engineering · Cost-quality curves, routing and cascades
- Distil a clause tagger and measure the gapLLM Cost Engineering · Distilling into small models
- Build a serving cost calculatorLLM Cost Engineering · Self-hosting break-even
- Benchmark an engine yourselfLLM Cost Engineering · Self-hosting break-even
- Build a cost ledger with budgets and alertsLLM Cost Engineering · Attribution, budgets and alerts
- Rewrite the searches summariser and measure itPrompt and Context Optimisation · Prompting current Claude models
- Effort versus prose instructionsPrompt and Context Optimisation · Prompting current Claude models
- Run an example ablation on the enquiries drafterPrompt and Context Optimisation · Choosing few-shot examples
- Three disciplined iterations on the enquiries drafterPrompt and Context Optimisation · Eval-driven prompt iteration
- Measure prompt fragilityPrompt and Context Optimisation · Eval-driven prompt iteration
- Build a small reflective optimiser on claude -pPrompt and Context Optimisation · Automatic prompt optimisation
- DSPy: MIPROv2 versus GEPAPrompt and Context Optimisation · Automatic prompt optimisation
- Build a skill-trigger eval in Claude CodePrompt and Context Optimisation · Optimising tools, instructions and skills
- Transcript-driven tool improvementPrompt and Context Optimisation · Optimising tools, instructions and skills
- Build and break an experiment analysisPrompt and Context Optimisation · Prompt registries and online tests
- Wire a registry with labels and trace linkagePrompt and Context Optimisation · Prompt registries and online tests
- Migrate the summariser behind a regression suitePrompt and Context Optimisation · Model migration and regression suites
- Gate prompt changes in CIPrompt and Context Optimisation · Model migration and regression suites
- Measure truncation and quantisation on legal textRetrieval and Knowledge Systems · Embeddings in practice
- Add a commercial embedder (stretch)Retrieval and Knowledge Systems · Embeddings in practice
- Structure-aware and contextual chunking, measuredRetrieval and Knowledge Systems · Chunking structured documents
- Try late chunking (stretch)Retrieval and Knowledge Systems · Chunking structured documents
- Tune an ANN index against a recall targetRetrieval and Knowledge Systems · Vector indexes and databases
- Red-team tenant isolation (stretch)Retrieval and Knowledge Systems · Vector indexes and databases
- Build and run a labelled query setRetrieval and Knowledge Systems · Measuring retrieval
- Verify citations end to end (stretch)Retrieval and Knowledge Systems · Measuring retrieval
- Build and measure a hybrid pipelineRetrieval and Knowledge Systems · Hybrid search and reranking
- Compare single-shot, grep-only and full agentic retrievalRetrieval and Knowledge Systems · Agentic retrieval
- Build scoped matter tools with the Agent SDK (stretch)Retrieval and Knowledge Systems · Agentic retrieval
- Build a graph from verified records, and compare with an LLM-extracted oneRetrieval and Knowledge Systems · Knowledge graphs and GraphRAG
- Trial GraphRAG on a global question (stretch)Retrieval and Knowledge Systems · Knowledge graphs and GraphRAG
- Compare long context, RAG and a router on your questionsRetrieval and Knowledge Systems · Long context versus RAG
- Simulate the three buckets and the cache cliffScaling AI Systems · Rate limits and quotas
- Log rate-limit headers and cache usageScaling AI Systems · Rate limits and quotas
- Build and test a token-aware, fair limiterScaling AI Systems · Concurrency and flow control
- Adaptive concurrency under a moving limitScaling AI Systems · Concurrency and flow control
- Simulate a retry storm and stop itScaling AI Systems · Retries, backoff and overload
- A circuit breaker with deadlines in front of a flaky mockScaling AI Systems · Retries, backoff and overload
- Simulate the month-end rushScaling AI Systems · Backpressure, load shedding and batching
- A deferrable-work batch pipeline against a mockScaling AI Systems · Backpressure, load shedding and batching
- Instrument and speed up a real agent turnScaling AI Systems · Latency engineering for agents
- When is speculation worth it?Scaling AI Systems · Latency engineering for agents
- Measure a semantic cache as a classifierScaling AI Systems · Response caching and failover
- Simulate failover with a cold cacheScaling AI Systems · Response caching and failover
- Load test a fleet slice against a mockScaling AI Systems · Load testing and capacity planning
- Write a capacity plan for doubling the fleetScaling AI Systems · Load testing and capacity planning
- Measure what parsing prose costsSystem One Models with Jev · What a System One model is
- Build a calibration toolkit and test it on two modelsSystem One Models with Jev · Calibrated probabilities
- Repair an overconfident model with temperature scalingSystem One Models with Jev · Calibrated probabilities
- Build and test your first requestSystem One Models with Jev · Your first Jev request
- Log the model that answered, and catch an alias moveSystem One Models with Jev · Your first Jev request
- Build an enquiry question set and an option-order checkSystem One Models with Jev · Choice, Score and Noul
- Route through a taxonomy with chained Choices and beam searchSystem One Models with Jev · Choice, Score and Noul
- Build a state builder and a reads-then-computes pipelineSystem One Models with Jev · State and decomposition
- Red-team your questions with injected instructionsSystem One Models with Jev · State and decomposition
- Build a cost-derived confidence routerSystem One Models with Jev · Routing on confidence
- Conformal prediction sets for triageSystem One Models with Jev · Routing on confidence
- Build a draft-then-gate reply pipelineSystem One Models with Jev · Jev alongside LLMs
- Sweep a cascade's gate and find the frontierSystem One Models with Jev · Jev alongside LLMs
- Build an eval harness for System One answersSystem One Models with Jev · Evaluating Jev on your data
- Consistency and version regression checksSystem One Models with Jev · Evaluating Jev on your data