caikit.core.data_model.json_dict

This module holds common utilities for managing arbitrary JSON serializable dicts as protobuf Struct objects

Attributes

JsonDictValue

JsonDict

STRUCT_PROTOBUF_NAME

Functions

dict_to_struct(→ google.protobuf.struct_pb2.Struct)

Convert a python dict to a protobuf Struct

struct_to_dict(→ JsonDict)

Convert a struct into the equivalent json dict

_value_to_struct_value(value, struct_class, ...)

Recursive helper to convert python values to struct values

_struct_value_to_py(→ JsonDictValue)

Recursive helper to convert struct values to python values

_get_message_class(...)

Helper to get the concrete protobuf class from a descriptor. This

Module Contents

caikit.core.data_model.json_dict.JsonDictValue
caikit.core.data_model.json_dict.JsonDict
caikit.core.data_model.json_dict.STRUCT_PROTOBUF_NAME = 'google.protobuf.Struct'
caikit.core.data_model.json_dict.dict_to_struct(dictionary: JsonDict, struct_class: type | None = None, value_class: type | None = None, list_value_class: type | None = None) google.protobuf.struct_pb2.Struct[source]

Convert a python dict to a protobuf Struct

caikit.core.data_model.json_dict.struct_to_dict(struct: google.protobuf.struct_pb2.Struct) JsonDict[source]

Convert a struct into the equivalent json dict

caikit.core.data_model.json_dict._value_to_struct_value(value, struct_class, value_class, list_value_class)[source]

Recursive helper to convert python values to struct values

caikit.core.data_model.json_dict._struct_value_to_py(struct_value: google.protobuf.struct_pb2.Value) JsonDictValue[source]

Recursive helper to convert struct values to python values

caikit.core.data_model.json_dict._get_message_class(desc: google.protobuf.descriptor.Descriptor) google.protobuf.message_factory.message.Message[source]

Helper to get the concrete protobuf class from a descriptor. This supports compatibility between protobuf 3.X and 4.X