Python quickstart
Install the wheel (or run pixi run python-build in a source checkout):
python -m pip install predsync
The wheel does not bundle schema files. Copy a .yaml schema into your project
and load it from a path. The example below assumes a source checkout and is run
from the repository root; it uses the same four-field demo schema as the
generated Telemetry class.
from pathlib import Path
import predsync
from predsync.generated import Telemetry, TelemetryMode
schema_yaml = Path("examples/generated_example/schema/telemetry.yaml").read_text()
sample = Telemetry(
x=1.25,
mode=TelemetryMode.Active,
label="nominal",
samples=[7, 8, 9],
)
encoder = predsync.Encoder(schema_yaml, message=Telemetry.message_index, tick_ns=1_000_000)
decoder = predsync.Decoder(schema_yaml, message=Telemetry.message_index, resync_n=1)
for tick in range(3):
frame, _info = encoder.encode(sample.to_values(), tick * 1_000_000)
decoded = decoder.feed(frame)
assert Telemetry.from_values(decoded.values()) == sample
encode accepts either a field-name dictionary or a schema-order list. Decode
returns native Python values plus validity metadata in decoded.fields; enums
are represented by variant names.
Generated classes
Telemetry in the example above is a generated class from predsync.generated.
It exposes to_values() and from_values(), and carries schema_yaml,
message_index and field_names so engines can be created without a second
schema copy. TelemetryMode is the generated enum; its members are the schema
variant names.
See Python API and the ROS 2 example.