caikit.core.data_model.data_backends

Class higherarchy for implementing independent backends for Data Model classes

Submodules

Classes

DataModelBackendBase

A base interface class for accessing data from within a given backend

DictBackend

Data model backend for a raw dict

Package Contents

class caikit.core.data_model.data_backends.DataModelBackendBase[source]

Bases: abc.ABC

A base interface class for accessing data from within a given backend data layout

abstract get_attribute(data_model_class: Type[caikit.core.data_model.base.DataBase], name: str) Any | caikit.core.data_model.base.DataBase.OneofFieldVal[source]

A data model backend must implement this in order to provide the frontend view the functionality needed to lazily extract data.

Args:
data_model_class (Type[DataBase]): The frontend data model class

that is accessing this attribute

name (str): The name of the attribute to access

Returns:
value: Union[Any, OneofFieldVal]

The extracted attribute value or a OneofFieldVal that wraps the field val with an indicator about the oneof field that is set.

cache_attribute(name: str, value: Any) bool[source]

Determine whether or not to cache the given attribute’s result on the wrapping data model object.

The base implementation always returns True. Derived classes may opt to always return False to fully disable caching, or cache conditionally based on the name/value of the individual field.

Args:

name (str): The name of the attribute to check value (Any): The extracted value

Returns:
should_cache: bool

True if the value should be cached, False otherwise

class caikit.core.data_model.data_backends.DictBackend(data_dict: dict)[source]

Bases: caikit.core.data_model.data_backends.base.DataModelBackendBase

Data model backend for a raw dict

_data_dict
get_attribute(data_model_class: Type[caikit.core.data_model.base.DataBase], name: str) Any[source]

Fetch the attribute out of the internal dict and validate it against the target data model class. If the target attribute is a nested data model type, wrap the corresponding nested dict in an instance of this same backend.

Args:
data_model_class (Type[DataBase]): The frontend data model class

that is accessing this attribute

name (str): The name of the attribute to access

Returns:
value: Any

The extracted attribute value