Skip to main content
# read-protobuf

Small library to read serialized protobuf(s) directly into Pandas Dataframe.

This is meant to be a simple shortcut to getting from serialized protobuf bytes / files directly to a dataframe.

>Note: This currently only supports basic proto3 features for Python 3. I have not yet tested it with proto2, though I believe that should work. I plan to expand the utility of this library with time and need.

## Install

Available via pip:

```bash
$ pip install read-protobuf
```

## Usage

Run the [demo-notebook](tests/demo.ipynb) for an interactive demo.

```python
import demo_pb2 # compiled protobuf message module
from read_protobuf import read_protobuf

MessageType = demo_pb2.MessageType() # instantiate a new message type
df = read_protobuf(b'\x00\x00', MessageType) # create a dataframe from serialized protobuf bytes
df = read_protobuf([b'\x00\x00', b'x00\x00'] MessageType) # read multiple protobuf bytes

df = read_protobuf('demo.pb', MessageType) # use file instead of bytes
df = read_protobuf(['demo.pb', 'demo2.pb'], MessageType) # read multiple files

# options
df = read_protobuf('demo.pb', MessageType, flatten=False) # don't flatten pb messages
df = read_protobuf('demo.pb', MessageType, prefix_nested=True) # prefix nested messages with parent keys (like pandas.io.json.json_normalize)
```


To compile a protobuf Message class from python, use:

```bash
$ protoc --python_out="." demo.proto
```

## Alternatives

#### protobuf-to-dict

https://github.com/benhodgson/protobuf-to-dict

This library was developed earlier to convert protobufs to JSON via a dict.

#### JSON

The google protobuf library comes with a utility to convert messages to JSON. Then the JSON objects could be loaded into pands via `pd.read_json()`.

```python
from google.protobuf.json_format import MessageToJson
```

In my brief tests, the `read_protobuf` package is about twice as fast as converting a protobuf to a dataframe using `MessageToJson`.

## Develop

Currently developed for Python 3 using the anaconda python distribution. To install a development version of the package, run from the root directory:

```bash
$ pip install -e .
```

- To install development dependencies, use pip on the `dev-requirements.txt` file:

```bash
$ pip install -r dev-requirements.txt
```

## Lint

Uses `pylint` to lint application.

```
$ pylint read_protobuf
```

Configuration options are specified in `.pylintrc`

## Test

Uses `pytest` to run unit tests. From the root of the repository, run:

```
$ pytest
$ pytest -k "TestRead::test_read_bytes" # specify test
```

Configuration options are specified in `setup.cfg`

## Code Coverage

We use `coverage` to monitor code coverage during tests. To record coverage while running tests, run:

```bash
$ coverage run -m pytest # watch files while testing
$ coverage report # will display coverage report
```


## UnLicense

This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.

In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to <http://unlicense.org/>




Metadata

Release files for read-protobuf 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for read-protobuf 0.1.1
File Size Uploaded Provenance Actions
read-protobuf-0.1.1.tar.gz 7.3 kB Without provenance Details for read-protobuf-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for read-protobuf 0.1.1
File Interpreter ABI Platform Actions
read_protobuf-0.1.1-py3-none-any.whl Python 3 none any Details for read_protobuf-0.1.1-py3-none-any.whl

Total release size: 14.6 kB

Release files / read-protobuf-0.1.1.tar.gz

Download URL read-protobuf-0.1.1.tar.gz
Size 7.3 kB
Tags Source
SHA-256 checksum
How to use checksums
67cceb7463c36b076cd9572d30feb395ff41ed2065e683f487c561f4a395b364
BLAKE2b-256 checksum
How to use checksums
df4e25d836d95376c33b311f633dffae5f78cb36c342195c85a469d3fe5b0104
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / read_protobuf-0.1.1-py3-none-any.whl

Download URL read_protobuf-0.1.1-py3-none-any.whl
Size 7.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
394b7d064fe377c2bef0b36f05584a56ed332ffdf4d4d187f28af8190a6382f9
BLAKE2b-256 checksum
How to use checksums
3c271f2995cf2f06251faa917f87ce642673f820fd0d89cde379523ab34a0af7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for read-protobuf 0.1.1

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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