Safeguard
Developer Tools•

Can pip create a lock file? What pip lock does and where it stops

Pip now has an experimental lock command that writes pylock.toml. Learn what it locks, why it is tied to one platform, and how to use it with care.

Safeguard Security Team
4 min read

Yes, in current pip releases. The pip lock command resolves requirements and writes a pylock.toml file. Its documentation marks it experimental and says the file is only guaranteed valid for the current Python version and platform. Use it as a reviewable record, and do not assume one file works on every machine.

What the command does

The pip reference describes it as locking packages and their dependencies from several kinds of input: package indexes using requirement specifiers, VCS project URLs, local project directories, and local or remote source archives. It also accepts requirements files, in the usual format or in pylock.toml form, with the note that pylock.toml support is experimental.

python -m pip lock -r requirements.txt -o pylock.toml

The default output name is pylock.toml, and a dash sends it to standard output. Other options include constraint files, a build-constraint option for build dependencies, and reading dependencies from a script that uses inline metadata.

Why it differs from pip freeze

A freeze lists what is installed in one environment. A lock is produced by resolving, so it can be created without installing and reviewed before anything runs. If you want the file format explained, see what pylock.toml is.

Questionpip freezepip lock
Needs an installed environmentYesNo
Shows transitive dependenciesYes, as installedYes, as resolved
Formatrequirements.txt linespylock.toml
StabilityLong establishedMarked experimental

For a deeper look at what a freeze misses, see does pip freeze pin transitive dependencies.

The platform caveat

The documentation says the generated lock file is only guaranteed to be valid for the current Python version and platform. In practice that means a lock made on a Linux build host may not describe what a macOS developer or a different Python version would resolve.

Options for teams with mixed environments:

  1. Generate the lock in the same container image you deploy, and treat that as the source of truth for production.
  2. Generate one lock per supported platform and Python version.
  3. Keep your source requirements file alongside, and regenerate when you change targets.

What a lock does not decide

A lock records which versions were resolved. It does not decide whether those versions are safe. Review remains your job: look at new packages, new maintainers and sudden version jumps in the diff of the lock file.

It also sits upstream of install time controls. Hash-checking mode and wheel only installs are still how you constrain what lands on a machine. See how pip hash checking works.

Using it with care

  • Commit the lock file and review changes like code.
  • Pin the pip version in CI, since the feature is experimental and behaviour may change.
  • Do not delete your source requirements. A lock is output, not intent.
  • Compare the lock with what a scanner reports so you notice drift.

Safeguard's SBOM generation and dependency scanning record the resolved package set of a project, which pairs well with a committed lock file for comparison. A free scan is available at gold.safeguard.sh/scan.

Try it yourself

Click through it at your own pace, or open it full screen. See how new advisories are matched against a package set that has not changed.

Quick check

Is pip lock stable enough for production pipelines?

The documentation labels it experimental. Pin your pip version and be ready to adjust.

Can one pylock.toml serve Windows, macOS and Linux?

Not guaranteed. The docs say the file is valid for the current Python version and platform.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.