Metadata-Version: 2.4
Name: protobug
Version: 1.0.0
Summary: A pythonic protobuf library using dataclasses and enums
Project-URL: Documentation, https://github.com/yt-dlp/protobug?tab=readme-ov-file
Project-URL: Repository, https://github.com/yt-dlp/protobug
Project-URL: Issues, https://github.com/yt-dlp/protobug/issues
Project-URL: Source, https://github.com/yt-dlp/protobug
Author-email: Simon Sawicki <contact@grub4k.dev>
License-Expression: Unlicense
License-File: LICENSE
Keywords: protobuf
Classifier: Development Status :: 5 - Production/Stable
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: Implementation :: CPython
Requires-Python: >=3.10
Description-Content-Type: text/markdown

# 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:
```py
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:
```py
>>> 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](https://spdx.org/licenses/Unlicense.html) license.
