uv.lock is uv's lock file. It captures the exact version of every dependency, including transitive ones, much like:
- Node.js
package-lock.json - Rust
Cargo.lock - Python Poetry
poetry.lock
Keeping uv.lock in version control guarantees that everyone installs the same dependency set.
- Running
uv sync --frozen - Building Docker images that call
uv sync --frozen - Editing source code without touching dependency metadata
-
uv lockoruv lock --upgradeuv lock # Resolve according to current constraints uv lock --upgrade # Re-resolve and upgrade to the newest compatible releases
Use these commands after modifying
pyproject.toml, when you want fresh dependency versions, or if the lock file was deleted or corrupted. -
uv adduv add requests # Adds the dependency and updates both files uv add --dev pytest # Adds a dev dependency
uv addeditspyproject.tomland refreshesuv.lockin one step. -
uv removeuv remove requests
This removes the dependency from
pyproject.tomland rewritesuv.lock. -
uv syncwithout--frozenuv sync
Normally this only installs what is already locked. However, if
pyproject.tomlanduv.lockdisagree or the lock file is missing, uv will regenerate and updateuv.lock. In CI and production builds you should preferuv sync --frozento prevent unintended updates.
# Recommended: let uv handle both files
uv add fastapi
git add pyproject.toml uv.lock
git commit -m "Add fastapi dependency"
# Manual alternative
# 1. Edit pyproject.toml
# 2. Regenerate the lock file
uv lock
git add pyproject.toml uv.lock
git commit -m "Add fastapi dependency"# 1. Edit the requirement in pyproject.toml,
# e.g. openai>=1.0.0,<2.0.0 -> openai>=1.5.0,<2.0.0
# 2. Re-resolve the lock file
uv lock
# 3. Commit both files
git add pyproject.toml uv.lock
git commit -m "Update openai to >=1.5.0"uv lock --upgrade
git diff uv.lock
git add uv.lock
git commit -m "Upgrade dependencies to latest compatible versions"git pull # Fetch latest code and lock file
uv sync --locked --inexact --extra test --extra offline # Same extras as your first install- Pass the extras you installed with. A bare
uv sync/uv sync --frozeninstalls no extras, and because it is exact by default it uninstalls the ones you had. --lockedinstalls exactly whatuv.lockspecifies and fails, rather than rewritinguv.lock, when the lock is out of date withpyproject.toml.--inexactkeeps packages that are not inuv.lock, such as the spaCy models installed bylightrag-download-cache --spacy-install.
RUN uv sync --frozen --no-dev --extra api--frozen guarantees reproducible builds because uv will refuse to deviate from the locked versions.
--extra api install API server
uv lock always resolves every optional dependency set declared in pyproject.toml (api, offline, test, …) into one uv.lock. It has no --extra option, and none is needed. The extras are chosen at install time instead, for example uv sync --frozen --extra api --extra offline, and that works without further resolution.
-
uv.lockis almost 1 MB. Does that matter? No. The file is read only during dependency resolution. -
Should we commit
uv.lock? Yes. Commit it so collaborators and CI jobs share the same dependency graph. -
Deleted the lock file by accident? Run
uv lockto regenerate it frompyproject.toml. -
Can
uv.lockandrequirements.txtcoexist? They can, but maintaining both is redundant. Prefer relying onuv.lockalone whenever possible. -
How do I inspect locked versions?
uv tree grep -A5 'name = "openai"' uv.lock
- Commit
uv.lockalongsidepyproject.toml. - Use
uv sync --frozenin CI, Docker, and other reproducible environments. - In a local checkout, update with
uv sync --locked --inexactplus your extras (Scenario 4). Drop--lockedonly when you deliberately want uv to reconcile the lock for you. - Run
uv lock --upgradeperiodically to pick up the latest compatible releases. - Regenerate the lock file immediately after changing dependency constraints.
- Running
uv syncwithout--frozenin CI or production pipelines. - Editing
uv.lockby hand—uv will overwrite manual edits. - Ignoring lock file diffs in code reviews—unexpected dependency changes can break builds.
| Command | Updates uv.lock |
Typical use |
|---|---|---|
uv lock |
✅ Yes | After editing constraints |
uv lock --upgrade |
✅ Yes | Upgrade to the newest compatible versions |
uv add <pkg> |
✅ Yes | Add a dependency |
uv remove <pkg> |
✅ Yes | Remove a dependency |
uv sync |
Local development; can regenerate the lock | |
uv sync --locked |
❌ No (fails if stale) | Local development after git pull |
uv sync --frozen |
❌ No | CI/CD, Docker, reproducible builds |
Remember: uv.lock only changes when you run a command that tells it to. Keep it in sync with your project and commit it whenever it changes.