Is there a method to compile a .proto message within a python script?

50 views
Skip to first unread message

Taran Deshpande

unread,
Jul 7, 2020, 12:44:20 PM7/7/20
to Protocol Buffers
 Hello,

I want to write a python script that will parse a proto message without having the definition compiled beforehand. Basically, I want the script to take in a .proto definition as an argument at runtime and compile it using protoc so the script can parse any protobuf message. Is there a python module available to invoke protoc?

Austin Bennett

unread,
Jul 7, 2020, 1:48:59 PM7/7/20
to Taran Deshpande, Protocol Buffers
Sometimes I use python rather than protoc to generate, for example:

python -m grpc.tools.protoc \
--proto_path=. \
--proto_path=${GOOGLEAPIS_DIR} \
--python_out=python \
--grpc_python_out=python \
${PROTO_NAME}.proto

So, crudely wondering whether you could create within your script using grpc.tools.protoc.  Haven't considered doing this previously -- so merely a pointer to one area that might (or not) be useful to explore --

Good luck!


On Tue, Jul 7, 2020 at 9:44 AM Taran Deshpande <td...@umich.edu> wrote:
 Hello,

I want to write a python script that will parse a proto message without having the definition compiled beforehand. Basically, I want the script to take in a .proto definition as an argument at runtime and compile it using protoc so the script can parse any protobuf message. Is there a python module available to invoke protoc?

--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/protobuf/e6d2011f-d4fc-417f-aefd-fffb03a29a1co%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages