A Python library written in Rust for JSON/Protobuf conversion
Project description
protoruf
A high-performance Python library written in Rust for converting between JSON and Protobuf messages.
Features
- ⚡ Fast — JSON ↔ Protobuf conversion powered by Rust
- 🔒 Type-safe — Explicit message type specification
- 📦 Built-in proto compilation — Uses Rust protox, no external dependencies
Installation
pip install protoruf
Quick Start
from protoruf import json_to_protobuf, protobuf_to_json, compile_proto
# 1. Compile your .proto file
descriptor = compile_proto("message.proto")
# 2. Convert JSON to Protobuf
json_data = '{"id": "123", "content": "Hello", "priority": 1}'
protobuf_bytes = json_to_protobuf(json_data, descriptor, message_type="message.Message")
# 3. Convert Protobuf back to JSON
json_str = protobuf_to_json(protobuf_bytes, descriptor, message_type="message.Message", pretty=True)
print(json_str)
API Reference
compile_proto(proto_path, include_paths=None, output_path=None)
Compile a .proto file to a descriptor set.
| Parameter | Type | Description |
|---|---|---|
proto_path |
str |
Path to the .proto file |
include_paths |
list[str] | None |
Optional include paths for imports |
output_path |
str | None |
Optional path to save the descriptor |
Returns: bytes — The compiled descriptor set.
load_descriptor(descriptor_path)
Load a pre-compiled descriptor set from a file.
| Parameter | Type | Description |
|---|---|---|
descriptor_path |
str |
Path to the .desc file |
Returns: bytes — The descriptor set.
json_to_protobuf(json_str, descriptor_bytes, message_type)
Convert a JSON string to a Protobuf message.
| Parameter | Type | Description |
|---|---|---|
json_str |
str |
JSON string to convert |
descriptor_bytes |
bytes |
Compiled protobuf descriptor set |
message_type |
str |
Full message type name (e.g. "message.Message") |
Returns: bytes — The Protobuf message.
protobuf_to_json(protobuf_bytes, descriptor_bytes, message_type, pretty=False)
Convert a Protobuf message to a JSON string.
| Parameter | Type | Description |
|---|---|---|
protobuf_bytes |
bytes |
Protobuf message as bytes |
descriptor_bytes |
bytes |
Compiled protobuf descriptor set |
message_type |
str |
Full message type name (e.g. "message.Message") |
pretty |
bool |
If True, format JSON with indentation |
Returns: str — The JSON representation.
Usage with Pydantic
from pydantic import BaseModel
from protoruf import compile_proto, json_to_protobuf, protobuf_to_json
class Message(BaseModel):
id: str = ""
content: str = ""
priority: int = 0
descriptor = compile_proto("message.proto")
msg = Message(id="123", content="Hello", priority=1)
protobuf_bytes = json_to_protobuf(msg.model_dump_json(), descriptor, message_type="message.Message")
result = protobuf_to_json(protobuf_bytes, descriptor, message_type="message.Message")
Links
- Documentation: https://github.com/EdwinAlkins/protoruf/blob/main/doc/index.md
- Source Code: https://github.com/EdwinAlkins/protoruf
- Bug Reports: https://github.com/EdwinAlkins/protoruf/issues
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file protoruf-0.1.1.tar.gz.
File metadata
- Download URL: protoruf-0.1.1.tar.gz
- Upload date:
- Size: 37.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8f83eafe34bf84c23fde6beae4f38a672ee0a6e7ba5717474cca733b5d1d6f7d
|
|
| MD5 |
155fa748bb7142e1a974609550c8f97c
|
|
| BLAKE2b-256 |
082eab676d9dd023e9113ad3e402656331059350445ed13ba0b34ed7d8d51dd0
|
Provenance
The following attestation bundles were made for protoruf-0.1.1.tar.gz:
Publisher:
publish-pypi.yml on EdwinAlkins/protoruf
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
protoruf-0.1.1.tar.gz -
Subject digest:
8f83eafe34bf84c23fde6beae4f38a672ee0a6e7ba5717474cca733b5d1d6f7d - Sigstore transparency entry: 1258771602
- Sigstore integration time:
-
Permalink:
EdwinAlkins/protoruf@1b86f24fb963fb861ddc70552737227d476d8644 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/EdwinAlkins
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@1b86f24fb963fb861ddc70552737227d476d8644 -
Trigger Event:
release
-
Statement type:
File details
Details for the file protoruf-0.1.1-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: protoruf-0.1.1-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 861.5 kB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cea1b627cdda8eeb110d8f2ad4abe567239c8c4d03dd9f0bccb616c17e2f072f
|
|
| MD5 |
042b7c9608d7e0db08f68c2872c5b175
|
|
| BLAKE2b-256 |
2c1e559bce8b4b043163ec1aa2001e247bda3ff12d9504458dcf439376196190
|
Provenance
The following attestation bundles were made for protoruf-0.1.1-cp312-cp312-win_amd64.whl:
Publisher:
publish-pypi.yml on EdwinAlkins/protoruf
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
protoruf-0.1.1-cp312-cp312-win_amd64.whl -
Subject digest:
cea1b627cdda8eeb110d8f2ad4abe567239c8c4d03dd9f0bccb616c17e2f072f - Sigstore transparency entry: 1258771716
- Sigstore integration time:
-
Permalink:
EdwinAlkins/protoruf@1b86f24fb963fb861ddc70552737227d476d8644 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/EdwinAlkins
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@1b86f24fb963fb861ddc70552737227d476d8644 -
Trigger Event:
release
-
Statement type:
File details
Details for the file protoruf-0.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: protoruf-0.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 1.1 MB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
98993f3dfa321d824f514da4dfed63b92e736f03a675b1511e052e9fa0116e60
|
|
| MD5 |
50fbbf4642ee09109fb3860e74d55acf
|
|
| BLAKE2b-256 |
4a19b9380422dccf5cd43032b00d60e358347b4976dcf8a52506b5e74b043bef
|
Provenance
The following attestation bundles were made for protoruf-0.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
publish-pypi.yml on EdwinAlkins/protoruf
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
protoruf-0.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
98993f3dfa321d824f514da4dfed63b92e736f03a675b1511e052e9fa0116e60 - Sigstore transparency entry: 1258771928
- Sigstore integration time:
-
Permalink:
EdwinAlkins/protoruf@1b86f24fb963fb861ddc70552737227d476d8644 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/EdwinAlkins
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@1b86f24fb963fb861ddc70552737227d476d8644 -
Trigger Event:
release
-
Statement type:
File details
Details for the file protoruf-0.1.1-cp312-cp312-macosx_11_0_arm64.whl.
File metadata
- Download URL: protoruf-0.1.1-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 956.3 kB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3935a54b1d1f9d18f8929f51a2f767d61a26cd517d43f1a7388efa4a44a65de6
|
|
| MD5 |
2ff665c0f07d203c3f4898357a8788d7
|
|
| BLAKE2b-256 |
dd4f508a9d962fa3a183dcfe8d4338e0c74356bba97662538b3a31d4afdc44c0
|
Provenance
The following attestation bundles were made for protoruf-0.1.1-cp312-cp312-macosx_11_0_arm64.whl:
Publisher:
publish-pypi.yml on EdwinAlkins/protoruf
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
protoruf-0.1.1-cp312-cp312-macosx_11_0_arm64.whl -
Subject digest:
3935a54b1d1f9d18f8929f51a2f767d61a26cd517d43f1a7388efa4a44a65de6 - Sigstore transparency entry: 1258771831
- Sigstore integration time:
-
Permalink:
EdwinAlkins/protoruf@1b86f24fb963fb861ddc70552737227d476d8644 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/EdwinAlkins
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@1b86f24fb963fb861ddc70552737227d476d8644 -
Trigger Event:
release
-
Statement type: