Skip to main content

Update and resolve requirements.txt based on the Python environment and pip used.

Project description

Python Requirements Updater

PyPI version License: MIT

Not pur, but pru. It updates and resolves requirements.txt based on the current Python environment and pip version. Unlike Poetry and other dependency management tools, pru can be used outside your project and doesn't need to be included as a project dependency. Just run pru whenever you want to install the latest packages and update requirements.txt accordingly.

For example, turn this requirements.txt:

requests>=2.32.1
numpy<=1.26.3
pandas==2.2.1
scipy

into this:

requests==2.32.3
numpy==2.0.0
pandas==2.2.2
scipy==1.14.0

The primary purpose of pru is to update packages and pin their versions in requirements.txt. The motivation behind this is that, unlike pyproject.toml, requirements.txt should lock the versions of the packages currently used in the environment to ensure future reproducibility. This is best suited for repositories containing experiments and examples, not for package development. An article explaining pru also available at Medium.

Performance with uv

pru automatically detects and uses uv when available, making package installations significantly faster.

Installation

Standard installation:

pip install pru

For faster performance, install with uv:

pip install uv
pip install pru

Or using uv directly:

uv pip install pru

Quick Start with uv

For developers working on a project, use pru to pin your requirements.txt as follows:

uv venv env3.14 --python 3.14
source env3.14/bin/activate
uv pip install pru
pru -r requirements.txt

Then, you can guide your users as follows:

uv venv env3.14 --python 3.14
source env3.14/bin/activate
uv pip install -r requirements.txt

[!NOTE] On windows, a Python environment can be activated using source env3.14\Scripts\activate.

Usage

pru has multiple use cases. The main utilities (but not limited to) are:

  1. upgrade_requirements: upgrade and pin requirements.
  2. replace_requirements_packages_versions: update and pin the requirements file based on the installed packages.
  3. get_installed_packages_name_and_version: list the installed packages and their versions.
  4. get_installed_requirements_packages_and_version: list the installed packages and their versions, based on the list of packages in the requirements file.

pru can be used both as a Python package and from the CLI.

Using CLI (automatically uses uv if available):

pru

Explicit run using CLI:

pru -r "requirements.txt" upgrade_requirements --cmd "uv pip install --upgrade" -o "requirements.txt"

Using Python:

from pru import upgrade_requirements

file_path = 'requirements.txt'
upgrade_requirements(file_path, command='uv pip install --upgrade')

Very useful in workflows (this will update requirements.txt, and you can commit the changes after this step):

      - name: Upgrade pip and install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install pru
          pru

or to debug installed packages in a workflow:

      - name: Run pru if tests fail
        if: steps.pytest.outcome != 'success'
        run: |
          python_version_minor=$(python -c "import sys; print(f'{sys.version_info.minor}')")
          pru -r pytests/requirements/3_${python_version_minor}/requirements.txt
          echo "Contents of pytests/requirements/3_${python_version_minor}/requirements.txt:"
          cat pytests/requirements/3_${python_version_minor}/requirements.txt

Known Issue

In Python 3.7, pru sometimes cannot install and update requirements using a single call to upgrade_requirements. To fix this, simply run the command twice.

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

pru-0.0.4.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

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

pru-0.0.4-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file pru-0.0.4.tar.gz.

File metadata

  • Download URL: pru-0.0.4.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pru-0.0.4.tar.gz
Algorithm Hash digest
SHA256 818a59d7a345ee33cd1cb883aca101647e72f5c56596a2cdc033e267354b6524
MD5 49c3bdd5ee1bc1b929c92d3a155151bd
BLAKE2b-256 d4195e0ceb451f26b6e7bbdeb584c6ca7411e716bf940f03764e4e462a22f11d

See more details on using hashes here.

File details

Details for the file pru-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: pru-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pru-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 c1a22cfdae26a803c47f382000a28fcdb9e5d78c40eab09747f62cf4914c36c1
MD5 371952e1a25f72859a40e87d4b1cff11
BLAKE2b-256 3f44f88e6a8228934144baf96f39f2806f37b43602ad4d8b489e0e4638c33209

See more details on using hashes here.

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