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.3.0

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.3.0
File Size Uploaded Provenance Actions
protoruf-0.3.0.tar.gz 1.4 MB With provenance Details for protoruf-0.3.0.tar.gz

Built distributions (wheels)

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

Total release size: 14.6 MB

Release files / protoruf-0.3.0.tar.gz

Download URL protoruf-0.3.0.tar.gz
Size 1.4 MB
Tags Source
SHA-256 checksum
How to use checksums
b2a510f86153d3f202509d5b64bc644b41bba2a5d4064e856258eb5022971e20
BLAKE2b-256 checksum
How to use checksums
50329fff18d5f6f6b8964ba5774af474afbd2c9d7c1d2ed3bfd3fd8a09dda294
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 28, 2026.

Transparency log

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

Download URL protoruf-0.3.0-cp314-cp314-win_amd64.whl
Size 1.1 MB
Tags CPython 3.14 Windows x86-64
SHA-256 checksum
How to use checksums
aa1e81e5eeba8e0c9a67e119abba43709a461a5e9c9f43014418bc87cdf64d23
BLAKE2b-256 checksum
How to use checksums
5dbad5d11f7e787eb4fa184529759e12b6145a12d8c90a9a3f8167f2fa0fe008
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 28, 2026.

Transparency log

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

Download URL protoruf-0.3.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.1 MB
Tags CPython 3.14 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
8037b92a082e84315ec47f4dda9ebdaef087e65c767c92f0294bb659233fb46e
BLAKE2b-256 checksum
How to use checksums
cffbac5f809124757f57ce4b155c2bb46fb92aa66af6e59544b4ab42f0233d4b
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 28, 2026.

Transparency log

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

Download URL protoruf-0.3.0-cp314-cp314-macosx_11_0_arm64.whl
Size 1.0 MB
Tags CPython 3.14 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
ab7c22e1d0926f9d5d34bead878ed5e8852913e14dcbbef7e140f6ae55d87e45
BLAKE2b-256 checksum
How to use checksums
38c41f9adb2f93bc59c60ab6531d536c09dd2f18fda5c82fa76659f6b6696fde
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 28, 2026.

Transparency log

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

Download URL protoruf-0.3.0-cp314-cp314-macosx_10_12_x86_64.whl
Size 1.1 MB
Tags CPython 3.14 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
cc363dd46a5d46518646cf9524921097c0f4bce640f421d3349f2dbd17dec3ad
BLAKE2b-256 checksum
How to use checksums
c391034c01b92cb0b1357e95fd94547b7e620a2555045d6b0122105434ab9edd
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 28, 2026.

Transparency log

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

Download URL protoruf-0.3.0-cp313-cp313-win_amd64.whl
Size 1.1 MB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
d2c88c46d2a84abd8b0b9c5b255c65c61cd38e5825e957bb269059a0e9706ba6
BLAKE2b-256 checksum
How to use checksums
c9309f604e1a72706c3cd10481d5e149bc4925769b7f817b8edf4e049e0effb7
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 28, 2026.

Transparency log

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

Download URL protoruf-0.3.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.1 MB
Tags CPython 3.13 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
24112b5326d8865f4b38c86d90230e97576ebf58484f467458f6fde10103ea61
BLAKE2b-256 checksum
How to use checksums
a33151840f431ada602f5d3caa9abb7054591841115068ba848fd71faf8d546f
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 28, 2026.

Transparency log

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

Download URL protoruf-0.3.0-cp313-cp313-macosx_11_0_arm64.whl
Size 1.0 MB
Tags CPython 3.13 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
2f58c42c5ac6c44181cfd1038c331e1cd6d958288494fa00e566a173b83757b6
BLAKE2b-256 checksum
How to use checksums
2f642d92b26f446db06e231c328744f9c01fa9d212acdf9fd516d7926b0c42de
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 28, 2026.

Transparency log

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

Download URL protoruf-0.3.0-cp313-cp313-macosx_10_12_x86_64.whl
Size 1.1 MB
Tags CPython 3.13 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
ef1e2c1bb530a90b915f6473605d9b52f5d6c08de49e2faff54ce124aa214f72
BLAKE2b-256 checksum
How to use checksums
91a769e6bd1fb04ddadc4ee5242fc7bb46f1e84119872b2f7893dc2c692e8994
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 28, 2026.

Transparency log

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

Download URL protoruf-0.3.0-cp312-cp312-win_amd64.whl
Size 1.1 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
ebe0df26daf4e62536e31d3390e11c1a443e5eeab9023bec440bd04bf3032956
BLAKE2b-256 checksum
How to use checksums
71eaa091f11755b8014db4197378a884a7f1864c3f92351d9d3165a98508f441
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 28, 2026.

Transparency log

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

Download URL protoruf-0.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.1 MB
Tags CPython 3.12 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
5f34f57c54dfcdb181c6ac4bdc16350591beeb60cf9aef956a09a49c4d7036bf
BLAKE2b-256 checksum
How to use checksums
49a33ef4cb6cc1968b6ef4929233786e1f09a3787cb48cbdbb9b1bb64b0940cb
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 28, 2026.

Transparency log

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

Download URL protoruf-0.3.0-cp312-cp312-macosx_11_0_arm64.whl
Size 1.0 MB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
97380ab3a2682d739937412a0df20c3664a18d9abd79a90099fb187b9284de73
BLAKE2b-256 checksum
How to use checksums
06f302cfd1c8fc0780b4444e003ff9d65cf2ae8404b7f64aa779d1995a0c28a3
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 28, 2026.

Transparency log

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

Download URL protoruf-0.3.0-cp312-cp312-macosx_10_12_x86_64.whl
Size 1.1 MB
Tags CPython 3.12 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
6aa2d079a1251cfdd63c217014a22e13aabb22b27e6f2e5db2028fc92644fc8d
BLAKE2b-256 checksum
How to use checksums
ea4085de80a0eb7af50fc279e3598e652da75289867a629b27fc4f882d2fe888
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 28, 2026.

Transparency log

Security for protoruf 0.3.0

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.3.0.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 28, 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