Skip to main content

Protosaurus

Protosaurus

Parse and create Protobuf messages at runtime in Python — no protoc required. Also includes a CLI to deserialize Protobuf from Kafka using kcat and a schema registry.

CI Wheels PyPI Python License

Installation

Requires Python >= 3.12.

uv add protosaurus

Or using pip:

pip install protosaurus

Usage

Parse and serialize Protobuf in Python

Protosaurus can parse .proto definitions at runtime without using protoc. This allows Protobuf byte arrays to be converted to JSON and vice versa. The Context object is thread-safe and can be shared across threads.

import json
from protosaurus import Context
from base64 import b64decode

# create a context which stores the proto schemas
ctx = Context()

# add protos by specifying name and content
ctx.add_proto('diet.proto',
    """
    syntax = "proto3";
    enum Diet {
        carnivorous = 0;
        herbivorous = 1;
    }
    """)

# the proto can be imported via the specified name
ctx.add_proto('animal.proto',
    """
    syntax = "proto3";
    import "diet.proto";
    message Animal {
        string name = 1;
        Diet diet = 2;
        double length = 3;
    }
    """)

# convert a message from base64 string...
data = ctx.to_json('Animal', b64decode('CglJZ3Vhbm9kb24QARkAAAAAAAAkQA=='))

# ...or hex string
data = ctx.to_json('Animal', bytes.fromhex('0a09496775616e6f646f6e1001190000000000002440'))

print(data)
# >>> '{"name":"Iguanodon","diet":"herbivorous","length":10}'


# fields left at their default are omitted...
data = ctx.to_json('Animal', b64decode('CglJZ3Vhbm9kb24='))

print(data)
# >>> '{"name":"Iguanodon"}'

# ...unless they are requested explicitly
data = ctx.to_json('Animal', b64decode('CglJZ3Vhbm9kb24='), include_defaults=True)

print(data)
# >>> '{"name":"Iguanodon","diet":"carnivorous","length":0}'


# convert json to protobuf
data = ctx.from_json('Animal', json.dumps({"name":"Iguanodon","diet":"herbivorous","length":10}))

print(data)
# >>> b'\n\tIguanodon\x10\x01\x19\x00\x00\x00\x00\x00\x00$@'

to_json accepts the following keyword-only options, all False by default:

Option Effect
include_defaults Print fields that do not track presence even when they hold their default: implicit-presence scalars, empty lists and empty maps. Fields with explicit presence (proto3 optional, submessages, oneof members) stay omitted when unset.
pretty Indent and line-break the output instead of emitting a single line.
proto_field_names Keep the field names as written in the .proto instead of lowerCamelCase.
enums_as_ints Print enum values as numbers instead of their names.
unquote_int64 Print 64-bit integers unquoted when the value round-trips through a double. Values that would lose precision stay quoted, so the JSON type of a field depends on its value.

from_json accepts one keyword-only option:

Option Effect
ignore_unknown_fields Accept JSON fields the schema does not define instead of failing. Useful when a producer has already moved to a newer schema than the one at hand.
# fails: the schema has no such field
ctx.from_json('Animal', '{"name":"Iguanodon","colour":"green"}')

# succeeds, the unknown field is dropped
ctx.from_json('Animal', '{"name":"Iguanodon","colour":"green"}', ignore_unknown_fields=True)

Read varints from the wire format

read_varint decodes a single base-128 varint out of a bytes object and returns the value together with the position just after it, so consecutive reads need no state of their own:

from protosaurus import read_varint

data = b'\xac\x02\x08'

value, offset = read_varint(data)          # (300, 2)
value, offset = read_varint(data, offset)  # (8, 3)

Pass zigzag=True for the sint32/sint64 encoding, which maps signed values onto unsigned ones. Field tags, lengths, int32, int64, uint64, bool and enums are not zigzag encoded, so the default is off:

