Skip to main content

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

  1. JSON-serializable primitives (None, bool, int, float, str)
  2. numpy ndarrays (via shape + dtype + raw bytes)
  3. pandas DataFrames (via columns + index + array serialization)
  4. pandas Series (via name + array serialization)
  5. Dicts (sorted keys, recursive serialization)
  6. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

scicanonicalhash-0.1.0.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

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

scicanonicalhash-0.1.0-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

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

Hashes for scicanonicalhash-0.1.0.tar.gz
Algorithm Hash digest
SHA256 976d7bfb4fd7e68569923862b74aca9baafbc105b45a9a8d3036c07955d00290
MD5 722ae5674bf75295106215bcaf63ac45
BLAKE2b-256 983d9bed1d38e572d393a39bdb829568c4fe1c52d20dc0576978ac67293325ea

See more details on using hashes here.

File details

Details for the file scicanonicalhash-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for scicanonicalhash-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 380635bf5fcdcfb7528d4a6323077cb7357b414145506fd123d61938f613168a
MD5 615a0f0b0ae7742ebe20b8652352023c
BLAKE2b-256 7f9324e9176a9d9227f3c5819e98089236ef73390cc214f9919131142c5db74e

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