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)

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

License

MIT

Metadata

Release files for protoruf 0.2.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.2.0
File Size Uploaded Provenance Actions
protoruf-0.2.0.tar.gz 1.3 MB With provenance Details for protoruf-0.2.0.tar.gz

Built distributions (wheels)

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

Total release size: 13.6 MB

Release files / protoruf-0.2.0.tar.gz

Download URL protoruf-0.2.0.tar.gz
Size 1.3 MB
Tags Source
SHA-256 checksum
How to use checksums
392eb86122cc14a3141cfea7720226fc82afb377b9c32fbf26da17fb1e38d05c
BLAKE2b-256 checksum
How to use checksums
9fe2361486026b021ba4148ffcb07518f7f3bb6d2313198a62d451ad12ce0c02
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 21, 2026.

Transparency log

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

Download URL protoruf-0.2.0-cp314-cp314-win_amd64.whl
Size 1.0 MB
Tags CPython 3.14 Windows x86-64
SHA-256 checksum
How to use checksums
00129a05ade7b8bdf222f5c08572335f25decc1222263f6e99120d4c1f2bb77f
BLAKE2b-256 checksum
How to use checksums
04405cb40a47ae87e4dd9de06038400e93bf90b206f78c6bb22d041545cfd971
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 21, 2026.

Transparency log

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

Download URL protoruf-0.2.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
6550a5edc5faf6a6b238b6ea57ac1774e29d1b077b32fb0e4c13a98ba075011c
BLAKE2b-256 checksum
How to use checksums
8adcce406ccc8f4ee36b1d02fb014951123d58952e9367769dfc9ad950d27a33
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 21, 2026.

Transparency log

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

Download URL protoruf-0.2.0-cp314-cp314-macosx_11_0_arm64.whl
Size 972.1 kB
Tags CPython 3.14 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
ceb90dfebbe3a7c48182ce7d42701190a5e93f707f81e46538084b56f097059b
BLAKE2b-256 checksum
How to use checksums
0c61cae2d369919569ba7a9d54695e863f77ac561b217e88c921c935b680253b
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 21, 2026.

Transparency log

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

Download URL protoruf-0.2.0-cp314-cp314-macosx_10_12_x86_64.whl
Size 1.0 MB
Tags CPython 3.14 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
f1d7f7a9d593b214aa18f51f8bc4c6354db55c87ca5b5b184a8b9e37696c4124
BLAKE2b-256 checksum
How to use checksums
ef64785d512a6bd3335bccc6617d3c3b2d863899e83b3efdde19bd6ff2e79ca1
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 21, 2026.

Transparency log

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

Download URL protoruf-0.2.0-cp313-cp313-win_amd64.whl
Size 1.0 MB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
c9adbec7380b481a91a50a78475f2c0b84ac56d2c696a1ddb7f2f2e271fbd1fb
BLAKE2b-256 checksum
How to use checksums
4f6b36c35e42d443774b6e3f2ff580c020a42d32a13eed2e85493d5a949c5768
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 21, 2026.

Transparency log

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

Download URL protoruf-0.2.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
7d582ac9a8d23a9a7137ea386e7144a6f05367e77ea23bfa3be6957bfc7cd7d8
BLAKE2b-256 checksum
How to use checksums
ac8ed008f11df31c3fb2c814919c8058f2df7cc5539141fa82638eb8dd82e84b
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 21, 2026.

Transparency log

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

Download URL protoruf-0.2.0-cp313-cp313-macosx_11_0_arm64.whl
Size 972.1 kB
Tags CPython 3.13 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
c1b0edd8d48dbd81a1b565748959b21c741441e2cf9c59300e833f65794ad7f6
BLAKE2b-256 checksum
How to use checksums
507066dcbb2918f8578ebd47978c7856605125abbab3dd0c3a8c546a2032fdb9
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 21, 2026.

Transparency log

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

Download URL protoruf-0.2.0-cp313-cp313-macosx_10_12_x86_64.whl
Size 1.0 MB
Tags CPython 3.13 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
6803ee772243526c355aa9c7a489979222a87a975c6ce4d3311fec24eb6fca34
BLAKE2b-256 checksum
How to use checksums
08e01eaa33a35b9e9024891e7b2403933206b3d15637bae10bcf574e82902d73
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 21, 2026.

Transparency log

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

Download URL protoruf-0.2.0-cp312-cp312-win_amd64.whl
Size 1.1 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
7548f1cf2b5cfddce032ee11a711cf361b04698cd56f7b3151cad2913d7bf18c
BLAKE2b-256 checksum
How to use checksums
22f8869fb6ca9e73d86886b983e14256f6a41a494e8b551a61dce68ea6db63ce
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 21, 2026.

Transparency log

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

Download URL protoruf-0.2.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
db77f820f7729f3ab0a8acdf1452e7574229b5a93fea481d8849a1cd4233d287
BLAKE2b-256 checksum
How to use checksums
a82d11dc6a863bed4532b1a899ade44fa8e77a866a538452360b8d9d78c19682
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 21, 2026.

Transparency log

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

Download URL protoruf-0.2.0-cp312-cp312-macosx_11_0_arm64.whl
Size 972.4 kB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
f9fc22009a1b603ca6382a540b4e115739470c50a7bad4d3d37788474e40a8d6
BLAKE2b-256 checksum
How to use checksums
7ab3ef78de0b32129f15f3003445d39bdc33fe03991ae16a9d38637859207235
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 21, 2026.

Transparency log

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

Download URL protoruf-0.2.0-cp312-cp312-macosx_10_12_x86_64.whl
Size 1.0 MB
Tags CPython 3.12 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
f501de2e852f2d1563d358b285d322739edb0b11ef08c418d19a52fa3be5780c
BLAKE2b-256 checksum
How to use checksums
8232cda66cc8701bff95101fb7d727d8655ab48daa293b49b0c6c63805168d3f
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 21, 2026.

Transparency log

Security for protoruf 0.2.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.2.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 21, 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