Skip to main content

protoruf

protoruf logo

High-performance JSON ↔ Protobuf conversion for Python, powered by Rust

📖 Documentation • 💻 Source • 🐛 Issues


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.


compile_proto_from_sources(files, root, include_imports=True, output_path=None)

Compile .proto sources held in memory, with no filesystem access. Useful when your schemas are generated at runtime, fetched over the network, or stored in a database. import statements are resolved by name against the files mapping, and Google well-known types are resolved automatically.

Parameter Type Description
files dict[str, str] Mapping of file name → .proto source text
root str Entry file to compile (must be a key of files)
include_imports bool Embed imported files in the descriptor (default True)
output_path str | None Optional path to save the descriptor

Returns: bytes — The compiled descriptor set.

from protoruf import compile_proto_from_sources

files = {
    "user.proto": """
syntax = "proto3";
package user;
message User { string id = 1; string email = 2; }
""",
}

descriptor = compile_proto_from_sources(files, root="user.proto")

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, include_default_values=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
include_default_values bool If True, emit fields without presence even at their default value

Returns: str — The JSON representation.


pydantic_to_protobuf(pydantic_model, descriptor_bytes, message_type)

Convert a Pydantic model directly to a Protobuf message.

Parameter Type Description
pydantic_model BaseModel Pydantic model instance 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_pydantic(protobuf_bytes, descriptor_bytes, model_class, message_type)

Convert a Protobuf message directly to a Pydantic model instance.

Parameter Type Description
protobuf_bytes bytes Protobuf message as bytes
descriptor_bytes bytes Compiled protobuf descriptor set
model_class Type[T] The Pydantic model class to instantiate
message_type str Full message type name (e.g. "message.Message")

Returns: T — An instance of the specified Pydantic model class.

Usage with Pydantic

protoruf provides built-in functions for seamless Pydantic integration:

from pydantic import BaseModel
from protoruf import compile_proto, pydantic_to_protobuf, protobuf_to_pydantic

class Message(BaseModel):
    id: str = ""
    content: str = ""
    priority: int = 0

descriptor = compile_proto("message.proto")
msg = Message(id="123", content="Hello", priority=1)

# Direct conversion from Pydantic to Protobuf
protobuf_bytes = pydantic_to_protobuf(msg, descriptor, message_type="message.Message")

# Direct conversion from Protobuf back to Pydantic
result = protobuf_to_pydantic(protobuf_bytes, descriptor, Message, message_type="message.Message")

License

MIT

Metadata

Release files for protoruf 0.5.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for protoruf 0.5.2
File Size Uploaded Provenance Actions
protoruf-0.5.2.tar.gz 1.4 MB With provenance Details for protoruf-0.5.2.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for protoruf 0.5.2
File Actions
protoruf-0.5.2-cp314-cp314-win_amd64.whl CPython 3.14 CPython 3.14 Windows x86-64 Details for protoruf-0.5.2-cp314-cp314-win_amd64.whl
protoruf-0.5.2-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.17+ x86-64 Details for protoruf-0.5.2-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
protoruf-0.5.2-cp314-cp314-macosx_11_0_arm64.whl CPython 3.14 CPython 3.14 macOS 11.0+ ARM64 Details for protoruf-0.5.2-cp314-cp314-macosx_11_0_arm64.whl
protoruf-0.5.2-cp314-cp314-macosx_10_12_x86_64.whl CPython 3.14 CPython 3.14 macOS 10.12+ x86-64 Details for protoruf-0.5.2-cp314-cp314-macosx_10_12_x86_64.whl
protoruf-0.5.2-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details for protoruf-0.5.2-cp313-cp313-win_amd64.whl
protoruf-0.5.2-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.17+ x86-64 Details for protoruf-0.5.2-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
protoruf-0.5.2-cp313-cp313-macosx_11_0_arm64.whl CPython 3.13 CPython 3.13 macOS 11.0+ ARM64 Details for protoruf-0.5.2-cp313-cp313-macosx_11_0_arm64.whl
protoruf-0.5.2-cp313-cp313-macosx_10_12_x86_64.whl CPython 3.13 CPython 3.13 macOS 10.12+ x86-64 Details for protoruf-0.5.2-cp313-cp313-macosx_10_12_x86_64.whl
protoruf-0.5.2-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details for protoruf-0.5.2-cp312-cp312-win_amd64.whl
protoruf-0.5.2-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ x86-64 Details for protoruf-0.5.2-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
protoruf-0.5.2-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details for protoruf-0.5.2-cp312-cp312-macosx_11_0_arm64.whl
protoruf-0.5.2-cp312-cp312-macosx_10_12_x86_64.whl CPython 3.12 CPython 3.12 macOS 10.12+ x86-64 Details for protoruf-0.5.2-cp312-cp312-macosx_10_12_x86_64.whl

