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

Built distributions (wheels)

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

Total release size: 15.3 MB

Release files / protoruf-0.4.0.tar.gz

Download URL protoruf-0.4.0.tar.gz
Size 1.4 MB
Tags Source
SHA-256 checksum
How to use checksums
493449a5bdc33102b3704266ed4b6a35fa918dbb354374f4c186b5cfd623dbb8
BLAKE2b-256 checksum
How to use checksums
22073ecb6fbef00a123d062fa68bb6a77fff1c8669a1c0dac6b5bf002988811d
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.4.0-cp314-cp314-win_amd64.whl

Download URL protoruf-0.4.0-cp314-cp314-win_amd64.whl
Size 1.2 MB
Tags CPython 3.14 Windows x86-64
SHA-256 checksum
How to use checksums
fd3b58dc380cf8718cf1a07439a3ad1c6225298f4b5be4e039161032ee2d8145
BLAKE2b-256 checksum
How to use checksums
196f2b168ad2670cc9eb50eb3bc5919c7146fad5566a7754a33ecc6d1c4272cb
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.4.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL protoruf-0.4.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.2 MB
Tags CPython 3.14 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
84a58047d871b423bb4c4081e838c1232fa2e146fa4f4f8c1a6320069ba2cf92
BLAKE2b-256 checksum
How to use checksums
906eb6071fa726fedbec78f2554dc457809b44799a17c6f741f5d789e8a0f604
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.4.0-cp314-cp314-macosx_11_0_arm64.whl

Download URL protoruf-0.4.0-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
41cfa737999865965e61f438695455585b8a60b893dcdd57e22bd6556a6a61ad
BLAKE2b-256 checksum
How to use checksums
1f9a7e370a9cea8662dead80f04a816d7f0216ae6f8b3144b401ec71d06000ca
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.4.0-cp314-cp314-macosx_10_12_x86_64.whl

Download URL protoruf-0.4.0-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
7fdd3122cd2e99c2f6d8d80f7324a3e843c39e76eff42ef8439c72a78a1605b6
BLAKE2b-256 checksum
How to use checksums
712507d0b10a1d61f4d9528c80ba4462e82775ad6cbfa224b2997cc8ae754720
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.4.0-cp313-cp313-win_amd64.whl

Download URL protoruf-0.4.0-cp313-cp313-win_amd64.whl
Size 1.2 MB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
e158b902d751db421c94bc2131f20dfb98a6fd2c8f671d4049651d79f9640ac5
BLAKE2b-256 checksum
How to use checksums
4a91030bda5cd23723da53db58f6da2a217c7b7a83b7688ae2481fc00409be2b
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.4.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL protoruf-0.4.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.2 MB
Tags CPython 3.13 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
9ca76d52f3136a298c89dcfdb91cedb7d3f6e29d8865b9d4ba788dd55bd1ec61
BLAKE2b-256 checksum
How to use checksums
74b771fcb40e2efd9c5e4539ceb23b867f5d1f87dbf27d520efdb5d0d978d159
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.4.0-cp313-cp313-macosx_11_0_arm64.whl

Download URL protoruf-0.4.0-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
2cd5daf9724e3694eba46f665451bb4afabede4d97c9d468e1d90df5768631ab
BLAKE2b-256 checksum
How to use checksums
adcda63c450062ed16e5edb0e7ba0701607ad99227e2e75a5f7e77a7c9602c9e
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.4.0-cp313-cp313-macosx_10_12_x86_64.whl

Download URL protoruf-0.4.0-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
222f4138566da3702b6128b77b4527e374d708d81880b37e576b824ee29fcc93
BLAKE2b-256 checksum
How to use checksums
2d1fe810618e776202e58740171d374420fc4bfdfa86754550368bfee593829a
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.4.0-cp312-cp312-win_amd64.whl

Download URL protoruf-0.4.0-cp312-cp312-win_amd64.whl
Size 1.2 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
191096f6c6d7eeb2f2370b19ed62ca64418de1f7a8b0625e2d478c824a50d376
BLAKE2b-256 checksum
How to use checksums
ac004d7468df005b5af52713b99d8eae0b5d22473812af11c2b1f94349d1fa2f
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.4.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL protoruf-0.4.0-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
99b34c35f3d086f8100f6516612736d54782fc93e90d052f82b0fb0f9a54146d
BLAKE2b-256 checksum
How to use checksums
060eb46083176d7daba846ced6f51d03bccb142134fc332fc2b12ba2c0960737
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.4.0-cp312-cp312-macosx_11_0_arm64.whl

Download URL protoruf-0.4.0-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
b308000b51ba7a50f3431701bc1671302a549aa10447aa7adb3e8603944b447a
BLAKE2b-256 checksum
How to use checksums
cc28b918841744a078619ff4464c819ae6b4ba76904a1dfbf9253dca5ef2856e
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.4.0-cp312-cp312-macosx_10_12_x86_64.whl

Download URL protoruf-0.4.0-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
3588a9b55b87041b9fcc76b8f0841a834a9b35dd92b7482d5f7cad45c0989468
BLAKE2b-256 checksum
How to use checksums
65ce9f205e41dc769934834d7793d40bda5702917fc358d7fdb8581628dd03dc
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.4.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.4.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 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