Skip to main content

Rock-solid primitives for content-addressable hashing, chain fingerprinting, and config diffing

Project description

knurl

Rock-solid primitives for content-addressable hashing, chain fingerprinting, and config diffing.

Extracted from the SpiritEngine project.

Modules

  • canon - Canonical JSON serialization (RFC 8785 + mandatory Unicode NFC normalization). Deterministic, byte-identical across implementations and Python versions. Floats are rejected by default (pass accept_floats=True for non-hash use); integers keep their exact digits; NaN/Infinity, unassigned code points, and duplicate-after-NFC keys raise CanonError.
  • hash - Content-addressable hashing
  • chain - Merkle-like chain fingerprinting
  • diverge - Divergence detection for fingerprint chains
  • diff - JSON Patch (RFC 6902) diffs
  • yield_ - Yield data serialization

Installation

pip install knurl

# With diff support (requires jsonpatch)
pip install knurl[diff]

Usage

from knurl import canon, hash, chain, diverge

# Canonical serialization
canonical_bytes = canon.serialize({"b": 1, "a": 2})  # b'{"a":2,"b":1}'

# Content-addressable hashing
content_hash = hash.compute("hello world")        # 'sha256:...' (strings)
blob_hash = hash.compute_bytes(b"\x00\x01\x02")   # 'sha256:...' (raw bytes)
file_hash = hash.compute_file("video.mp4")        # 'sha256:...' (streamed, multi-GB safe)
tree_hash = hash.compute_tree("mirror/")          # 'sha256:...' (reproducible directory digest)

# Same walk, but keep the per-file content hashes (for content-addressed dedup)
manifest = hash.compute_tree_manifest("mirror/")  # TreeManifest(digest, entries, paths)
manifest.digest                                   # == compute_tree("mirror/")
manifest.entries["index.html"]                    # {'type': 'file', 'hash': 'sha256:...'} (NFC key)
manifest.paths["index.html"]                      # real on-disk relative path, to re-read the bytes

# Chain fingerprinting
fingerprints = chain.fingerprint([config1, config2, config3])

# Divergence detection
result = diverge.find(old_fingerprints, new_fingerprints)

Requirements

  • Python 3.10+
  • No dependencies (stdlib only)
  • Optional: jsonpatch for diff module

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

knurl-0.5.0.tar.gz (128.9 kB view details)

Uploaded Source

Built Distribution

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

knurl-0.5.0-py3-none-any.whl (33.0 kB view details)

Uploaded Python 3

File details

Details for the file knurl-0.5.0.tar.gz.

File metadata

  • Download URL: knurl-0.5.0.tar.gz
  • Upload date:
  • Size: 128.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for knurl-0.5.0.tar.gz
Algorithm Hash digest
SHA256 7b84648be2a08d0bf8dbd776fd234501496dd251631a18fdd037f9f75a8c774f
MD5 7431d745f7bc60fe1b8dd6b8973a0dbb
BLAKE2b-256 ee20879de2f7627247c3ea94f40f724d9074bc2b215966a07bddb0d471e34147

See more details on using hashes here.

Provenance

The following attestation bundles were made for knurl-0.5.0.tar.gz:

Publisher: publish.yml on spiritengine/knurl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file knurl-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: knurl-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 33.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for knurl-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fd041c39683287ab21e35d2e9197339a0381c12482f0c76cca870e14fc61b9e9
MD5 363445e665626618a23cf61a280abd8c
BLAKE2b-256 d560f7c3644a9708c280dd938d3c580433b4019cb37f2e608106e9a32729a550

See more details on using hashes here.

Provenance

The following attestation bundles were made for knurl-0.5.0-py3-none-any.whl:

Publisher: publish.yml on spiritengine/knurl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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