Reputation: 847
I want to parse a .proto file that is part of a gRPC client/server definition. I just want a starting point for doing this. I have the gRPC code installed and can autogenerate python code from the proto files. I am wondering if there are any obvious python classes in the gRPC code (or open source libs out there) that read in proto files and, in some limited way, parses them into some kind of structured objects?
Upvotes: 0
Views: 4758
Reputation: 6576
parsy (combinator library) has an example that parses .proto
files, version 3. You can find it in the repo. The result is a structured object, using simple custom defined classes such as Proto
for the whole file, which has a statements
attribute, which contains Import
for each import line, Message
for each message etc.
Upvotes: 2
Reputation: 63709
The gRPC web page tells me that it uses protobufs syntax as its IDL. The examples directory included with the pyparsing source distribution includes a pure Python protobuf parser. You can view it here: https://sourceforge.net/p/pyparsing/code/HEAD/tree/trunk/src/examples/protobuf_parser.py
Upvotes: 1