tags:

views:

131

answers:

3

I have a compiled Python library and API docs that I would like to use from Ruby.

Is it possible to load a Python library, instantiate a class defined in it and call methods on that object from Ruby?

+1  A: 

This article gives some techniques for running Ruby code from Python which should also be applicable in the reverse direction (such as XML-RPC or pipes) as well as specific techniques for running Python code from Ruby. In particular rubypython or Ruby/Python look like they may do what you want.

kindall
Do you know of any available comparisons between these 2 offerings?
Bryan Ash
Sadly, no. Nor have I used either myself.
kindall
A: 

Are you on Windows? Could you create a DLL or COM object from your python lib and call it with Ruby's Win32Api or Win32Ole?

AShelly
+1  A: 

Even you can make this work, you might want to consider if this is the best architectural choice. You could run into all sorts of versioning hell trying to maintain such a beast.

If you really can't find an equivalent Ruby library (or it's a big investment in Python you want to leverage,) consider using a queue (like RabbitMQ) to implement a message passing design. Then you can keep your Python bits Python and your Ruby bits Ruby and not try to maintain a Frankenstein build environment.

Joshua
The Python library is an interface to a piece of commercial test equipment, so I don't have the option of changing it or rewriting in Ruby.
Bryan Ash