django dude
django dude

Reputation: 81

using swig to bind google protocol buffers

I'm writing python program that needs to process a lot of small but complex protobuf-encoded messages. I tried to use the Python implementation of protocol buffers, which is written in pure python, but its performance is really terrible.

So I'm looking into a solution that apparently some folks got to work - use protoc to generate C++ files, then use swig to wrap them with python. The problem is that I can't get to a working Python module.

I was wondering if anyone has a working example of getting swig to work on top of protobuf-C++?

Alternatively - is there an example of some other solution, such as the Python extension mentioned in the same page? Though that seems like a high-maintenance solution for my dynamic schema...

If none of this works I'm considering dropping python in favor of Groovy - assuming that the Java implementation of protocol buffers would be more efficient. Any comment on that?

Muchas Gracias!

Upvotes: 7

Views: 2687

Answers (3)

Sandeep
Sandeep

Reputation: 658

New version of Protobuf supports using the fast C++ implementation of Protobuf with Python code. Set the environment variable PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=cpp.

Upvotes: 2

django dude
django dude

Reputation: 81

Here is the correct link to the Greplin fast-python-pb solution which I ended up using. It's very easy to use (at least in Linux), and performance is x100 times up.

This software is still young and not 100% compatible with the Google implementation, at least with regard to empty values in optional fields - but the differences are pretty minor.

Upvotes: 1

John Zwinck
John Zwinck

Reputation: 249153

Try %include'ing your generated headers in your SWIG file and also the base class files explicitly (rather than using includeall). You should be able to be explicit enough that SWIG understands you want to bind the base classes and the derived ones.

Upvotes: 0

Related Questions