Skip to main content

Pin all dependencies in pyproject.toml to their currently installed versions

Project description

pin-versions

A CLI tool and pre-commit hook that pins all unpinned dependencies in pyproject.toml to their currently installed versions.

Why pin versions?

Unpinned dependencies (e.g. requests instead of requests==2.31.0) mean your project silently picks up whatever version happens to be newest at install time. This causes real problems:

  • Broken builds -- a new release of a dependency can introduce breaking changes or bugs that suddenly fail your CI or production deploys, even though your code hasn't changed.
  • "Works on my machine" -- different team members install at different times and get different versions, leading to bugs that are impossible to reproduce.
  • Non-reproducible deployments -- deploying the same commit twice can produce different behavior if a dependency was updated between deploys.
  • Silent security risk -- without knowing exactly what you're running, auditing your dependency tree for vulnerabilities is guesswork.

Pinning gives you control: upgrades happen when you choose, not when a package author publishes.

Why some dependencies are left unpinned

pin-versions resolves versions by checking what is currently installed in your virtual environment. A dependency will remain unpinned if:

  • It isn't installed -- the package appears in pyproject.toml but is not present in the target virtual environment (e.g. an optional dependency you haven't installed locally).
  • The package name doesn't match -- the name in pyproject.toml differs from the distribution name (underscores vs hyphens, etc.) and can't be matched to an installed package.
  • PyPI lookup fails (when using --pin-latest) -- if the network request to PyPI errors out, the package is left as-is rather than guessing.

In all of these cases, pin-versions reports the unpinned packages so you can address them. You can use --pin-latest to automatically fetch the latest version from PyPI for any package that isn't installed locally.

Installation

pip install pin-versions

Or with uv:

uv add pin-versions

Usage

Run in a project directory with a pyproject.toml and a virtual environment:

pin-versions

This pins dependencies in [project].dependencies, [project.optional-dependencies], and [dependency-groups].

By default, pin-versions runs in dry-run mode — it shows what would change without modifying the file. Use --fix to apply the pins.

Options

Flag Description
--fix Apply changes to pyproject.toml (default is dry run)
--operator, -o Version pin operator (default: ==). Supports >=, ~=, etc.
--pyproject, -p Path to pyproject.toml (default: ./pyproject.toml)
--venv Path to the virtual environment (default: .venv)
--pin-latest Pin uninstalled packages to their latest version on PyPI

Pre-commit hook

Add to your .pre-commit-config.yaml:

repos:
  - repo: https://github.com/kjaymiller/pin-versions
    rev: v0.1.0
    hooks:
      - id: pin-versions

Contributing

  1. Fork the repo and clone it locally.
  2. Create a virtual environment and install the project in editable mode:
    uv venv && uv pip install -e ".[dev]"
    
  3. Create a branch for your changes:
    git checkout -b my-feature
    
  4. Make your changes and ensure they work by running:
    pin-versions --dry-run
    
  5. Open a pull request against main.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pin_versions-2026.3.4.tar.gz (23.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pin_versions-2026.3.4-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file pin_versions-2026.3.4.tar.gz.

File metadata

  • Download URL: pin_versions-2026.3.4.tar.gz
  • Upload date:
  • Size: 23.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pin_versions-2026.3.4.tar.gz
Algorithm Hash digest
SHA256 8b918228ed7e7579bb85ec89b1030eb3040c760b61c1e0cc6c14249dff96e9c7
MD5 ee46da7378b71f37631fbca05876786a
BLAKE2b-256 c21979f77790f08b090422171127e5b5b8600f67e6ad54b70f7fca299db98ba4

See more details on using hashes here.

Provenance

The following attestation bundles were made for pin_versions-2026.3.4.tar.gz:

Publisher: publish.yml on kjaymiller/pin-versions

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pin_versions-2026.3.4-py3-none-any.whl.

File metadata

File hashes

Hashes for pin_versions-2026.3.4-py3-none-any.whl
Algorithm Hash digest
SHA256 9db704b9922db4c2e7de2583d177cd5cfcad3b5a9b48f02815b70302fec2c368
MD5 0f6728d706a0b5879df0e3c37655bd9f
BLAKE2b-256 541a816a50a12e93e420e4b9f60f6957b166a68507b896c2f377ad5222878a5a

See more details on using hashes here.

Provenance

The following attestation bundles were made for pin_versions-2026.3.4-py3-none-any.whl:

Publisher: publish.yml on kjaymiller/pin-versions

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page