Skip to content

latent.utils

Utility functions for hashing and dynamic imports.

Functions

import_string

import_string(dotted_path: str) -> Any

Import a class or function from a dotted path.

Args: dotted_path: "module.submodule.ClassName"

Returns: The imported object

Raises: ImportError: If module cannot be imported AttributeError: If class/function cannot be found

stable_hash

stable_hash(obj: Any) -> str

Generate a stable MD5 hash for an object.

Handles: - Primitives (str, int, float, bool, None) - Dictionaries and Lists (recursively sorted) - Pandas DataFrames (content-based) - Pydantic Models - Other objects (via str representation)

Args: obj: Object to hash

Returns: Hex digest string

truncate_for_logging

truncate_for_logging(value: Any, max_length: int = 200) -> str

Truncate/summarize a value for logging purposes.

Handles DataFrames, arrays, large collections, and long strings gracefully.

Args: value: Any value to summarize max_length: Maximum string length before truncation

Returns: A concise string representation