Total release size: 15.4 MB

Release files / protoruf-0.5.2.tar.gz

Download URL protoruf-0.5.2.tar.gz
Size 1.4 MB
Tags Source
SHA-256 checksum
How to use checksums
569bf2317859ff780844ae87d63d2a9ce4eadd287567ae8cd800f7aeabd2c7bf
BLAKE2b-256 checksum
How to use checksums
068d5f55805e55e4dad3c7036b2da748819a0c2ce0b1eba40df4da4664fb4905
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 29, 2026.

Transparency log

Release files / protoruf-0.5.2-cp314-cp314-win_amd64.whl

Download URL protoruf-0.5.2-cp314-cp314-win_amd64.whl
Size 1.2 MB
Tags CPython 3.14 Windows x86-64
SHA-256 checksum
How to use checksums
4e5c9237ca39dbbfa4c7eff73b493bc23dbc962307a0c329cdc85c115218aae1
BLAKE2b-256 checksum
How to use checksums
fe29103c031882ef2d467340b26f73e78e459a293a217b6704aaa824573e5d0c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 29, 2026.

Transparency log

Release files / protoruf-0.5.2-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL protoruf-0.5.2-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 1.2 MB
Tags CPython 3.14 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
35ad818da967ee8223b023195a3b200e62b8711aa1c09e0701f685bc88080f1e
BLAKE2b-256 checksum
How to use checksums
8e2f994d23540250ca022f74a4fb52b6bd5c4da0bf7cb892aa89279856de70c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 29, 2026.

Transparency log

Release files / protoruf-0.5.2-cp314-cp314-macosx_11_0_arm64.whl

Download URL protoruf-0.5.2-cp314-cp314-macosx_11_0_arm64.whl
Size 1.1 MB
Tags CPython 3.14 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
b4264ab8d3681394a4f67b3721bdf7e688ae48bcf76ef224df22e6571753e88c
BLAKE2b-256 checksum
How to use checksums
c0b2333f5a46378478d5b137f6eeb329a7b853fc4e7e8c61b6989328522bd3ce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 29, 2026.

Transparency log

Release files / protoruf-0.5.2-cp314-cp314-macosx_10_12_x86_64.whl

Download URL protoruf-0.5.2-cp314-cp314-macosx_10_12_x86_64.whl
Size 1.2 MB
Tags CPython 3.14 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
fd1acc9ac4f4934e4eff82da5d73fbafd6ddb7b045d9d3ff5db084fb1402e85a
BLAKE2b-256 checksum
How to use checksums
1cbe6ec3950c6c08e89b65f7d212f1960972397f0c6c9acd0c493ff04cc8ac8d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 29, 2026.

Transparency log

Release files / protoruf-0.5.2-cp313-cp313-win_amd64.whl

Download URL protoruf-0.5.2-cp313-cp313-win_amd64.whl
Size 1.2 MB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
7995e5ff18fae7f80d8cce416dfbc6f2a66fffd16867b3335ac4af1f00c027bb
BLAKE2b-256 checksum
How to use checksums
c914e66e591fdbe5948cd9987b1420f60b197ad2281a6984f0a00654a42063b5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 29, 2026.

