hashin: Requirements.txt Hashing Tool

1.0.5 · active · verified Fri Apr 17

hashin is a command-line tool that automates the process of adding hashes (e.g., SHA256) to entries in a `requirements.txt` file, improving supply chain security by ensuring integrity. It is currently at version 1.0.5 and maintains an active release cadence, with recent updates focusing on Python version compatibility and internal dependency management.

Common errors

Warnings

Install

Quickstart

This quickstart demonstrates how to use `hashin` from the command line. It creates a temporary `requirements.txt` file, runs `hashin` to add hashes, and then prints the updated content. `hashin` modifies the file in-place.

import subprocess
import os

# Create a dummy requirements.txt for demonstration
requirements_content = """
requests==2.31.0
click==8.1.7
"""
with open("requirements.txt", "w") as f:
    f.write(requirements_content)

print("Original requirements.txt:")
with open("requirements.txt", "r") as f:
    print(f.read())

try:
    # Run hashin to add hashes to requirements.txt in place
    # Using -r requirements.txt explicitly for clarity, though it's the default.
    print("\nRunning: hashin -r requirements.txt\n")
    result = subprocess.run(["hashin", "-r", "requirements.txt"], capture_output=True, text=True, check=True)
    print("hashin output:")
    print(result.stdout)
    if result.stderr:
        print("hashin stderr (if any):\n" + result.stderr)

    print("\nUpdated requirements.txt:")
    with open("requirements.txt", "r") as f:
        print(f.read())

except subprocess.CalledProcessError as e:
    print(f"Error running hashin: {e.stderr}")
except FileNotFoundError:
    print("Error: 'hashin' command not found. Please ensure it's installed and in your PATH.")
finally:
    # Clean up the dummy file
    if os.path.exists("requirements.txt"):
        os.remove("requirements.txt")

view raw JSON →