Skip to content


Serialize nested dictionaries to bytes using google.protobuf.Struct.

Prerequisites: - All keys must be of type: str - Values must be of type: bool, int, float, str, bytes, dict - Strings must be unicode, as google.protobuf.Struct does not support bytes

The following encoding is required and performed, and sentinel values are added for decoding: - bytes to string - integer to string


def to_bytes(data: Dict[str, Any]) -> bytes

Serialize to bytes using protobuf. Adds extra data for type-casting.


def from_bytes(buffer: bytes) -> Dict[str, Any]

Deserialize patched-up python dict from protobuf bytes.


def patch(data: Dict[str, Any]) -> Dict[str, Any]

Patch for protobuf serialization. In-place operation.


def unpatch(data: Dict[str, Any]) -> Dict[str, Any]

Unpatch for protobuf deserialization. In-place operation.

DictProtobufStructSerializer Objects

class DictProtobufStructSerializer()

Class to keep backwards compatibility

Back to top