sift_client.util.metadata
¶
| CLASS | DESCRIPTION |
|---|---|
Metadata |
Entity metadata: a dict of key -> first value, plus access to every |
| FUNCTION | DESCRIPTION |
|---|---|
metadata_dict_to_proto |
Converts metadata dictionary into a list of MetadataValue objects. |
metadata_proto_to_dict |
Converts a list of MetadataValue objects into a Metadata mapping. |
Metadata
¶
Metadata(
first_values: dict[str, str | float | bool]
| None = None,
all_values: dict[str, list[str | float | bool]]
| None = None,
)
Bases: Dict[str, Union[str, float, bool]]
Entity metadata: a dict of key -> first value, plus access to every value of a key via getall().
A metadata key may hold multiple values (multi-value metadata), kept in canonical order. Plain dict access (md["k"], md.get("k"), iteration, ==) sees the first value only -- the same value every single-value context uses -- so existing code written against scalar metadata keeps working unchanged. getall(key) returns the full ordered value list; its first element is always the dict value.
Build the mapping from a first-value dict and optional full value lists.
| METHOD | DESCRIPTION |
|---|---|
getall |
Return every value of |
getall
¶
Return every value of key as a new list, in canonical order.
Keys absent from the metadata yield []; keys holding a single value yield a one-element list.
metadata_dict_to_proto
¶
Converts metadata dictionary into a list of MetadataValue objects.
| PARAMETER | DESCRIPTION |
|---|---|
_metadata
|
Dictionary of metadata key-value pairs.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[MetadataValue]
|
List of MetadataValue objects. |
metadata_proto_to_dict
¶
metadata_proto_to_dict(
metadata: list[MetadataValue],
) -> Metadata
Converts a list of MetadataValue objects into a Metadata mapping.
A key may appear multiple times when it holds multiple values
(multi-value metadata). The mapping's dict view keeps the first value of
each key -- the API returns values in canonical order, so this matches
the value every other single-value context (e.g. backend flattening)
uses -- and Metadata.getall(key) returns the full ordered list.
| PARAMETER | DESCRIPTION |
|---|---|
metadata
|
List of MetadataValue objects.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Metadata
|
Metadata mapping of key-value pairs (first value per key; all values |
Metadata
|
via getall). |