Skip to content
Pyrula

Serde

The serde types encode and decode in Rust. serialize and deserialize return an Either, so a bad payload is an Err you handle, not an exception that escapes.

from pyrula import JsonSerde
serde = JsonSerde()
serde.serialize({"id": 1, "name": "alice"}) # Ok(b'{"id":1,...}')
serde.deserialize(b'{"id": 1}') # Ok({"id": 1})
serde.deserialize(b'not json') # Err(DeserializationError(...))

AvroSerde takes a schema as a JSON string and validates against it.

from pyrula import AvroSerde
serde = AvroSerde(schema_json=SCHEMA)
serde.serialize({"id": 1, "name": "alice"}) # Ok(bytes)

For throughput, the _many methods take an IList and encode in one Rust call instead of looping in Python. serialize_many gives back an IList of results; serialize_many_raw gives a packed BytesList.

from pyrula import IList
serde.serialize_many(IList([{"id": 1}, {"id": 2}]))

Everything raises through one hierarchy when you do unwrap it:

from pyrula import SerdeError, SerializationError, DeserializationError

SerializationError and DeserializationError both subclass SerdeError, so you can catch one or all three.

For Confluent Schema Registry framing (the [0x00][schema_id][payload] wire format), there are registry-aware serdes: AvroRegistrySerde, JsonSchemaRegistrySerde, and ProtobufRegistrySerde. They handle registration, schema-id lookup, and TLS/mTLS to the registry. Those live on the Kafka path. See Kafka.