Calling Elixir function from Python with pyrlang

Hello all,

I’ve recently been playing around with both Erlang and Elixir and wished to create a few apps for my Github with them, both of which required a small UI. For the Erlang project I managed to get a Java Swing program to call functions running on an Erlang server without any issues. For the Elixir project I’d like to use Python.

I came across ‘pyrlang’ and was able to run through a couple of examples of interacting with an Erlang server through Python, but I’m not finding much in the way of information regarding calling Elixir.

If anyone has any experience with pyrlang, can you tell me what I’d need to do to pass a couple of variables to an Elixir function, and retrieve the result?

# To start server: werl -name erl@127.0.0.1 -setcookie COOKIE -env ERL_LIBS "C:\Program Files (x86)\Elixir\lib" -user Elixir.IEx.CLI -extra --no-halt
# To compile: c("library.ex")
# To test: Lib.add_numbers(3, 4)

defmodule Lib do
    def add_numbers(a, b) do
        a + b
    end
end
3 Likes

Hello friend and welcome to the forum. :slight_smile:

Being in a similar boat, I’ve found the step-by-step articles below to be very helpful in devising a solution using ErlPort, an Elixir library:

  1. https://medium.com/hackernoon/mixing-python-with-elixir-7a2b7ac6696
  2. https://medium.com/hackernoon/mixing-python-with-elixir-ii-async-e8586f9b2d53
  3. https://medium.com/hackernoon/calling-python-from-elixir-erlport-vs-thrift-be75073b6536

Perhaps they can, at the very least, point you in the right direction? :slight_smile:

1 Like

In case anyone comes across this via searching for Pyrlang and Elixir examples:

The documentation, and code examples now cover elixir

There are 2 make commands for the python and elixir nodes Pyrlang/Makefile at master · Pyrlang/Pyrlang · GitHub

plus, there are Examples! — Pyrlang 1.0 documentation instructions and code
Pyrlang/examples/elixir at master · Pyrlang/Pyrlang · GitHub

2 Likes