Install & Compatibility
Where this runs
tested against v0.1.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
build_error
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 1.6s · import 0.000s · 22MB
20MB installed
● package 20MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
betterproto_rust_codec
✓ import betterproto_rust_codec
✗ from betterproto_rust_codec import ProtobufCodec
deserialize
✓ from betterproto_rust_codec import deserialize
serialize
✓ from betterproto_rust_codec import serialize
This quickstart demonstrates how to define a `betterproto` message, instantiate the `ProtobufCodec`, and then use it to efficiently encode and decode the message to and from Protobuf wire format bytes.
import betterproto
from betterproto.lib.google.protobuf import Timestamp
from betterproto_rust_codec import ProtobufCodec
import datetime
@betterproto.dataclass
class MyMessage(betterproto.Message):
name: str = betterproto.string_field(1)
value: int = betterproto.int32_field(2)
timestamp: Timestamp = betterproto.message_field(3, wraps=True)
# Create an instance of the codec
codec = ProtobufCodec()
# Create a betterproto message
now_timestamp = Timestamp().from_datetime(datetime.datetime.now(datetime.timezone.utc))
original_message = MyMessage(
name="Test Name",
value=123,
timestamp=now_timestamp
)
print(f"Original message: {original_message}")
# Encode the message
encoded_bytes = codec.encode(original_message)
print(f"Encoded bytes length: {len(encoded_bytes)}")
# Decode the message
decoded_message = codec.decode(MyMessage, encoded_bytes)
# Verify
print(f"Decoded message: {decoded_message}")
assert original_message.name == decoded_message.name
assert original_message.value == decoded_message.value
assert original_message.timestamp.seconds == decoded_message.timestamp.seconds
print("\nEncode/Decode successful!")
Debug
Known issues
breakingThis library has strict dependency requirements for `betterproto`. Ensure your `betterproto` version meets the minimum requirement specified by `betterproto-rust-codec` (currently `>=2.0.0b6`). Using incompatible versions can lead to runtime errors or incorrect serialization.fixUpgrade `betterproto` to the required version: `pip install betterproto>="2.0.0b6"` or check the `pyproject.toml` of `betterproto-rust-codec` for the exact requirement.
affects: <0.1.1 (and potentially future versions)
breakingSimilarly, `betterproto-rust-codec` also has a minimum requirement for the `protobuf` library itself (currently `>=3.20.0`). Incompatible `protobuf` versions might cause issues with underlying type conversions or wire format interpretation.fixUpgrade `protobuf` to the required version: `pip install protobuf>="3.20.0"` or check the `pyproject.toml` of `betterproto-rust-codec` for the exact requirement.
affects: <0.1.1 (and potentially future versions)
gotchaThis codec is designed exclusively for `betterproto` messages. It will not work directly with messages generated by `protoc` or other standard `protobuf` Python libraries without first converting them to `betterproto` types.fixEnsure you are using `betterproto.Message` subclasses. If working with non-betterproto messages, use the standard `protobuf` library's encoding/decoding or convert messages to `betterproto` format first.
affects: All versions
gotchaWhile providing significant performance benefits, `betterproto-rust-codec` introduces a Rust dependency (compiled into a wheel). For extremely simple use cases or environments where Rust compilation might be an issue (e.g., highly restricted embedded systems, though pre-built wheels usually mitigate this), the overhead might not be justified if performance isn't a critical concern.fixEvaluate your performance needs. If speed is paramount for Protobuf serialization/deserialization, this library is highly recommended. Otherwise, Python-native `betterproto` encoding/decoding might suffice.
affects: All versions
Upgrade
Version history
0.1.1latest on PyPI · released Apr 13, 2024
Audit
Dependencies
betterprotorequiredRequired for defining Protobuf messages and base functionality. This codec specifically operates on betterproto message types.
protobufrequiredDirect dependency, required for underlying Protobuf type handling.