Skip to main content

Simplified hashing helpers for strings, files, and checksums

Project description

philiprehberger-hash-utils

Tests PyPI version License

Simplified hashing helpers for strings, files, and checksums.

Installation

pip install philiprehberger-hash-utils

Usage

Hash Strings and Bytes

from philiprehberger_hash_utils import hash_string, hash_bytes

hash_string("hello world")                # SHA-256 hex digest
hash_string("hello world", "md5")         # MD5 hex digest
hash_bytes(b"\x00\x01\x02", "sha512")    # SHA-512 hex digest

Hash Files

from philiprehberger_hash_utils import hash_file

digest = hash_file("large_file.bin")  # Streams in chunks
digest = hash_file("data.csv", algorithm="blake2b")

Hash Dictionaries

from philiprehberger_hash_utils import hash_dict

# Deterministic — key order doesn't matter
hash_dict({"b": 2, "a": 1}) == hash_dict({"a": 1, "b": 2})  # True

Verify Checksums

from philiprehberger_hash_utils import verify_checksum

# Timing-safe comparison
is_valid = verify_checksum("download.zip", expected_sha256)

Supported Algorithms

md5, sha1, sha256 (default), sha512, blake2b

API

Function / Class Description
hash_string(s, algorithm="sha256") Hash a string
hash_bytes(data, algorithm="sha256") Hash raw bytes
hash_file(path, algorithm="sha256", chunk_size=8192) Hash a file (streaming)
hash_dict(d, algorithm="sha256") Deterministic dict hash
verify_checksum(path, expected, algorithm="sha256") Timing-safe file verification
SUPPORTED_ALGORITHMS List of supported algorithm names

Development

pip install -e .
python -m pytest tests/ -v

License

MIT

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

philiprehberger_hash_utils-0.1.8.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

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

philiprehberger_hash_utils-0.1.8-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file philiprehberger_hash_utils-0.1.8.tar.gz.

File metadata

File hashes

Hashes for philiprehberger_hash_utils-0.1.8.tar.gz
Algorithm Hash digest
SHA256 81e46ea5745da715c6b7371e5e073d2dc2f5b48b8fbd9d81fcd0251c3b288bc0
MD5 21e6a115e6cba5fa8b09296aa339e164
BLAKE2b-256 6be1fbc904c6c440d6d46fa89577ba3661cb4bdfd288926b61f96cf1f9762b67

See more details on using hashes here.

File details

Details for the file philiprehberger_hash_utils-0.1.8-py3-none-any.whl.

File metadata

File hashes

Hashes for philiprehberger_hash_utils-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 ac5d70f61323a7cbc5328aa979178dbaf7320cd42a9b3ca6d57eb305e06c4f7b
MD5 c27970a7aa1c6631f61f84e17474df34
BLAKE2b-256 71890ab1e82ba4160972ffdf8d126151db1724c736e279460d9e844b26225618

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