← Back to Payloads
Tutorial2026-06-12

uv for LLM Scripts: The 5-Minute Setup That Actually Beats Your Old Workflow

If you are writing LLM scripts in Python in 2026 and you are not on uv, you are paying a tax in seconds that compounds into hours per week. uv is a 10-100x faster drop-in for pip that ships its own venv, lockfile, and Python version manager. Five minutes from zero to a reproducible LLM project.
Quick Access
Install command
$ mrt install tutorial
Browse related skills
uv for LLM Scripts: The 5-Minute Setup That Actually Beats Your Old Workflow

uv for LLM Scripts: The 5-Minute Setup That Actually Beats Your Old Workflow

I used to keep a requirements.txt next to every LLM experiment. I used to spin up venvs by reflex. I used to wait 40 seconds for pip install to finish before I could test a one-line prompt change. Then I tried uv for a weekend hack in early 2025, and I have not looked back. If you are writing LLM scripts in 2026 and you are not on uv, you are paying a tax in seconds that compounds into hours per week.

The Setup

bash curl -LsSf https://astral.sh/uv/install.sh | sh

That drops uv into ~/.local/bin and you also get uvx for running CLI tools in isolated environments, uv python install for pinning Python versions, and uv pip as a 10-100x faster drop-in for pip. Now make a project.

bash mkdir rag-experiment && cd rag-experiment uv init --python 3.12 uv add openai anthropic tenacity httpx

uv init creates a pyproject.toml and a .python-version file. uv add writes pinned versions to a uv.lock, creates a project-local virtualenv in .venv/, and installs everything in under a second. Yes, a second, for six packages. Time a cold pip install for the same six packages and tell me it is not a tax.

The LLM Script

Drop this in the project root:

```python import os from openai import OpenAI from tenacity import retry, stop_after_attempt, wait_exponential

client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])

@retry(stop=stop_after_attempt(3), wait=wait_exponential(min=1, max=10)) def classify(text: str) -> str: resp = client.chat.completions.create( model="gpt-4.1", messages=[ {"role": "system", "content": "Classify as positive, negative, or neutral."}, {"role": "user", "content": text}, ], temperature=0, ) return resp.choices[0].message.content.strip() ```

Run it:

bash uv run classify.py

uv run resolves the lockfile, ensures the venv is in sync, and executes the script in the correct environment. No source .venv/bin/activate. No "wait, which Python is in my PATH." The lockfile is what makes collaboration safe: uv sync on a teammate's machine produces byte-identical installs.

The Gotchas

  • **uv does not read your old requirements.txt automatically.** Run uv add -r requirements.txt to migrate, commit the new uv.lock, and delete the old file. I left one lying around for two months as a "just in case" and it bit me when a teammate installed from it and got a different httpx version.
  • **The .venv is project-local by default.** This is the right call, but your IDE needs to be told where the interpreter lives. In VS Code, run Python: Select Interpreter and pick .venv/bin/python.
  • **uv pip install is fast but skips lockfile resolution.** If you need reproducibility, use uv add or uv sync instead. I have muscle memory for uv pip install from a thousand years of Python work, and I have to consciously override it every time.
  • System Python on macOS will fight you. If python3 resolves to /usr/bin/python3 and you call uv from a venv that inherited it, you will get weird interpreter errors. Pin with uv python pin 3.12 and stick to uv run.

The Take

uv is the workflow change I have recommended most often this year. Five minutes from zero to a locked, reproducible LLM project with the packages you actually use. The speed compounds: every script iteration drops from 40 seconds of pip overhead to 0.3 seconds of uv cache hits, and the difference between a 30-second loop and a 1-second loop is whether you actually run the experiment or talk yourself out of it. Try it on the next throwaway script. Then try it on the next real one.

Mr. Technology

Related Dispatches