Skip to main content

Extra tools for Protobuf and Python

Project description

protobuf-extra provides a program and a library to convert between ASCII, Python dictionary, and binary Protocol Buffer message representations.

Basic usage

Typical usage of the program might look like this:

$ export PYTHONPATH=.
$ pb --type test.Person.Person >person-template.txt

The ‘PYTHONPATH’ should contain the path to the Python protobuf message definitions, those generated by the ‘protoc’ protobuf compiler.

Now edit the person-template.txt.

Then generate protobuf message from it:

$ pb --type test.Person.Person --in ascii --out bin >person.gpb <person-template.txt
$ pb --type test.Person.Person --in bin --out dict <person.gpb
{'age': 39, 'birthday': {'month': 8, 'day': 4, 'year': 1978}, 'name': u'Mikko', 'children': [{'age': 4, 'birthday': {'month': 3, 'day': 18, 'year': 2013}, 'name': u'Sonja'}]}
$ pb --type test.Person.Person --in bin --out ascii <person.gpb
name: "Mikko"
age: 39
birthday {
  year: 1978
  month: 8
  day: 4
}
children {
  name: "Sonja"
  age: 4
  birthday {
    year: 2013
    month: 3
    day: 18
  }
}

See ‘pb –help’ for a complete listing of options.

The included Python library provides the ability to make, for example, protobuf Message instances from a Python dictionary:

#!/usr/bin/env python
from test.Person_pb2 import Person
from protobuf_extra import MessageFromDictionary

person = MessageFromDictionary(Person, {
    "name": "John Doe",
    "birthday": {"year": 1970, "month": 1, "day": 1}
})

See ‘pydoc protobuf_extra’ for a lot more documentation.

Requirements

In addition to Python (2.7 or 3.3 - 3.6), protobuf (3.0.0 - 3.3.0) is required.

Installation

Use either pip install protobut-extra or download the source archive and use python setup.py install.

The source code is available at Python Package Index (PyPI) or, if you want the unreleased version, from Github git repository.

Authors

Original author and current maintainer is Mikko Värri (vmj@linuxbox.fi).

License

protobuf-extra is Free Software, licensed under GNU General Public License (GPL), version 3 or later. See LICENSE.txt file for details.

Release history

Version 0.5.2 (2017-11-10)

A source distribution packaging bug was fixed.

Version 0.5.1 (2017-08-15)

This release fixes a few places in docs.

Version 0.5 (2017-08-15)

Ported to Python 3, still compatible with Python 2.7. Python 3 support requires protobuf 3.0.0 or newer.

This version still only supports ‘proto2’ syntax.

Version 0.1 (2013-10-08)

Initial release.

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

protobuf-extra-0.5.2.tar.gz (7.2 kB view hashes)

Uploaded Source

Supported by

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