TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/ismael-sarmiento/kimera_python/llms.txt
Use this file to discover all available pages before exploring further.
build_hash function produces a stable, deterministic MD5 hex digest for any Python object by encoding both str(_obj) and str(type(_obj)) before hashing. Combining the string representation with the type is critical for collision safety — without the type component, the integer 42, the float 42.0, and the string '42' would all produce the same hash because str() renders them identically. Use build_hash wherever you need a consistent, reproducible key: cache key generation, request deduplication, content-addressable storage, or fingerprinting intermediate pipeline results.
Import
Function Signature
Any Python object. The function calls
str(_obj) to obtain the object’s representation and str(type(_obj)) to capture its type. For custom classes, define __str__ or __repr__ to ensure consistent output across sessions.How the Hash Is Built
Internally the function concatenates two encoded byte strings and passes them tohashlib.md5:
str() output is stable. For custom classes that do not define __str__ or __repr__, the default object.__repr__ includes the memory address — which changes between interpreter runs — so the hash will not be reproducible across sessions.
Usage Examples
The following examples demonstrate howbuild_hash handles primitives, collections, and custom objects. Notice that values that look identical in string form — such as 42 (int) and '42' (str) — produce distinct hashes because their types differ.
Using build_hash as a Cache Key
A common pattern is to hash a dictionary of query parameters or function arguments to produce a compact, fixed-length cache key. This avoids dealing with arbitrarily long or complex key strings while guaranteeing that two semantically identical parameter sets always map to the same key.
build_hash relies on str() for object representation. For custom classes, define __repr__ or __str__ to ensure stable hashing across interpreter sessions. Without an explicit representation, the default object.__repr__ includes the memory address, which changes between runs and breaks repeatability.