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.
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file protobuf-extra-0.5.2.tar.gz
.
File metadata
- Download URL: protobuf-extra-0.5.2.tar.gz
- Upload date:
- Size: 7.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 52fcb70dbcf8c6b767cf03993efa699a4ce63979be911c46b0217d179856b25f |
|
MD5 | 6013b6e7aa7cbc4bb01d1d2cf5cad19b |
|
BLAKE2b-256 | 5ad4e15cade462ed0c5f4cafecea5119989dfb7f156958c02366051c8573a6a5 |