YTsaurus YSON
YTsaurus YSON (version 0.4.10) provides high-performance C++ bindings for YSON (Yandex Serialization Object Notation), enabling fast serialization and deserialization of YSON data. It is a sub-package of the larger `ytsaurus-python` project, specifically focused on YSON processing. Releases are tied to the `ytsaurus-python` project, with regular updates that reflect changes in the broader YTsaurus ecosystem.
Warnings
- breaking The `ytsaurus-yson` package was refactored out of the main `ytsaurus-python` library and the legacy `yt` library. It is now a standalone installable package.
- gotcha `ytsaurus-yson` functions `loads` and `dumps` primarily operate on `bytes` objects, not Python `str` objects, reflecting YSON's binary nature. Passing strings without encoding or expecting string output can lead to `TypeError` or incorrect deserialization.
- gotcha Installation of `ytsaurus-yson` requires a C++ compiler and associated build tools on the system, as it provides C++ bindings. This can be a common point of failure on environments without development dependencies.
- gotcha YSON has specific types (e.g., `entity`, `uint64`, `null`) and attributes which do not have direct, idiomatic Python equivalents. These are mapped to special `YsonType` objects (e.g., `YsonEntity`, `YsonUint64`) or accessed via `.attributes` on `YsonType` instances, which may require explicit handling.
Install
-
pip install ytsaurus-yson
Imports
- loads
from ytsaurus_yson import loads
- dumps
from ytsaurus_yson import dumps
- YsonType
from ytsaurus_yson import YsonType
Quickstart
from ytsaurus_yson import loads, dumps
# Deserialize YSON bytes to Python object
y_string_bytes = b'{key="value";number=123;list=[a;b;c;];}'
data = loads(y_string_bytes)
print(f"Deserialized: {data} (Type: {type(data)})\n")
# Serialize Python object to YSON bytes
python_object = {'name': 'Alice', 'age': 30, 'hobbies': ['reading', 'coding']}
yson_bytes = dumps(python_object)
print(f"Serialized: {yson_bytes} (Type: {type(yson_bytes)})\n")
# Demonstrate basic usage with YSON attributes (advanced)
yson_with_attrs = b'<"version"="1.0">{data="payload"}'
loaded_with_attrs = loads(yson_with_attrs)
print(f"Data with attributes: {loaded_with_attrs.value}, Attributes: {loaded_with_attrs.attributes}")