read_varint(b'\xac\x02')                # (300, 2)
read_varint(b'\xac\x02', zigzag=True)   # (150, 2)

Malformed input is rejected rather than read on indefinitely: data ending mid-varint raises EOFError, more than ten bytes raises RuntimeError, and an offset past the end raises IndexError.

Deserialize Protobuf from Kafka using a schema registry

Protosaurus also ships a CLI that can deserialize Protobuf messages from Kafka automatically when a schema registry is available:

kcat -C -e -F <kafka.config> -t <topic> -f "%o\\n%k\\n%R%s" | protosaurus - --schema-registry <url>

To disable SSL certificate verification (e.g. for self-signed certificates), pass --no-verify:

kcat -C -e -F <kafka.config> -t <topic> -f "%o\\n%k\\n%R%s" | protosaurus - --schema-registry <url> --no-verify

The JSON output options above are available as flags: --defaults, --pretty, --proto-field-names, --enums-as-ints and --unquote-int64.

kcat -C -e -F <kafka.config> -t <topic> -f "%o\\n%k\\n%R%s" | protosaurus - --schema-registry <url> --defaults --pretty

Using uvx (no installation required):

kcat -C -e -F <kafka.config> -t <topic> -f "%o\\n%k\\n%R%s" | uvx protosaurus - --schema-registry <url>

License

ISC License — see LICENSE for details.

Release files for protosaurus 0.7.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 protosaurus 0.7.0
File Size Uploaded
protosaurus-0.7.0.tar.gz 204.2 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for protosaurus 0.7.0
File
protosaurus-0.7.0-cp312-abi3-win_amd64.whl CPython 3.12 abi3 Windows x86-64 Details
protosaurus-0.7.0-cp312-abi3-win32.whl CPython 3.12 abi3 Windows x86-32 Details
protosaurus-0.7.0-cp312-abi3-musllinux_1_2_x86_64.whl CPython 3.12 abi3 Linux musl 1.2+ x86-64 Details
protosaurus-0.7.0-cp312-abi3-musllinux_1_2_aarch64.whl CPython 3.12 abi3 Linux musl 1.2+ ARM64 Details
protosaurus-0.7.0-cp312-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.12 abi3 Linux glibc 2.28+ x86-64, Linux glibc 2.27+ x86-64 Details
protosaurus-0.7.0-cp312-abi3-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl CPython 3.12 abi3 Linux glibc 2.26+ ARM64, Linux glibc 2.28+ ARM64 Details
protosaurus-0.7.0-cp312-abi3-macosx_11_0_arm64.whl CPython 3.12 abi3 macOS 11.0+ ARM64 Details
protosaurus-0.7.0-cp312-abi3-macosx_10_14_x86_64.whl CPython 3.12 abi3 macOS 10.14+ x86-64 Details

Total release size: 10.4 MB

Release files / protosaurus-0.7.0.tar.gz

Download URL protosaurus-0.7.0.tar.gz
Size 204.2 kB
Tags Source
SHA-256 checksum
How to use checksums
963e49318a250599d2c1bfe40e9c04cf36573fa483ab8af1b7b67e6f67078958
BLAKE2b-256 checksum
How to use checksums
37acc3f923b04d09b91f8cba89924e2c1103b0a399f1355d27563865f3a7a48e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 16, 2026.

Transparency log

Release files / protosaurus-0.7.0-cp312-abi3-win_amd64.whl

Download URL protosaurus-0.7.0-cp312-abi3-win_amd64.whl
Size 765.2 kB
Tags CPython 3.12 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
692d99efd45ed26885f54e6f8ea4a14238624c7b6f35d0f0907faaf77f819a03
BLAKE2b-256 checksum
How to use checksums
c6ece14c07a6f06cd875179d5f02f1cf450746f1e0b9fe961767676eb2767cd2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 16, 2026.

Transparency log

Release files / protosaurus-0.7.0-cp312-abi3-win32.whl

