Calling Python from Ruby

Viewed 28415

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?

6 Answers

https://github.com/mrkn/pycall.rb

Here is a simple example to call Python's math.sin function and compare it to the Math.sin in Ruby:

require 'pycall/import'
include PyCall::Import
pyimport :math
math.sin(math.pi / 4) - Math.sin(Math::PI / 4)   # => 0.0

Type conversions from Ruby to Python are automatically performed for numeric, boolean, string, arrays, and hashes.

Related