Skip to content

kiara.operations.store_value

StoreOperationType

Store a value into a local data store.

This is a special operation type, that is used internally by the [LocalDataStore](http://dharpa.org/kiara/latest/api_reference/kiara.data.registry.store/#kiara.data.registry.store.LocalDataStore] data registry implementation.

For each value type that should be supported by the persistent kiara data store, there must be an implementation of the StoreValueTypeModule class, which handles the actual persisting on disk. In most cases, end users won't need to interact with this type of operation.

StoreValueModuleConfig pydantic-model

value_type: str pydantic-field required

The type of the value to save.

StoreValueTypeModule

Store a specific value type.

This is used internally.

create_input_schema(self)

Abstract method to implement by child classes, returns a description of the input schema of this module.

If returning a dictionary of dictionaries, the format of the return value is as follows (items with '*' are optional):

{ "[input_field_name]: { "type": "[value_type]", "doc*": "[a description of this input]", "optional*': [boolean whether this input is optional or required (defaults to 'False')] "[other_input_field_name]: { "type: ... ... }

Source code in kiara/operations/store_value.py
def create_input_schema(
    self,
) -> typing.Mapping[
    str, typing.Union[ValueSchema, typing.Mapping[str, typing.Any]]
]:

    field_name = self.get_config_value("value_type")
    if field_name == "any":
        field_name = "value_item"

    inputs: typing.Mapping[str, typing.Any] = {
        "value_id": {
            "type": "string",
            "doc": "The id to use when saving the value.",
        },
        field_name: {
            "type": self.get_config_value("value_type"),
            "doc": f"A value of type '{self.get_config_value('value_type')}'.",
        },
        "base_path": {
            "type": "string",
            "doc": "The base path to save the value to.",
        },
    }

    return inputs

create_output_schema(self)

Abstract method to implement by child classes, returns a description of the output schema of this module.

If returning a dictionary of dictionaries, the format of the return value is as follows (items with '*' are optional):

{ "[output_field_name]: { "type": "[value_type]", "doc*": "[a description of this output]" "[other_input_field_name]: { "type: ... ... }

Source code in kiara/operations/store_value.py
def create_output_schema(
    self,
) -> typing.Mapping[
    str, typing.Union[ValueSchema, typing.Mapping[str, typing.Any]]
]:

    field_name = self.get_config_value("value_type")
    if field_name == "any":
        field_name = "value_item"

    outputs: typing.Mapping[str, typing.Any] = {
        field_name: {
            "type": self.get_config_value("value_type"),
            "doc": "The original or cloned (if applicable) value that was saved.",
        },
        "load_config": {
            "type": "load_config",
            "doc": "The configuration to use with kiara to load the saved value.",
        },
    }

    return outputs

retrieve_module_profiles(kiara) classmethod

Retrieve a collection of profiles (pre-set module configs) for this kiara module type.

This is used to automatically create generally useful operations (incl. their ids).

Source code in kiara/operations/store_value.py
@classmethod
def retrieve_module_profiles(
    cls, kiara: Kiara
) -> typing.Mapping[str, typing.Union[typing.Mapping[str, typing.Any], Operation]]:

    all_metadata_profiles: typing.Dict[
        str, typing.Dict[str, typing.Dict[str, typing.Any]]
    ] = {}

    all_types_and_subtypes = set()
    for sup_type in cls.get_supported_value_types():
        if sup_type not in kiara.type_mgmt.value_type_names:
            log_message(
                f"Ignoring save operation for type '{sup_type}': type not available"
            )
            continue

        all_types_and_subtypes.add(sup_type)
        sub_types = kiara.type_mgmt.get_sub_types(sup_type)
        all_types_and_subtypes.update(sub_types)

    for sup_type in all_types_and_subtypes:

        op_config = {
            "module_type": cls._module_type_id,  # type: ignore
            "module_config": {"value_type": sup_type},
            "doc": f"Store a value of type '{sup_type}'.",
        }
        all_metadata_profiles[f"store.{sup_type}"] = op_config

    return all_metadata_profiles

store_value(self, value, base_path)

Save the value, and return the load config needed to load it again.

Source code in kiara/operations/store_value.py
@abc.abstractmethod
def store_value(
    self, value: Value, base_path: str
) -> typing.Union[
    typing.Tuple[typing.Dict[str, typing.Any], typing.Any],
    typing.Dict[str, typing.Any],
]:
    """Save the value, and return the load config needed to load it again."""