Metadata-Version: 2.1
Name: protosaurus
Version: 0.1.0
Summary: Protocol Buffers at runtime
Author-Email: Thomas Oberbichler <thomas.oberbichler@gmail.com>
Classifier: License :: OSI Approved :: ISC License (ISCL)
Project-URL: Homepage, https://github.com/oberbichler/protosaurus
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE

# Protosaurus

Parse ProtoBuffer messages at runtime.

[![Pip Action Status][actions-pip-badge]][actions-pip-link]
[![Wheel Action Status][actions-wheels-badge]][actions-wheels-link]
[![PyPi][pypi-badge]][pypi-link]


[actions-pip-link]:        https://github.com/oberbichler/protosaurus/actions?query=workflow%3APip
[actions-pip-badge]:       https://github.com/oberbichler/protosaurus/workflows/Pip/badge.svg
[actions-wheels-link]:     https://github.com/oberbichler/protosaurus/actions?query=workflow%3AWheels
[actions-wheels-badge]:    https://github.com/oberbichler/protosaurus/workflows/Wheels/badge.svg
[pypi-link]:               https://pypi.org/project/protosaurus/
[pypi-badge]:              https://img.shields.io/pypi/v/protosaurus

## Installation

```bash
pip install protosaurus
```

## Usage

```python
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 specified names can be used for imports (like filenames)
ctx.add_proto('dino.proto',
    """
    syntax = "proto3";
    import "diet.proto";
    message Dino {
        string name = 1;
        Diet diet = 2;
        double length = 3;
    }
    """)

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

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

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