Deterministic hashing for arbitrary Python objects
Project description
Canonical Hash
Deterministic hashing for arbitrary Python objects.
Provides utilities for creating stable, deterministic hashes of Python objects, essential for cache key computation, data versioning, and reproducibility.
Usage
from scicanonicalhash import canonical_hash, generate_record_id
# Hash any supported Python object
h = canonical_hash(42)
h = canonical_hash([1, 2, 3])
h = canonical_hash({"key": "value"})
# Generates a 16-character hex string (first 64 bits of SHA-256)
assert len(h) == 16
assert canonical_hash(42) == canonical_hash(42) # Deterministic
Supported Types
- JSON-serializable primitives (None, bool, int, float, str)
- numpy ndarrays (via shape + dtype + raw bytes)
- pandas DataFrames (via columns + index + array serialization)
- pandas Series (via name + array serialization)
- Dicts (sorted keys, recursive serialization)
- Lists/tuples (order-preserving, recursive serialization)
generate_record_id
Generate a unique record ID from type, schema version, content hash, and metadata:
rid = generate_record_id("MyData", 1, "abc123", {"subject": 1})
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file scicanonicalhash-0.1.0.tar.gz.
File metadata
- Download URL: scicanonicalhash-0.1.0.tar.gz
- Upload date:
- Size: 3.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
976d7bfb4fd7e68569923862b74aca9baafbc105b45a9a8d3036c07955d00290
|
|
| MD5 |
722ae5674bf75295106215bcaf63ac45
|
|
| BLAKE2b-256 |
983d9bed1d38e572d393a39bdb829568c4fe1c52d20dc0576978ac67293325ea
|
File details
Details for the file scicanonicalhash-0.1.0-py3-none-any.whl.
File metadata
- Download URL: scicanonicalhash-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
380635bf5fcdcfb7528d4a6323077cb7357b414145506fd123d61938f613168a
|
|
| MD5 |
615a0f0b0ae7742ebe20b8652352023c
|
|
| BLAKE2b-256 |
7f9324e9176a9d9227f3c5819e98089236ef73390cc214f9919131142c5db74e
|