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.


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.


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")

Links

License

MIT

Metadata

Release files for protoruf 0.1.5

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.1.5
File Size Uploaded
protoruf-0.1.5.tar.gz 641.0 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for protoruf 0.1.5
File Interpreter ABI Platform
protoruf-0.1.5-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details
protoruf-0.1.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ x86-64 Details
protoruf-0.1.5-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details

Total release size: 4.1 MB

Release files / protoruf-0.1.5.tar.gz

Download URL protoruf-0.1.5.tar.gz
Size 641.0 kB
Tags Source
SHA-256 checksum
How to use checksums
21384b8a34c0fc422e050251adfb161e0d2a64428e59b95cc19c44da04f64bd2
BLAKE2b-256 checksum
How to use checksums
6ae7f477878d21659eb3bb061ea9fcdfeb5c809f18320197ab61684a7670a128
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jun 18, 2026.

Transparency log

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

Download URL protoruf-0.1.5-cp312-cp312-win_amd64.whl
Size 1.0 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
fb4d0f1f13cda18d057c715825db7da757abf53d0af71923fe66cc877d31d1d8
BLAKE2b-256 checksum
How to use checksums
bf64e68b42918c640ac9a846653feaf6a719968a3be196d6c8a69ef7f47f898f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jun 18, 2026.

Transparency log

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

Download URL protoruf-0.1.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.2 MB
Tags CPython 3.12 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
1b29e0b160b9f6c4f4bf20af43b11ad0fe4cd192ad38ccdbbcba387f57e29206
BLAKE2b-256 checksum
How to use checksums
dbb9df676b3bf7aa94e5a35757ab91663d8cc1ae3258f86e8ee38261370777fd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jun 18, 2026.

Transparency log

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

Download URL protoruf-0.1.5-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
7221dc96139fec6026f6cb2039af20c38ba4f20e8d2c6ffb1b67a20552cbba27
BLAKE2b-256 checksum
How to use checksums
3bcbeac565a06bf9a0488a6b08d97a6b4c56044f95e5e881433515041ffea76a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jun 18, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.5 This release

4 release files

0.1.4

4 release files

0.1.3

4 release files

0.1.2

4 release files

0.1.1

4 release files

0.1.0

4 release files

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