This is outdated: See Pre-PEP: Add ability to install a package with reproducible dependencies for the new proposal
Proposal: Including pylock.toml in Wheels
I would like to propose a PEP that allows including pylock.toml or named lock files like pylock.<name>.toml (as defined in PEP 751) inside a wheelâs *.dist-info/pylock/ folder.
As explained in PEP 770, adding new files or folders to a wheel does not require a new metadata version.
Background
Although PEP 751 was accepted, there is currently no standardized way to distribute lock files, apart from placing them in a version control system (VCS) repository.
Most projects rely on CI/CD pipelines to validate their builds.
Including the lock file inside the final build artifact â often a wheel â that is later distributed makes sense.
These artifacts are typically the result of successful CI/CD runs and therefore signal that the package works as expected with the specified dependencies.
Distributing lock files via wheels eliminates the need for additional infrastructure just to support reproducible installations.
Use Cases
- Packages that are frequently installed as tools (e.g., via
pipxoruvx/uv tool) MAY include a lock file, which MAY be used by the package installer to create a virtual environment. - Companies maintaining software composed of multiple packages can use their existing infrastructure to install reproducible builds of their software stack â with the option to easily roll back to earlier versions, including dependencies.
- Library authors can distribute the set of dependencies their library was tested against. This helps less technical users to identify whether issues are dependency-related.
Non-Alternatives
- Lock files could be distributed alongside wheels, similar to how
.METADATAfiles might be handled (warehouse issue #8254):- This approach requires an additional HTTP request to check for existence.
- It becomes difficult or impossible to detect named lock files.
- It would require changes to wheel-hosting services (e.g., PyPIâs Warehouse or
devpi).
How Should Package Installers Handle Lock Files?
Assuming the installer supports lock files in wheels:
- When installing a wheel as a library:
- The installer SHALL NOT consider any lock files unless explicitly instructed by the user.
- When installing a wheel as a tool (i.e. using
pipxoruv toolfor installation):- The installer MAY use the lock file unless the user explicitly opts out.
Things to Consider
Python Version Compatibility
As discussed in the thread on Locking a PEP 723 single-file script, special attention must be given to Python version compatibility.
Wheels are usually built once for a specific Python interpreter version. When a newer Python version is used, users are often forced to build from sdist â a process that can be difficult or even impossible in some environments.
Therefore, I suggest loosening the strict requirement of requires-python to only allow a lower bound in the top-level metadata of pylock.toml. Instead, adopt the same semantics as for packages.requires-python, which uses standard version specifiers.
In most cases, existing tooling already supports upper bounds for Python versions, so minimal or no changes should be necessary.
The requires-python field could indicate the range of Python versions under which the package was tested during CI/CD.
Also note: since the lock file is distributed inside a wheel, the wheel itself can already be limited to a specific Python version.
Security
In the PEP 723 single-file script discussion, some raised valid concerns:
Locked old dependencies might contain known vulnerabilities (CVEs).
Unlike ad-hoc scripts, package builds typically occur in CI/CD environments with tools like Dependabot or Renovate keeping dependencies up to date.
Another concern is that lock files might reference untrusted or unexpected sources via arbitrary URLs. To mitigate this:
A package installer SHALL require user confirmation if any requirement in the lock file is to be installed from a source different (=mismatching host) from the one used for the original wheel.
This is another benefit of bundling the lock file inside the wheel: it enables verification that dependencies come from trusted sources (e.g., the same index).
How to Include Lock Files in Wheels
Including lock files in wheels would be the responsibility of the [build system].
The build backend could either copy an existing pylock.toml file or generate one dynamically during the build process. This would provide yet another mechanism for updating and locking dependencies as part of the build workflow.
Disclosure: I used an LLM to proofread/improve (NOT generate) this post as I am not a native English speaker and a bit dyslexic.