proto files parsing in python - libs or tips?

37 views
Skip to first unread message

שחם פרידנברג

unread,
Mar 23, 2020, 10:32:45 AM3/23/20
to Protocol Buffers
hey all,

I wish to write a python tool which verifies comparability between two different versions of my proto files.

For that, I want to first parse proto files and represent them in some sorts of python classes. 

Any idea of a python library that does that? I wrote some simple parser and then realized that there might be infinite nested messages..

Thanks in advance for any help and tip :)
Shaham

Nadav Samet

unread,
Mar 23, 2020, 10:41:52 AM3/23/20
to שחם פרידנברג, Protocol Buffers
Hi Shaham,

If you already have Python generated code for your messages, you can import it and look for the descriptors to traverse the structure (I think this is message.DESCRIPTOR). If you don't have generated code, you can look into "protoc --descriptor_set_out" to create a descriptor given a proto file. You can load this descriptor in runtime and perform the verification you want to do.

Alternatively, you can also look into https://github.com/uber/prototool - the README suggest there's a command "prototool break check" which may do similar things to what you want. 

Hope this helps,
Nadav

--
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/42282c8a-373a-4625-a73e-f4a5d9dc67d9%40googlegroups.com.


--
-Nadav

שחם פרידנברג

unread,
Mar 23, 2020, 10:50:55 AM3/23/20
to Protocol Buffers
Thanks a lot for the quick and comprehensive response, I'll look into the suggested methods! :)

בתאריך יום שני, 23 במרץ 2020 בשעה 16:41:52 UTC+2, מאת Nadav Samet:
Hi Shaham,

If you already have Python generated code for your messages, you can import it and look for the descriptors to traverse the structure (I think this is message.DESCRIPTOR). If you don't have generated code, you can look into "protoc --descriptor_set_out" to create a descriptor given a proto file. You can load this descriptor in runtime and perform the verification you want to do.

Alternatively, you can also look into https://github.com/uber/prototool - the README suggest there's a command "prototool break check" which may do similar things to what you want. 

Hope this helps,
Nadav

‪On Mon, Mar 23, 2020 at 7:32 AM ‫שחם פרידנברג‬‎ <sha...@gmail.com> wrote:‬
hey all,

I wish to write a python tool which verifies comparability between two different versions of my proto files.

For that, I want to first parse proto files and represent them in some sorts of python classes. 

Any idea of a python library that does that? I wrote some simple parser and then realized that there might be infinite nested messages..

Thanks in advance for any help and tip :)
Shaham

--
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 prot...@googlegroups.com.


--
-Nadav
Reply all
Reply to author
Forward
0 new messages