loom.eka.utilities.serialization

Copyright (c) Entropica Labs Pte Ltd 2025.

Use, distribution and reproduction of this program in its source or compiled form is prohibited without the express written consent of Entropica Labs Pte Ltd.

loom.eka.utilities.serialization.apply_to_nested(nested_list, func, param=None)[source]

Apply a function to all elements of a nested list.

loom.eka.utilities.serialization.dump(data, file)[source]

Write a pydantic dataclass as JSON to a file.

Parameters:
  • data (dataclass) – Pydantic dataclass to be saved as JSON

  • file (str) – Filename to write to

loom.eka.utilities.serialization.dumps(data)[source]

Return the pydantic dataclass as a JSON string. If the dataclass defines its own custom dumps() method, the custom method is used. Otherwise, the dataclass object is converted to a dictionary using the asdict method of the dataclasses module and then converted to a JSON string.

Parameters:

data (dataclass) – Pydantic dataclass to be saved as JSON

Returns:

JSON string representation of the Eka

Return type:

str

loom.eka.utilities.serialization.findall(in_list, value)[source]

Find all the indices of a value in a list.

loom.eka.utilities.serialization.load(cls, file)[source]

Load a pydantic dataclass from a JSON file.

Parameters:
  • cls (dataclass) – The dataclass to be loaded from the JSON file

  • file (str) – Filename to read from

Return type:

An instance of cls containing the data from the JSON file

loom.eka.utilities.serialization.loads(cls, data_json)[source]

Load the a pydantic dataclass from a JSON string. If the dataclass defines its own custom loads() method, the custom method is used, giving the loaded dictionary as input.

Parameters:
  • cls (dataclass) – The dataclass to be loaded from the JSON string

  • data_json (str) – Dataclass saved as JSON string

Return type:

An instance of cls containing the data from the JSON string