uv.lock, uv lock & uv sync
uv splits "decide the versions" from "make the environment match" into two commands, and uv run calls both for you:
uv lockresolvespyproject.tomlintouv.lock, a universal lockfile (all platforms, all Python versions inrequires-python).uv syncmakes.venvmatch the lockfile exactly: installs what's missing, upgrades and downgrades, and removes anything extra.
Reading uv.lock
uv.lock is TOML, meant to be committed and reviewed in diffs but never edited by hand:
uv init -q --no-package app && cd app
uv add -q "requests==2.31.0" && uv add -q --dev "pytest>=9"
head -3 uv.lock
echo "..."
sed -n '/^name = "app"/,/^$/p' uv.lock
sed -n '/^\[package.metadata\]/,/^$/p' uv.lock
echo "..."
sed -n '/^name = "requests"/,/^$/p' uv.lock | sed 's/sha256:[0-9a-f]*/sha256:…/'
echo "..."
sed -n '/^name = "pytest"/,/^dependencies/p' uv.lock
sed -n '/^name = "pytest"/,/^\[\[package/p' uv.lock | grep coloramaversion = 1
revision = 5
requires-python = ">=3.13"
...
name = "app"
version = "0.1.0"
source = { virtual = "." }
dependencies = [
{ name = "requests" },
]
[package.metadata]
requires-dist = [{ name = "requests", specifier = "==2.31.0" }]
...
name = "requests"
version = "2.31.0"
source = { registry = "http://127.0.0.1:8080/simple/" }
dependencies = [
{ name = "certifi" },
{ name = "charset-normalizer" },
{ name = "idna" },
{ name = "urllib3" },
]
wheels = [
{ url = "http://127.0.0.1:8080/packages/requests-2.31.0-py3-none-any.whl", hash = "sha256:…" },
]
...
name = "pytest"
version = "9.1.1"
source = { registry = "http://127.0.0.1:8080/simple/" }
dependencies = [
{ name = "colorama", marker = "sys_platform == 'win32'" },
What to notice:
requires-pythonat the top: the lock is valid for every Python the project supports.- The project itself is a package with
source = { virtual = "." }(a--no-packageapp; a packaged project sayseditable = "."), and its[package.metadata]records the requirements as written inpyproject.toml. That's how uv knows whether the lock is stale. - Every other package has its exact version, its source (the registry URL), and an sdist and/or wheels with hashes. A lock records all wheels of a version (every platform), not just the one for this machine.
- Dependencies carry markers: pytest needs
coloramaonlysys_platform == 'win32'. The lock contains colorama, butuv syncon Linux won't install it.
Locked, frozen and stale
uv init -q --no-package app && cd app
uv add -q "requests==2.31.0"
uv lock --check && echo "lock is up to date"
echo "--- someone loosens the requirement by hand"
sed -i 's/requests==2.31.0/requests>=2.31/' pyproject.toml
uv lock --check 2>&1; echo "exit code: $?"
uv sync --locked 2>&1; echo "exit code: $?"
uv sync --frozen 2>&1 | tail -1; uv run --frozen python -c 'import requests; print("frozen: still", requests.__version__)'
echo "--- re-lock: uv keeps the locked version if it still fits"
uv lock 2>&1 | grep -v '^Resolved'
grep -A1 '^name = "requests"' uv.lock
echo "--- upgrade on purpose"
uv lock --upgrade-package requests 2>&1 | grep -v '^Resolved'Resolved 6 packages in 1ms
lock is up to date
--- someone loosens the requirement by hand
Resolved 6 packages in 19ms
error: The lockfile at `uv.lock` needs to be updated, but `--check` was provided.
hint: To update the lockfile, run `uv lock`.
exit code: 1
Resolved 6 packages in 21ms
error: The lockfile at `uv.lock` needs to be updated, but `--locked` was provided.
hint: To update the lockfile, run `uv lock`.
exit code: 1
Checked 5 packages in 0.19ms
frozen: still 2.31.0
--- re-lock: uv keeps the locked version if it still fits
name = "requests"
version = "2.31.0"
--- upgrade on purpose
Updated requests v2.31.0 -> v2.34.2
| Flag | Lock stale? | Behaviour |
|---|---|---|
| (none) | re-lock it | the developer default: keep everything in sync automatically |
--locked |
error | CI: prove the committed lock matches pyproject.toml |
--frozen |
ignore | use the lock as it is, don't even check (fast Docker builds) |
Like poetry lock, a plain uv lock is minimal: loosening the requirement didn't move requests from 2.31.0, because 2.31.0 still satisfies it. Upgrades happen only when you ask: --upgrade-package requests for one, --upgrade (-U) for everything.
uv sync is exact
uv init -q --no-package app && cd app
uv add -q attrs && uv add -q --dev pytest
uv pip install -q rich 2>&1
echo "--- sync removes what the lock doesn't list"
uv sync 2>&1 | grep -E '^ [-+]'
echo "--- production: no dev group"
uv sync --no-dev 2>&1 | grep -E '^ [-+]'
echo "--- back to everything"
uv sync 2>&1 | grep -E '^ [-+]'--- sync removes what the lock doesn't list
- markdown-it-py==4.2.0
- mdurl==0.1.2
- rich==15.0.0
--- production: no dev group
- iniconfig==2.3.1
- packaging==26.3
- pluggy==1.7.0
- pygments==2.21.0
- pytest==9.1.1
--- back to everything
+ iniconfig==2.3.1
+ packaging==26.3
+ pluggy==1.7.0
+ pygments==2.21.0
+ pytest==9.1.1
rich, installed by hand, was removed along with its dependencies: the environment is a pure function of the lock. Selection flags mirror Poetry's: --no-dev, --only-dev, --group docs, --only-group test, --all-groups, --extra fancy, --all-extras. Add --inexact if you really want to keep extra packages.
Exporting for other tools
Platforms that only understand requirements.txt (some PaaS builders, pip install -r in an old Dockerfile) can still consume a uv lock:
uv init -q --no-package app && cd app
uv add -q "requests==2.31.0"
uv export --no-hashes --no-dev 2>&1Resolved 6 packages in 1ms
# This file was autogenerated by uv via the following command:
# uv export --no-hashes --no-dev
certifi==2026.10.23
# via requests
charset-normalizer==3.5.2
# via requests
idna==3.20
# via requests
requests==2.31.0
# via app
urllib3==2.8.0
# via requests
Drop --no-hashes and every line gets --hash=sha256:… options, so pip install --require-hashes -r requirements.txt verifies every download. uv export --format pylock.toml writes the new standard lock format, pylock.toml (PEP 751), which uv pip install -r pylock.toml can install; pip can already write one (pip lock, still experimental) and installer support is spreading.
Test yourself
In CI you want the job to fail if uv.lock doesn't match pyproject.toml. Which flag?
- --frozen
- --locked
- --no-dev
- --upgrade
You installed a package with uv pip install inside a uv project. What does the next uv sync do?
- Adds it to pyproject.toml
- Keeps it
- Removes it, because sync makes the environment match the lockfile exactly
- Fails
Why does a uv.lock made on Linux list wheels for Windows and macOS too?
- Mistake
- It's a universal lock: one file for every platform and supported Python version; markers decide what's installed
- uv downloads every wheel
- For caching