Download URL protosaurus-0.7.0-cp312-abi3-win32.whl
Size 692.0 kB
Tags CPython 3.12 Windows x86-32 abi3
SHA-256 checksum
How to use checksums
cec4ff6565342f79c7af1df20b1f51063004b5031d32ee905997c80e933bb155
BLAKE2b-256 checksum
How to use checksums
eeb0e7612f31b455f6e9563f170100b4738533d5721fdeb76edbafefa676f4c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 16, 2026.

Transparency log

Release files / protosaurus-0.7.0-cp312-abi3-musllinux_1_2_x86_64.whl

Download URL protosaurus-0.7.0-cp312-abi3-musllinux_1_2_x86_64.whl
Size 2.0 MB
Tags CPython 3.12 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
6b26f0ed992eb642774882725b81413d09278458a81461a972ca70ddcc98af06
BLAKE2b-256 checksum
How to use checksums
fdfa0319b36c0e52e870bb19df178ea8ab18860ab61ba68fcdc1b227deff07a7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 16, 2026.

Transparency log

Release files / protosaurus-0.7.0-cp312-abi3-musllinux_1_2_aarch64.whl

Download URL protosaurus-0.7.0-cp312-abi3-musllinux_1_2_aarch64.whl
Size 1.9 MB
Tags CPython 3.12 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
bf8a10d5e5181bbbc2af977e965032b5727a58f562880d1d82f39639344bb444
BLAKE2b-256 checksum
How to use checksums
62da100021b0cc343ecdbdac4f1cf260224e895c206e5451d8a089725cb33cfe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 16, 2026.

Transparency log

Release files / protosaurus-0.7.0-cp312-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL protosaurus-0.7.0-cp312-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 1.5 MB
Tags CPython 3.12 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
c5ca6358c4b329934e846718e35ae37a5be1d5f12c50bb706df97b2b8bda66e6
BLAKE2b-256 checksum
How to use checksums
4c43f048e7080ad4b5e8ce5b3c46b255ecea8ce6e219e64da3186696b4e47851
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 16, 2026.

Transparency log

Release files / protosaurus-0.7.0-cp312-abi3-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl

Download URL protosaurus-0.7.0-cp312-abi3-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Size 1.4 MB
Tags CPython 3.12 Linux glibc 2.26+ ARM64 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
bad0b32ba58214737c6586bb2db320ed20e0a6858fe3487517ba20f461ddeed5
BLAKE2b-256 checksum
How to use checksums
411821c25ff202fab552533f4a4c07832645c2e0381a86012f5d26efdfe1cdd8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 16, 2026.

Transparency log

Release files / protosaurus-0.7.0-cp312-abi3-macosx_11_0_arm64.whl

Download URL protosaurus-0.7.0-cp312-abi3-macosx_11_0_arm64.whl
Size 894.0 kB
Tags CPython 3.12 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
1547105be9f2eb0acc52255fffabf2bf87f9425c5d4e3f0608e428e990750def
BLAKE2b-256 checksum
How to use checksums
c3854fad3051304052faae328c765a072fb59720a5ab716876f6310e5dea288a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 16, 2026.

Transparency log

Release files / protosaurus-0.7.0-cp312-abi3-macosx_10_14_x86_64.whl

Download URL protosaurus-0.7.0-cp312-abi3-macosx_10_14_x86_64.whl
Size 949.1 kB
Tags CPython 3.12 abi3 macOS 10.14+ x86-64
SHA-256 checksum
How to use checksums
aa0d435bda2b6b53b94cd5dbb20cc89347e395453369bbaf2c353f21d41f06d5
BLAKE2b-256 checksum
How to use checksums
9e701920369346c9245c052a8ed15e7e93fe685df59ac5b2e11e88ae5800e9e1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 16, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.7.0 This release

9 release files

0.6.0

9 release files

0.5.0

9 release files

0.4.0

8 release files

0.3.2

53 release files

0.3.0

49 release files

0.2.0

49 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