Package: protobuf-schematics
ProtoBuf SchematicsConvert ProtoBufprotofile to cuteSchematicsclasses file.Google Protobuf is great when it comes to high performance schema aware APIs, but when Google designed Protobuf, it didn’t tried to make the generated code idiomatic in Python, which brings a problem when exporting messages outside interface modules or having nice IDE auto-completions. Schematics is a cute and Pythonic schema library that goes well with most applications. Why not join both?Currently this package doesnotsupport the Protobuf binary format and will work with a any other textual representation which is easily generated with the original Protobuf API for any language. Ease of use was prioritized while writing this package rather than mere performance.Free software: Apache Software License 2.0Documentation:https://protobuf-schematics.readthedocs.io.UsageConvert theprotofile to pythonSchematicsclasses:protobuf_schematics <path-to-file.proto> generated_schematics_proto.py # or any output filenameConvert your ProtoBuf message to Json:In Java:importcom.google.protobuf.util.JsonFormat;FileWriterfile=newFileWriter("protoBufMessage.json")JsonFormat.Printerprinter=JsonFormat.printer().preservingProtoFieldNames();Stringmessage=printer.print(someProtoBufMessage);file.write(message)or from Python:importjsonfromgoogle.protobuf.json_formatimportMessageToJsonjson=MessageToJson(org,preserving_proto_field_name=True,including_default_value_fields=True)withopen("protoBufMessage.json",'w')asoutput:json.dump(json,output)In your project, load the message in python asSchematicsobject:importjsonfromgenerated_schematics_protoimportSomeMessage# import the schematics message classschematics_root_message=SomeMessage(json.load(open('protoBufMessage.json')))Or use a message loaded in python by Protobuf:importjsonfromgenerated_schematics_protoimportSomeMessage# import the schematics message class# ... get your protobuf message as the pb class representationschematics_root_message=SomeMessage.import_from_protobuf_message(protobuf_message)ExampleThisprotofile:syntax="proto3";enumIPAddressFamily{INVALID=0;IPv4=1;IPv6=2;};messageProtocolAndPorts{repeateduint32ports=3;}messageFlowFilter{enumSomeEnum{VALUE=0;};stringid=1[deprecated=true];SomeEnumconsumer_filter_id=2;map<string,ProtocolAndPorts>ports=3;repeatedProtocolAndPortsprotocol_and_ports=4;}Will be converted to:classIPAddressFamily(Enum):INVALID=0IPv4=1IPv6=2classProtocolAndPorts(ProtobufMessageModel):ports=ListType(IntType())classFlowFilter(ProtobufMessageModel):classInnerEnum(Enum):VALUE=0id=StringType()consumer_filter_id=EnumType(SomeEnum)ports=DictType(ModelType(ProtocolAndPorts),str)protocol_and_ports=ListType(ModelType(ProtocolAndPorts))FeaturesSupport both Protobuf syntax 2 and 3.Support builtin types such as StringType,IntType.Support proto map fields asSchematicsDictType.Supportrepeatedmodifier as convert toListType.Support Enum class generation and custom SchematicsEnumType.Support custom schematicsByteArrayTypebase64 encoded byte arrays converted from Java.DevelopmentFirst, install the Pipfile and create the proper virtual environment:pipenv install --devTo check linting withflake8, run:make lintTo run the unittests against your working python version:py.testTo see coverage report:make coverageTo run tests against all supported python versions:toxTo make the docs (which will be automatically published to readthedocs on commits to the master branch):make docsCreditsThe parsing work of.protofiles is provided thanks to the awesome guys atPyroBuf.This package was created withCookiecutterand theelgertam/cookiecutter-pipenvproject template, based onaudreyr/cookiecutter-pypackage.HistoryTODOAdd more meaningful unittests.Improve Protobuf support and integration.add support for parsing the Protobuf generated files as it is more comprehensive than the current Pyrobuf support.Read for Release0.4.0 (2019-01-16)Added more meaningful unittests.Export Types and Models out of the templates.Export heavy definition logic (such as field definition) from the jinja template to pythonic filters.Improve integration with Protobuf.0.2.0 (2019-01-14)Improve README - Add usage examples.Update the setup.py to point to official PyroBuf 0.8.5 PyPi release.0.1.0 (2019-01-13)First release on PyPI.CLI interface for compiling a given proto file to schematics definition file.