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.6.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.6.0
File Size Uploaded
protosaurus-0.6.0.tar.gz 202.9 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for protosaurus 0.6.0
File
protosaurus-0.6.0-cp312-abi3-win_amd64.whl CPython 3.12 abi3 Windows x86-64 Details
protosaurus-0.6.0-cp312-abi3-win32.whl CPython 3.12 abi3 Windows x86-32 Details
protosaurus-0.6.0-cp312-abi3-musllinux_1_2_x86_64.whl CPython 3.12 abi3 Linux musl 1.2+ x86-64 Details
protosaurus-0.6.0-cp312-abi3-musllinux_1_2_aarch64.whl CPython 3.12 abi3 Linux musl 1.2+ ARM64 Details
protosaurus-0.6.0-cp312-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.12 abi3 Linux glibc 2.27+ x86-64, Linux glibc 2.28+ x86-64 Details
protosaurus-0.6.0-cp312-abi3-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl CPython 3.12 abi3 Linux glibc 2.28+ ARM64, Linux glibc 2.26+ ARM64 Details
protosaurus-0.6.0-cp312-abi3-macosx_11_0_arm64.whl CPython 3.12 abi3 macOS 11.0+ ARM64 Details
protosaurus-0.6.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.6.0.tar.gz

Download URL protosaurus-0.6.0.tar.gz
Size 202.9 kB
Tags Source
SHA-256 checksum
How to use checksums
929a704fd8adac8b8fc0b879f1b442c78ea1a40c5a6193595cbb1ae54238829e
BLAKE2b-256 checksum
How to use checksums
640ada3bf04d8a2afc27f96f8607c0e71b0f78db8f9030471dd1b1bff70a43b4
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.6.0-cp312-abi3-win_amd64.whl

Download URL protosaurus-0.6.0-cp312-abi3-win_amd64.whl
Size 763.2 kB
Tags CPython 3.12 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
fff3e455cc260403206cf27f81523b60e6b8c47c4b636c1d77540b92fcd1f649
BLAKE2b-256 checksum
How to use checksums
ae13b816e9ead88f10d10c3a81136a30325427c3c2b75fb8ec6fce9b9fe22a1d
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.6.0-cp312-abi3-win32.whl

Download URL protosaurus-0.6.0-cp312-abi3-win32.whl
Size 690.1 kB
Tags CPython 3.12 Windows x86-32 abi3
SHA-256 checksum
How to use checksums
62a88fdc4a1488d2542bc14d137c666a26b9427cb4007287c5bcbd9fdc8891d1
BLAKE2b-256 checksum
How to use checksums
6b86473fa98617a5060194123c7ef3d6d011b5c7686a0ee23d83fc4f2f197ba3
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.6.0-cp312-abi3-musllinux_1_2_x86_64.whl

Download URL protosaurus-0.6.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
3ffcb4d29c52af1fbca63ff707c0eb0cdb3a5acd68059155e79dd003a265c9b9
BLAKE2b-256 checksum
How to use checksums
9d1c8378493f9d7f5fa33fbbbf3f0f61b6ca48a344c2b09a0279ac5bf0596f59
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.6.0-cp312-abi3-musllinux_1_2_aarch64.whl

Download URL protosaurus-0.6.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
c9664f5a78cabf91c9bcb1b2ab059e796f7f49b08a53c5aa0c42c2069f1a606e
BLAKE2b-256 checksum
How to use checksums
a3c2e9a16f9a19e4a6f1de1714f44a83cccff5e6158730c89e15661ff0e6ab29
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.6.0-cp312-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL protosaurus-0.6.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
78e9cb21f031298163fbcdc4a91c28b98f7def6fb8450221a38a89c5f1b8abc5
BLAKE2b-256 checksum
How to use checksums
8c75a10b50976bc8aa5ce8560cf8a5a26263c60130534b4a72ceced6ed90e7d1
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.6.0-cp312-abi3-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl

Download URL protosaurus-0.6.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
12e88ac7699ba1c4d799eda0abe3b82b18b2e5c59638c713cac3c8ac0b5c9908
BLAKE2b-256 checksum
How to use checksums
c9c813c50a384af146acdde61bf1095058779d7323f0eb5edad51ea493ee3f02
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.6.0-cp312-abi3-macosx_11_0_arm64.whl

Download URL protosaurus-0.6.0-cp312-abi3-macosx_11_0_arm64.whl
Size 892.0 kB
Tags CPython 3.12 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
6f11bd6fe9edf3109a1d9f7c17e5eac177d457f624181fd88f512756bf0cc208
BLAKE2b-256 checksum
How to use checksums
4752db37ffe1adc1f1d339b20c5dd3e3da5130b4797d0a081236e9c6e82203e7
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.6.0-cp312-abi3-macosx_10_14_x86_64.whl

Download URL protosaurus-0.6.0-cp312-abi3-macosx_10_14_x86_64.whl
Size 947.0 kB
Tags CPython 3.12 abi3 macOS 10.14+ x86-64
SHA-256 checksum
How to use checksums
68adc6675ba1ff0d1d66b28e08161ccddea3a438778dd0b323395cc26259c676
BLAKE2b-256 checksum
How to use checksums
c3faaf228599be12328f15b2e251c8327775af0e6bea83a84ba957f2f9ace564
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

0.7.0

9 release files

This release

0.6.0 This release

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