Transparency log

Release files / protoruf-0.5.2-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL protoruf-0.5.2-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 1.2 MB
Tags CPython 3.13 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
fb88bcccf206b7b6b6c9513ec7a2afbe09e9c0263c8e41ddfb8de218132bf236
BLAKE2b-256 checksum
How to use checksums
c44a7801ebbdda2f73f6f3a00dbac42c28101bc3cf121c7d90f9c082c1db43e6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 29, 2026.

Transparency log

Release files / protoruf-0.5.2-cp313-cp313-macosx_11_0_arm64.whl

Download URL protoruf-0.5.2-cp313-cp313-macosx_11_0_arm64.whl
Size 1.1 MB
Tags CPython 3.13 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
12f951e73b9e07c4bf654a3e2feca5eac1fe15a00d592ee29118ca893e1e3b6c
BLAKE2b-256 checksum
How to use checksums
bef3a5c18c8e477134c7f015daa28ccc6e86777839a48c12aaafd84d0a6c1b6d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 29, 2026.

Transparency log

Release files / protoruf-0.5.2-cp313-cp313-macosx_10_12_x86_64.whl

Download URL protoruf-0.5.2-cp313-cp313-macosx_10_12_x86_64.whl
Size 1.2 MB
Tags CPython 3.13 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
8467ce562d50fea6bbe4a81033d77d00c9d575aa4595f734a8911ffe7c9c8643
BLAKE2b-256 checksum
How to use checksums
2bb15e90afbde58667d5d6849a5ece8927a9222ce75402ebb7a4db216bce1039
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 29, 2026.

Transparency log

Release files / protoruf-0.5.2-cp312-cp312-win_amd64.whl

Download URL protoruf-0.5.2-cp312-cp312-win_amd64.whl
Size 1.2 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
ea720c255c3c2e4ea63a46ef1428eee25714c9ed5e03d7422e6463774c75470e
BLAKE2b-256 checksum
How to use checksums
e9193aaad96798894fc4cc302ffc4b5ab21c38cd54bb675bc38bc1802534a195
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 29, 2026.

Transparency log

Release files / protoruf-0.5.2-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL protoruf-0.5.2-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 1.2 MB
Tags CPython 3.12 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
7a7a2d349781ccd59c76f10ba6ff1430dcbecd2bfa3d7f48a70354ab060cfb02
BLAKE2b-256 checksum
How to use checksums
b69291bec5d6496259dde94339f249c500cc7769863ef6ca58c9c81b35f0f674
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 29, 2026.

Transparency log

Release files / protoruf-0.5.2-cp312-cp312-macosx_11_0_arm64.whl

Download URL protoruf-0.5.2-cp312-cp312-macosx_11_0_arm64.whl
Size 1.1 MB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
e46448755f48df98c9b91be2a1535f4702569e4517d121222231b0f9449168af
BLAKE2b-256 checksum
How to use checksums
22475305e3657e0fdde22c68e6b396943aa61eb85594be0238a8338e53b1bf04
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 29, 2026.

Transparency log

Release files / protoruf-0.5.2-cp312-cp312-macosx_10_12_x86_64.whl

Download URL protoruf-0.5.2-cp312-cp312-macosx_10_12_x86_64.whl
Size 1.2 MB
Tags CPython 3.12 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
b58ac5c80c065412b14fe1abe00f4e3504d9492f57b4e449b7d67f67942b941d
BLAKE2b-256 checksum
How to use checksums
967ae5c7534602ad17a82d0d6c4f05f809bc57eaeb416e4965cd6a6bfa8d0d62
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 29, 2026.

Transparency log

Security for protoruf 0.5.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 13 files in this release have been uploaded with provenance metadata.

Select from 13 files

Attestation for protoruf-0.5.2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 29, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page