or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

tessl/pypi-pur

Update packages in a requirements.txt file to latest versions.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/pur@6.1.x

To install, run

npx @tessl/cli install tessl/pypi-pur@6.1.0

index.mddocs/

PUR (pip-update-requirements)

PUR is a Python library and command-line tool that updates packages in a requirements.txt file to their latest versions. It safely parses requirements files, checks PyPI for latest versions, and updates version constraints while preserving the original file format and comments.

Package Information

  • Package Name: pur
  • Language: Python
  • Installation: pip install pur

Core Imports

from pur import update_requirements

For CLI usage:

pur -r requirements.txt

Basic Usage

Command Line Interface

# Update requirements.txt to latest versions
pur -r requirements.txt

# Interactive mode with prompts for each package
pur --interactive

# Dry run to preview changes without modifying files
pur --dry-run

# Update only specific packages
pur --only numpy,pandas

# Skip certain packages from updates
pur --skip tensorflow,torch

# Limit updates to minor versions only
pur --minor "*"

# Limit updates to patch versions only
pur --patch numpy,scipy

# Allow pre-release versions for specific packages
pur --pre "numpy,*"

# Use custom PyPI index
pur --index-url https://pypi.example.com/simple/

# Output to different file
pur -r requirements.txt -o updated-requirements.txt

Programmatic Interface

from pur import update_requirements

# Basic usage - update requirements.txt
updates = update_requirements(input_file='requirements.txt')

# With specific options
updates = update_requirements(
    input_file='requirements.txt',
    output_file='updated-requirements.txt',
    dry_run=True,
    skip=['tensorflow'],
    only=['numpy', 'pandas']
)

# Process update results
for package_name, update_list in updates.items():
    for update_info in update_list:
        print(f"Package: {update_info['package']}")
        print(f"Current: {update_info['current']}")
        print(f"Latest: {update_info['latest']}")
        print(f"Updated: {update_info['updated']}")
        print(f"Message: {update_info['message']}")

Architecture

PUR operates through a multi-layered architecture:

  • CLI Layer: Click-based command-line interface with comprehensive options
  • Core Logic: Requirements file parsing, package discovery, and version resolution
  • Pip Integration: Uses vendored pip internals for requirements file parsing and PyPI queries
  • Version Management: Sophisticated version constraint handling and update policies

The tool preserves the exact format of requirements files, including comments, spacing, and nested requirements, while safely updating only the version specifications.

Capabilities

Requirements File Processing

Core functionality for parsing, analyzing, and updating Python requirements files with full support for pip's requirements file format.

def update_requirements(
    input_file=None,
    output_file=None,
    force=False,
    interactive=False,
    skip=[],
    only=[],
    dry_run=False,
    minor=[],
    patch=[],
    pre=[],
    no_recursive=False,
    echo=False,
    index_urls=[],
    cert=None,
    no_ssl_verify=False
):
    """
    Update a requirements file to latest package versions.
    
    Parameters:
    - input_file (str, optional): Path to requirements.txt file (default: 'requirements.txt')
    - output_file (str, optional): Output file path (default: overwrites input_file)
    - force (bool): Update packages without version constraints (default: False)
    - interactive (bool): Prompt before each update (default: False)
    - skip (list): Package names to skip updating (default: [])
    - only (list): Only update these packages, ignore others (default: [])
    - dry_run (bool): Preview changes without writing files (default: False)
    - minor (list): Packages limited to minor version updates (default: [])
    - patch (list): Packages limited to patch version updates (default: [])
    - pre (list): Packages allowing pre-release versions (default: [])
    - no_recursive (bool): Don't update nested requirements files (default: False)
    - echo (bool): Print update messages to stdout (default: False)
    - index_urls (list): Custom PyPI index URLs (default: [])
    - cert (str, optional): Path to CA certificate bundle (default: None)
    - no_ssl_verify (bool): Disable SSL certificate verification (default: False)
    
    Returns:
    dict: Package update information grouped by package name. Each package
          maps to a list of update dictionaries containing:
          - 'package': Package name
          - 'current': Current version string
          - 'latest': Latest available version string  
          - 'updated': Boolean indicating if package was updated
          - 'message': Human-readable update message
    """

Command Line Interface

Complete CLI with extensive options for flexible requirements file updating workflows.

def pur(**options):
    """
    Command line entry point for pur CLI tool.
    
    Command Line Options:
    --requirement, -r PATH: Requirements file path (default: requirements.txt)
    --output, -o PATH: Output file path (default: overwrites input file)
    --interactive: Interactive prompts for each package update
    --force, -f: Force update packages without version constraints
    --dry-run, -d: Preview changes without writing files
    --no-recursive, -n: Skip nested requirements files
    --skip TEXT: Comma-separated list of packages to skip
    --only TEXT: Comma-separated list of packages to update exclusively
    --minor TEXT: Packages limited to minor version updates (use "*" for all)
    --patch TEXT: Packages limited to patch version updates (use "*" for all)
    --pre TEXT: Packages allowing pre-release versions (use "*" for all)
    --index-url TEXT: Custom PyPI index URLs (can be specified multiple times)
    --cert PATH: Path to CA certificate bundle
    --no-ssl-verify: Disable verifying the server's TLS certificate
    --nonzero-exit-code, -z: Use exit codes 10 (up-to-date) or 11 (updated)
    --version: Show version and exit
    --help: Show help message and exit
    
    Returns:
    None: Exits with status code 0 on success, non-zero on failure
    """

Exception Classes

class StopUpdating(Exception):
    """
    Exception that may be raised during interactive updates.
    
    This exception is raised when a user chooses to quit during
    interactive mode. It's primarily an internal exception but 
    may be encountered when extending pur's functionality.
    """

Return Value Structure

The update_requirements function returns a dictionary with the following structure:

{
    "package_name": [
        {
            "package": "package_name",
            "current": "1.0.0",  # Current version or "Unknown"
            "latest": "2.0.0",   # Latest available version
            "updated": True,     # Whether update was applied
            "message": "Updated package_name: 1.0.0 -> 2.0.0"
        }
    ]
}