guidellm.utils.mixins
Mixin classes for common metadata extraction and object introspection.
Provides reusable mixins for extracting structured metadata from objects, enabling consistent information exposure across different class hierarchies.
PYTHON_PRIMITIVES = (str, int, float, bool, list, tuple, dict) module-attribute
Type alias for serialized object representations
InfoMixin
Mixin class providing standardized metadata extraction for introspection.
Enables consistent object metadata extraction patterns across different class hierarchies for debugging, serialization, and runtime analysis. Provides both instance and class-level methods for extracting structured information from arbitrary objects with fallback handling for objects without built-in info capabilities.
Example: :: from guidellm.utils.mixins import InfoMixin
class ConfiguredClass(InfoMixin):
def __init__(self, setting: str):
self.setting = setting
obj = ConfiguredClass("value")
# Returns {'str': 'ConfiguredClass(...)', 'type': 'ConfiguredClass', ...}
print(obj.info)
Source code in src/guidellm/utils/mixins.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | |
info property
Return structured metadata about this instance.
Provides consistent access to object metadata for debugging, serialization, and introspection. Uses the create_info_dict method to generate standardized metadata format including class information and public attributes.
Returns:
| Type | Description |
|---|---|
dict[str, Any] | Dictionary containing class name, module, and public attributes |
create_info_dict(obj) classmethod
Create a structured info dictionary for the given object.
Builds standardized metadata dictionary containing object identification, type information, and accessible attributes. Used internally by other info extraction methods and available for direct metadata construction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj | Any | Object to extract info from | required |
Returns:
| Type | Description |
|---|---|
dict[str, Any] | Dictionary containing structured metadata about the object |
Source code in src/guidellm/utils/mixins.py
extract_from_obj(obj) classmethod
Extract structured metadata from any object.
Attempts to use the object's own info method or property if available, otherwise constructs metadata from object attributes and type information. Provides consistent metadata format across different object types.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj | Any | Object to extract metadata from | required |
Returns:
| Type | Description |
|---|---|
dict[str, Any] | Dictionary containing object metadata including type, class, module, and public attributes |