packable
packable(cls)Decorator to convert a regular class into a PackableSample.
This decorator transforms a class into a dataclass that inherits from PackableSample, enabling automatic msgpack serialization/deserialization with special handling for NDArray fields.
The resulting class satisfies the Packable protocol, making it compatible with all atdata APIs that accept packable types (e.g., publish_schema, lens transformations, etc.).
Type Checking
The return type is annotated as type[PackableSample] so that IDEs and type checkers recognize the PackableSample methods (packed, as_wds, from_bytes, etc.). The @dataclass_transform() decorator ensures that field access from the original class is also preserved for type checking.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| cls | type[_T] | The class to convert. Should have type annotations for its fields. | required |
Returns
| Name | Type | Description |
|---|---|---|
| type[PackableSample] | A new dataclass that inherits from PackableSample with the same |
|
| type[PackableSample] | name and annotations as the original class. The class satisfies the | |
| type[PackableSample] | Packable protocol and can be used with Type[Packable] signatures. |
Examples
>>> @packable
... class MyData:
... name: str
... values: NDArray
...
>>> sample = MyData(name="test", values=np.array([1, 2, 3]))
>>> bytes_data = sample.packed
>>> restored = MyData.from_bytes(bytes_data)
>>>
>>> # Works with Packable-typed APIs
>>> index.publish_schema(MyData, version="1.0.0") # Type-safe