red-data-tools/pycall.rb

Calling Python functions from the Ruby language

What it solves

PyCall allows Ruby developers to directly call Python code and use Python libraries within their Ruby applications. It bridges the gap between the two languages by enabling you to import Python modules and execute functions as if they were native Ruby code.

How it works

The library wraps Python objects and functions, providing automatic type conversion for common data types like numbers, strings, arrays, and hashes. It maps Python syntax to Ruby-friendly equivalents—for example, Python's classname(x) becomes classname.new(x) in Ruby, and keyword arguments are handled using Ruby's colon syntax (e.g., x: 1). It also provides tools to manage the Ruby Global VM Lock (GVL) when executing long-running Python tasks.

Who it’s for

This tool is for Ruby developers who need to leverage the rich ecosystem of Python libraries (such as data science or scientific computing tools) without leaving their Ruby environment.

Highlights

  • Automatic type conversion between Ruby and Python objects.
  • Seamless mapping of Python constructors, callable objects, and keyword arguments to Ruby syntax.
  • Support for releasing the Ruby GVL to improve performance during long-running Python function calls.
  • Compatible with Ruby 2.4+ and Python 3.7+.
  • Includes debugging tools to help locate Python shared libraries if they are not automatically detected.

Related

  • Project
  • Project
  • Project
  • Project