Public Member Functions | |
| None | __init__ (self) |
| Initialize an empty metadata container. | |
| None | set_value_by_name (self, str key, AllowedTypes value) |
| Store a value using a string-based key. | |
| None | remove_entry_by_name (self, str key) |
| Removes the entry using a string-based name. | |
| bool | has_entry_by_name (self, str key) |
| Check if a string key is present in the metadata. | |
| Any | try_get_value_by_name (self, str key) |
| Retrieve a value by string key, returning None if not found. | |
| T | get_value_by_name (self, Type[T] expected_type, str key) |
| Retrieve the value for a key and validate that it is of the expected type. | |
| None | set_value_by_key (self, MetadataKey key, Any value) |
| Store a value using a strongly typed metadata key. | |
| bool | has_entry_by_key (self, MetadataKey key) |
| Check if a strongly typed metadata key is present and matches the expected type. | |
| Any | get_value_by_key (self, MetadataKey key) |
| Retrieve the value of a strongly typed metadata key. | |
| List[str] | get_key_names (self) |
| Returns a list of metadata key names. | |
| bool | __eq__ (self, Any other) |
| Check if two metadata are equal. | |
| bool | __ne__ (self, Any other) |
| Check if two metadata are not equal. | |
| str | __str__ (self) |
| Return a human-readable string of metadata keys and values. | |
| str | __repr__ (self) |
| Return an unambiguous string of the Metadata object. | |
Static Public Attributes | |
| AllowedTypes | |
Protected Attributes | |
| dict | _data = {} |
A type-safe container for metadata key-value pairs.
This class provides a flexible mechanism for storing and retrieving metadata:
Values are stored in a Python dictionary but accessed with additional safety checks to ensure type correctness.
Example usage::
metadata = Metadata() metadata.set_value_by_key(MetadataKey.DEVICE_FRAME_ID, 1) print(metadata.get_value_by_key(MetadataKey.DEVICE_FRAME_ID)) # outputs: 1 print(metadata.has_entry_by_key(MetadataKey.DEVICE_FRAME_ID)) # outputs: True
| None __init__ | ( | self | ) |
Initialize an empty metadata container.
| bool __eq__ | ( | self, | |
| Any | other ) |
Check if two metadata are equal.
| other | Another Metadata object |
| bool __ne__ | ( | self, | |
| Any | other ) |
Check if two metadata are not equal.
| other | Another metadata object |
| str __repr__ | ( | self | ) |
Return an unambiguous string of the Metadata object.
| str __str__ | ( | self | ) |
Return a human-readable string of metadata keys and values.
Example: { "DeviceFrameID": 42, "DeviceTimestamp": 1695472000, "custom_data": "xyz" }
| List[str] get_key_names | ( | self | ) |
Returns a list of metadata key names.
| Any get_value_by_key | ( | self, | |
| MetadataKey | key ) |
Retrieve the value of a strongly typed metadata key.
| key | A MetadataKey object. |
| OutOfRangeException | If the key does not exist. |
| InvalidCastException | If the type does not match. |
Retrieve the value for a key and validate that it is of the expected type.
| expected_type | The expected type of the stored value. |
| key | The metadata key. |
| OutOfRangeException | If the key does not exist. |
| InvalidCastException | If the stored type does not match. |
| bool has_entry_by_key | ( | self, | |
| MetadataKey | key ) |
Check if a strongly typed metadata key is present and matches the expected type.
| key | A MetadataKey object. |
| bool has_entry_by_name | ( | self, | |
| str | key ) |
Check if a string key is present in the metadata.
| key | The metadata key. |
| None remove_entry_by_name | ( | self, | |
| str | key ) |
Removes the entry using a string-based name.
If the key does not exist, nothing happens.
| key | The metadata key to be removed. |
| None set_value_by_key | ( | self, | |
| MetadataKey | key, | ||
| Any | value ) |
Store a value using a strongly typed metadata key.
Note that passing an empty list may result in a loss of information when the metadata object is passed to an image.
| key | A MetadataKey object containing key name and expected type. |
| value | The value to store. |
| InvalidCastException | If the value type does not match the trait type. |
| None set_value_by_name | ( | self, | |
| str | key, | ||
| AllowedTypes | value ) |
Store a value using a string-based key.
Note that ignoring the allowed types for parameter value or passing an empty list may result in a loss of information when the metadata object is passed to an image.
| key | The key under which the value is stored. |
| value | Value to store. |
| Any try_get_value_by_name | ( | self, | |
| str | key ) |
Retrieve a value by string key, returning None if not found.
| key | The metadata key. |
|
protected |
|
static |