12

I am looking into using protocol buffers to communicate with some custom devices we have. The problem is that these devices run an embedded python interpreter and we cannot install extra libraries onto them. Is there a way to compile .proto files into python without requirement for the protobuf library?

5
  • 3
    You could just import the file right? So, download this github.com/google/protobuf/tree/master/python and then just do like import mox Commented Nov 4, 2016 at 4:22
  • Looks like there is more than 1.5M of code in there. Our whole app is less than 500K. I wonder how much am I going to need for the parsers to work. Commented Nov 4, 2016 at 14:31
  • 1
    Do you need Protobuf to communicate with other parts already using it? Can you use some other solutions, like: ASN.1, ZeroMQ? Commented Jan 1, 2017 at 20:14
  • I need a compact binary protocol to communicate with an embedded device over network. The device runs python, but has very limited resources and doesn't allow installing external libraries. I will look into zeromq and ASN.1, thanks. Commented Jan 1, 2017 at 22:53
  • This is just spitballing, crazy talk, but couldn't you tear apart like the deserialization bits of protobuff's python implementation, reimplement the bare minimum hard coding a protobuff format specification that initialized itself on load. Then you could communicate at least one way with your device using a single, static protobuff definition/network configuration. But if you are going to go to all that work why not just pickle? It'd be a heck of a lot easier Commented Jan 2, 2017 at 16:57

2 Answers 2

5
+50

Give a try to protlib instead, its only 51.4 KB and you can delete some code there that handles types that you don't need.

Sign up to request clarification or add additional context in comments.

1 Comment

Looks like the lib is in pure python, so we could embed it into our codebase. Thank you, I will mark this as the answer.
2

Another possibility is to use Better Protobuf for Python which is currently supported unlike protolib. It supports most use cases and has been under active development since 2019. It also provides a very friendly API to interact with the generated Protobuf files.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.