Skip to main content

Protocol Buffers at runtime

Project description

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}'


# 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$@'

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

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

protosaurus-0.4.0.tar.gz (183.6 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

protosaurus-0.4.0-cp312-abi3-win_amd64.whl (743.8 kB view details)

Uploaded CPython 3.12+Windows x86-64

protosaurus-0.4.0-cp312-abi3-win32.whl (677.9 kB view details)

Uploaded CPython 3.12+Windows x86

protosaurus-0.4.0-cp312-abi3-musllinux_1_2_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.12+musllinux: musl 1.2+ x86-64

protosaurus-0.4.0-cp312-abi3-musllinux_1_2_aarch64.whl (1.9 MB view details)

Uploaded CPython 3.12+musllinux: musl 1.2+ ARM64

protosaurus-0.4.0-cp312-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.12+manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

protosaurus-0.4.0-cp312-abi3-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl (1.4 MB view details)

Uploaded CPython 3.12+manylinux: glibc 2.26+ ARM64manylinux: glibc 2.28+ ARM64

protosaurus-0.4.0-cp312-abi3-macosx_11_0_arm64.whl (872.2 kB view details)

Uploaded CPython 3.12+macOS 11.0+ ARM64

File details

Details for the file protosaurus-0.4.0.tar.gz.

File metadata

  • Download URL: protosaurus-0.4.0.tar.gz
  • Upload date:
  • Size: 183.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for protosaurus-0.4.0.tar.gz
Algorithm Hash digest
SHA256 7b5095208b1cf796cad197691b3496f86691102afc242fc494c1adcba6ffce04
MD5 bbe055160ad7d7c10cd4bbaeecfbfa01
BLAKE2b-256 1c68e695604b974adc04d88b504c3b8d0df48cf4f14c5fb71e2a7406ab31f1ca

See more details on using hashes here.

Provenance

The following attestation bundles were made for protosaurus-0.4.0.tar.gz:

Publisher: wheels.yml on oberbichler/protosaurus

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file protosaurus-0.4.0-cp312-abi3-win_amd64.whl.

File metadata

  • Download URL: protosaurus-0.4.0-cp312-abi3-win_amd64.whl
  • Upload date:
  • Size: 743.8 kB
  • Tags: CPython 3.12+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for protosaurus-0.4.0-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 0069ce32c624ae442a7896c28fcded1d9b4292f744680d2993438898eabdf9a1
MD5 da81c344010cd9de6c57e685d091b47e
BLAKE2b-256 04ad646293b4768bfb05e52661db91af06e5c1defc92ff45d378b75ecc0ddf8b

See more details on using hashes here.

Provenance

The following attestation bundles were made for protosaurus-0.4.0-cp312-abi3-win_amd64.whl:

Publisher: wheels.yml on oberbichler/protosaurus

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file protosaurus-0.4.0-cp312-abi3-win32.whl.

File metadata

  • Download URL: protosaurus-0.4.0-cp312-abi3-win32.whl
  • Upload date:
  • Size: 677.9 kB
  • Tags: CPython 3.12+, Windows x86
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for protosaurus-0.4.0-cp312-abi3-win32.whl
Algorithm Hash digest
SHA256 c01a12a78c8383851f3937654dde820860171880fcea724adefd138b5249a31b
MD5 afb07e03e33d35e2d76306250b0eec5c
BLAKE2b-256 7bcd63d8c3dc984de49c9c7654c109fc0177716823c3a58a679bc74675325534

See more details on using hashes here.

Provenance

The following attestation bundles were made for protosaurus-0.4.0-cp312-abi3-win32.whl:

Publisher: wheels.yml on oberbichler/protosaurus

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file protosaurus-0.4.0-cp312-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for protosaurus-0.4.0-cp312-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 f486b7bbb96ebcdf960036c4aa412f89c58bf4308729e424331ec8c1a63a7a12
MD5 bfcc577db621e5a788c316defced4362
BLAKE2b-256 42a169bdbade01c06c9df0aea91ec78fd75a0b3c05bb001ce1ea6b50159f01d3

See more details on using hashes here.

Provenance

The following attestation bundles were made for protosaurus-0.4.0-cp312-abi3-musllinux_1_2_x86_64.whl:

Publisher: wheels.yml on oberbichler/protosaurus

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file protosaurus-0.4.0-cp312-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for protosaurus-0.4.0-cp312-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 5cc9435f7266fb0108bf90bda67c38fde8db4ec8e97624ade6cd1a7c3b8de57a
MD5 c2078f184883a7f262dd18669e99051b
BLAKE2b-256 f620fc3a048f7f4a04cb46000024dfe7ce79bcff3c7fbf1c12ec1ff12a61eae9

See more details on using hashes here.

Provenance

The following attestation bundles were made for protosaurus-0.4.0-cp312-abi3-musllinux_1_2_aarch64.whl:

Publisher: wheels.yml on oberbichler/protosaurus

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file protosaurus-0.4.0-cp312-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for protosaurus-0.4.0-cp312-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 57b0a1f832399c21e79b76b0344fc84caef2304788d6a9eb56712c36656f95f8
MD5 db42fe63419d40d827272f97a17d4bcf
BLAKE2b-256 06bc19a8fc54057019c58b4518b37ac6b069f24f58675f42c5ca2e458d731d02

See more details on using hashes here.

Provenance

The following attestation bundles were made for protosaurus-0.4.0-cp312-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: wheels.yml on oberbichler/protosaurus

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file protosaurus-0.4.0-cp312-abi3-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for protosaurus-0.4.0-cp312-abi3-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 95f38c4dd91e9c2280f37be83674675b7218746a82d1712cc499a48d281c89b7
MD5 f575188a76ba07d9b49d2e39af2a73c4
BLAKE2b-256 4026f6ad7f522c7327e9391859bccb11b091628c0d1be8e4b83286025ee3d76a

See more details on using hashes here.

Provenance

The following attestation bundles were made for protosaurus-0.4.0-cp312-abi3-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl:

Publisher: wheels.yml on oberbichler/protosaurus

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file protosaurus-0.4.0-cp312-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for protosaurus-0.4.0-cp312-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 299e421370463f7f7d2d3825b65370ee6da93d561f4b915b3cdb7140c1e70faa
MD5 496d7403c6274324a3f066a3b6ee62dc
BLAKE2b-256 c54ece06172649e6c7490a2ef100b11c0355212a641604c0ba06aebc2add16ca

See more details on using hashes here.

Provenance

The following attestation bundles were made for protosaurus-0.4.0-cp312-abi3-macosx_11_0_arm64.whl:

Publisher: wheels.yml on oberbichler/protosaurus

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page