Skip to main content

A pythonic protobuf library using dataclasses and enums

Project description

protobug

A pythonic protobuf library using dataclasses and enums

Usage

First, define a protobug.message. It is similar to a dataclass, except it uses protobug.field and protobug types:

import protobug


@protobug.message
class Message:
    a: protobug.String | None = protobug.field(1, default=None)
    b: list[protobug.String] = protobug.field(2, default_factory=list)
    c: dict[protobug.UInt32, protobug.String] = protobug.field(3, default_factory=dict)

After defining the model, you can freely decode and encode messages. protobug's API follows the familiar load/loads & dump/dumps convention:

>>> payload = b"\x0a\x0bhello world"
>>> protobug.loads(payload, Message)
Message(a='hello world', b=[], c={})

>>> payload = b"\x12\x05hello\x12\x05world"
>>> protobug.loads(payload, Message)
Message(a=None, b=['hello', 'world'], c={})

>>> payload = b"\x1a\x09\x08\x00\x12\x05val 0\x1a\x09\x08\x01\x12\x05val 1"
>>> protobug.loads(payload, Message)
Message(a=None, b=[], c={0: 'val 0', 1: 'val 1'})

>>> data = Message(a='val a', b=['val b'], c={0: 'val c'})
>>> protobug.dumps(data)
b'\n\x05val a\x12\x05val b\x1a\t\x08\x00\x12\x05val c'

License

protobug is distributed under the terms of the Unlicense license.

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

protobug-1.0.0.tar.gz (12.9 kB view details)

Uploaded Source

Built Distribution

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

protobug-1.0.0-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file protobug-1.0.0.tar.gz.

File metadata

  • Download URL: protobug-1.0.0.tar.gz
  • Upload date:
  • Size: 12.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for protobug-1.0.0.tar.gz
Algorithm Hash digest
SHA256 d6ea277e83e1a468b1c75a928fbba97e0cb10743df5558e8f326170984364fbb
MD5 820bf5a6a5114a6a3fbfad56faece894
BLAKE2b-256 fdf73174903b46402b4bd8a2cce57d7b363dedde93ebcdbaf63a5a630d22fe3c

See more details on using hashes here.

Provenance

The following attestation bundles were made for protobug-1.0.0.tar.gz:

Publisher: release.yml on yt-dlp/protobug

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

File details

Details for the file protobug-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: protobug-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 10.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for protobug-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8b1b5cb3f4b2dd4fa0a6219ca770f687d0af32606d344ac7acedf00943f220c3
MD5 79cc90f280fbf688353edc3261bdb79a
BLAKE2b-256 44bb02eccbae7de82571c9ca8ef0cca6d07dfd2cca2c1d7053cd0864f688af55

See more details on using hashes here.

Provenance

The following attestation bundles were made for protobug-1.0.0-py3-none-any.whl:

Publisher: release.yml on yt-dlp/protobug

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