httk.data.db.identity

Content identity: a canonical text form and SHA-256 identity for storable instances.

content_id() gives every storable instance a deterministic identity derived purely from its stored, non-derived field values — the basis of the store layer’s "content_id" deduplication policy and of its store-managed content_id column. Two instances (even of distinct object identity, even holding distinct-but-equal nested instances) get the same identity exactly when their stored values are equal.

The identity hashes canonical_form(): a compact JSON text of [table_name, [[field, canonical value], ...]] with the stored non-derived fields sorted by field name. Canonical values are chosen to be exact and deterministic per field role:

  • rationals (fractions.Fraction, FracScalar, SurdScalar) — their canonical exact text;

  • FracVector tensors — the canonical exact tensor text;

  • float — its repr (shortest exact round-trip text);

  • bytes — its hex text;

  • str/int/bool/None — as-is;

  • datetime (and any single-text-column codec) — its encoded text;

  • lists/tuples — JSON arrays of their elements’ canonical values, in order;

  • nested storable instances — their content_id(), recursively.

Derived (stored_property) values are functions of the fields and are excluded, so they can never skew the identity.

Functions

canonical_form(→ str)

The deterministic canonical JSON text of a storable instance's stored values.

content_id(→ str)

The SHA-256 hex digest (64 hex characters) of canonical_form() of obj.

Module Contents

httk.data.db.identity.canonical_form(obj: Any) str[source]

The deterministic canonical JSON text of a storable instance’s stored values.

Resolves the schema of obj’s class (so the class must be storable) and serializes [table_name, [[field, canonical value], ...]] over the non-derived stored fields, sorted by field name, as compact JSON.

httk.data.db.identity.content_id(obj: Any) str[source]

The SHA-256 hex digest (64 hex characters) of canonical_form() of obj.