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

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

Built distributions (wheels)

Table of built distributions (wheels) for protoruf 0.5.1
File Actions
protoruf-0.5.1-cp314-cp314-win_amd64.whl CPython 3.14 CPython 3.14 Windows x86-64 Details for protoruf-0.5.1-cp314-cp314-win_amd64.whl
protoruf-0.5.1-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.1-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
protoruf-0.5.1-cp314-cp314-macosx_11_0_arm64.whl CPython 3.14 CPython 3.14 macOS 11.0+ ARM64 Details for protoruf-0.5.1-cp314-cp314-macosx_11_0_arm64.whl
protoruf-0.5.1-cp314-cp314-macosx_10_12_x86_64.whl CPython 3.14 CPython 3.14 macOS 10.12+ x86-64 Details for protoruf-0.5.1-cp314-cp314-macosx_10_12_x86_64.whl
protoruf-0.5.1-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details for protoruf-0.5.1-cp313-cp313-win_amd64.whl
protoruf-0.5.1-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.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
protoruf-0.5.1-cp313-cp313-macosx_11_0_arm64.whl CPython 3.13 CPython 3.13 macOS 11.0+ ARM64 Details for protoruf-0.5.1-cp313-cp313-macosx_11_0_arm64.whl
protoruf-0.5.1-cp313-cp313-macosx_10_12_x86_64.whl CPython 3.13 CPython 3.13 macOS 10.12+ x86-64 Details for protoruf-0.5.1-cp313-cp313-macosx_10_12_x86_64.whl
protoruf-0.5.1-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details for protoruf-0.5.1-cp312-cp312-win_amd64.whl
protoruf-0.5.1-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.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
protoruf-0.5.1-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details for protoruf-0.5.1-cp312-cp312-macosx_11_0_arm64.whl
protoruf-0.5.1-cp312-cp312-macosx_10_12_x86_64.whl CPython 3.12 CPython 3.12 macOS 10.12+ x86-64 Details for protoruf-0.5.1-cp312-cp312-macosx_10_12_x86_64.whl

Total release size: 15.4 MB

Release files / protoruf-0.5.1.tar.gz

Download URL protoruf-0.5.1.tar.gz
Size 1.4 MB
Tags Source
SHA-256 checksum
How to use checksums
04dcdcc255a074a3479bafa45f91ed6cf859a4afe2212ce9178bbeeb46bef67b
BLAKE2b-256 checksum
How to use checksums
fc2a21b2ad03c72107b98295091a7246d5a68a1221cc551d673a105cd8d854c3
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.1-cp314-cp314-win_amd64.whl

Download URL protoruf-0.5.1-cp314-cp314-win_amd64.whl
Size 1.2 MB
Tags CPython 3.14 Windows x86-64
SHA-256 checksum
How to use checksums
cecd309d79641c2595f331cf90dde740405516df186fe0c10a46a67ab786e822
BLAKE2b-256 checksum
How to use checksums
3bca6c97bc94f0fb54bd7aaff0acb930d456ea894dfa0b66a262ff7d7ffdb3f5
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.1-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL protoruf-0.5.1-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
64a202bb9bfd71e5d4c7e938735f2c99e1c4e01c85d7cfe05fbdc42497dbbeb4
BLAKE2b-256 checksum
How to use checksums
5e13557b62767609efb25c1be7cac07a3c18bac91c59b430c8f1b5437a598c6d
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.1-cp314-cp314-macosx_11_0_arm64.whl

Download URL protoruf-0.5.1-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
395ed17b2c205f52e4eff3002cb07444eed7b716041e827138481e89f65e4e1b
BLAKE2b-256 checksum
How to use checksums
aa97e0d0707a07937e07f82772fbbd28b82c2b5a4d5d1171b7f6596b6aa87037
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.1-cp314-cp314-macosx_10_12_x86_64.whl

Download URL protoruf-0.5.1-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
039292485be264b131026503ccd6f8c9553cd0963466f50cab95b8e6565e998f
BLAKE2b-256 checksum
How to use checksums
9d9d5bc484f7c8b499438cfb5414ea6ea0d7bc58040b06012b603c991d72b877
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.1-cp313-cp313-win_amd64.whl

Download URL protoruf-0.5.1-cp313-cp313-win_amd64.whl
Size 1.2 MB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
b9bb7ef8006957c7c642adedb044150ae96aa79ffb8967aba38f303281e7ccc8
BLAKE2b-256 checksum
How to use checksums
986721853bde24c9a22023629d56c84a633c0d076ee2c363e66de2d38e673cd7
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.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL protoruf-0.5.1-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
c96cf1a76c7849d5e93d7a8dd3946cffa7cde600734897b93413f61c99c282c4
BLAKE2b-256 checksum
How to use checksums
0e32ec951ad28093fa0c940b53104cb1abc501c9debdf90dfab06353ddc22f31
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.1-cp313-cp313-macosx_11_0_arm64.whl

Download URL protoruf-0.5.1-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
d46fe8753df72074b4f390d0909b690c4ba5e08629224b8e9b08b96ad3f8610c
BLAKE2b-256 checksum
How to use checksums
42541b1ef5e04da51cb7b56bd7c2c7da50300839774393550e46371dab7c0e74
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.1-cp313-cp313-macosx_10_12_x86_64.whl

Download URL protoruf-0.5.1-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
ae0576311e8e0b06692eabb2ad0b5fa3e48f88ac0cb238c6d347cd7b0c9987d5
BLAKE2b-256 checksum
How to use checksums
89a27f9c2542b84274106b3626773083f19d3d600b0de6c2ce29b9ebd6a273e4
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.1-cp312-cp312-win_amd64.whl

Download URL protoruf-0.5.1-cp312-cp312-win_amd64.whl
Size 1.2 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
253ee67de9692509217611662efa6307f80da5517ad53e894233a7251cfe5731
BLAKE2b-256 checksum
How to use checksums
46fe5ba3ad3f540a2c1a4af0819911fc2f2636ab9fec1b40e62343d6b8d92fe5
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.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL protoruf-0.5.1-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
ee2de4b8bfecce81ce210fc815681136c9dd3a02d976344132f350f414c72734
BLAKE2b-256 checksum
How to use checksums
146278e76a302268dc7fcf2b64dc722042e44dd683f909aafa9bf1754b403d16
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.1-cp312-cp312-macosx_11_0_arm64.whl

Download URL protoruf-0.5.1-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
c86d9d931a951b6c451af442cf79349e93c3947c2bb1c18bceb85e8d6e92abb2
BLAKE2b-256 checksum
How to use checksums
7f481a94bb9db155befe03a41365bdbe79a0d8c252a60db85e67e80269c4bb40
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.1-cp312-cp312-macosx_10_12_x86_64.whl

Download URL protoruf-0.5.1-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
724b679f0f83e43592bd9539951e57f68223cbb0c8828799730b0a02bd27b840
BLAKE2b-256 checksum
How to use checksums
53e2b14a500715fb824b2113321c1b8b89f6fe8896b0378438f2fbacf69d25d6
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.1

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