trulens.core.utils.serial¶
    Serialization utilities.
TODO: Lens class: can we store just the python AST instead of building up our own "Step" classes to hold the same data? We are already using AST for parsing.
Attributes¶
module-attribute
  
¶
    Tuple of JSON-able base types.
Can be used in isinstance checks.
module-attribute
  
¶
    Alias for JSON-able base types.
module-attribute
  
¶
    Alias for (non-strict) JSON-able data (Any = JSON).
If used with type argument, that argument indicates what the JSON represents and can be desererialized into.
Formal JSON must be a dict at the root but non-strict here means that the root
can be a basic type or a sequence as well.
module-attribute
  
¶
    Alias for (strictly) JSON-able data.
Python object that is directly mappable to JSON.
Classes¶
    JSON-encoded data the can be deserialized into a given type T.
This class is meant only for type annotations. Any
serialization/deserialization logic is handled by different classes, usually
subclasses of pydantic.BaseModel.
Functions¶
classmethod
  
¶
__get_pydantic_core_schema__(
    source_type: Any, handler: GetCoreSchemaHandler
) -> CoreSchema
Make pydantic treat this class same as a dict.
    
    
              Bases: StepItemOrAttribute
An attribute lookup step as in someobject.someattribute.
    
              Bases: StepItemOrAttribute
An item lookup step as in someobject["somestring"].
    
              Bases: StepItemOrAttribute
A step in a path lens that selects an item or an attribute.
Note
TruLens allows looking up elements within sequences if the subelements have the item or attribute. We issue warning if this is ambiguous (looking up in a sequence of more than 1 element).
    
    
              Bases: BaseModel, Sized, Hashable
Lenses into Python objects.
Example
path = Lens().record[5]['somekey']
obj = ... # some object that contains a value at `obj.record[5]['somekey]`
value_at_path = path.get(obj) # that value
new_obj = path.set(obj, 42) # updates the value to be 42 instead
collect and special attributes¶
Some attributes hold special meaning for lenses. Attempting to access them will produce a special lens instead of one that looks up that attribute.
Example
path = Lens().record[:]
obj = dict(record=[1, 2, 3])
value_at_path = path.get(obj) # generates 3 items: 1, 2, 3 (not a list)
path_collect = path.collect()
value_at_path = path_collect.get(obj) # generates a single item, [1, 2, 3] (a list)
Functions¶
    Get the Lens representing the longest prefix of the path that exists in the given object.
staticmethod
  
¶
    Convert a string representing a Python expression into a Lens.
    If obj at path self is None or does not exist, sets it to a list
containing only the given val. If it already exists as a sequence,
appends val to that sequence as a list. If it is set but not a sequence,
error is thrown.
    
Functions¶
    Determine if the given object is JSON-able, strictly.
Strict JSON starts as a dictionary at the root.
    Return the dict/model_dump of the given pydantic instance regardless of it being v2 or v1.
    Get all queries for the given object that select all of its leaf values.
    Get all queries for the given object.