Skip to content

lock file

A lock file records the exact version of every package a project installs, including the dependencies of its dependencies, so that a later install reproduces the same environment. Most lock files also store a hash of each distribution file, which lets an installer confirm it’s getting the same bytes as before.

A lock file complements the loose requirements a project declares. A pyproject.toml might ask for requests>=2.32, and the dependency resolver turns that range into a concrete set of releases. The lock file captures that result, so teammates, CI jobs, and production servers install the identical set instead of resolving again and drifting as new releases appear. Here’s how that flow fits together:

pyproject.toml ranges go through the resolver into a lock file, which gives teammates, CI, and production identical environments.
Resolve Once, Install the Same Set Everywhere

Tools generate and update lock files, and projects commit them to version control alongside their code. For years, each tool had its own format, such as poetry.lock for Poetry and uv.lock for uv. PEP 751 standardized pylock.toml, a tool-agnostic format that an installer can use without resolving dependencies again.

Example

Say you’re deploying an app that depends only on requests, and every server should end up with exactly the same packages. You can ask pip to lock that requirement:

Language: Shell
$ python -m pip lock requests
WARNING: pip lock is currently an experimental command. ...

The command writes a pylock.toml file. Reading it back with the standard-library tomllib module shows what got pinned:

Language: Python
>>> import tomllib

>>> with open("pylock.toml", mode="rb") as lock_file:
...     lock = tomllib.load(lock_file)
...
>>> for package in lock["packages"]:
...     print(package["name"], package["version"])
...
certifi 2026.10.23
charset-normalizer 3.5.2
idna 3.20
requests 2.34.2
urllib3 2.8.0

>>> lock["packages"][-1]["wheels"][0]["hashes"]
{'sha256': '0cf3cae568d36aa9576b28dfb35f11328f1cb974ca7647d9475ebb86c75ac6e3'}

One direct requirement produced five locked entries, because requests pulls in four transitive dependencies. Each entry carries an exact version and a SHA-256 hash of its wheel, so an installer working from this file can verify every download against it.

A person triumphantly raises a key in front of a vault labeled pylock.toml, with a rack of colored keys, wooden crates marked with hashes, and a Python chip alongside.

Tutorial

Tool-Agnostic Python Lock Files With PEP 751 and pylock.toml

Learn how PEP 751 standardizes Python lock files with pylock.toml: generate one with pip or uv, install it with uv or pdm, and retire requirements.txt.

intermediate tools

For additional information on related topics, take a look at the following resources:

Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.


By Martin Breuss • Updated Nov. 21, 2026