LegitStack

LegitStack

Best way to get Elixir to work with python?

I’m hoping you guys can give me some general advice and perhaps code examples if you’re feeling up to it.

I’m very interested in Elixir, but we use Python at my place of work. I want to make an architecture of microservices, and I’d like to use the actor model more since I see it as a generalizable pattern that can compute across clusters of machines (a trend I see continuing). For both of these reasons Elixir has my attention, but I don’t think it would be right to try to convert everyone over to it at my work.

So I really have 2 questions. Firstly, is it worth trying to get Elixir to communicate with Python? And secondly, if so, how is it best done? What is the best pattern for achieving two-way communication across languages?

For instance, my thought is to use Elixir to make the microservices infrastructure and use it to initiate processes and projects written in Python.

Would it be better to simply use rx or some other semi-concurrent actor-model-like libraries in Python to approximate the kinds of computational structures across nodes that Elixir is made for?

I’ve read through:

But I’m looking for two-way communication. Is this perhaps the best resource for that?
https://www.theerlangelist.com/article/outside_elixir

Any input is greatly appreciated, thanks!

Most Liked

rvirding

rvirding

Creator of Erlang

Pyrlang is very much alive and being worked on and improved https://github.com/Pyrlang/Pyrlang .

filmor

filmor

The main differences between erlport and Pyrlang are (as far as I can tell):

  • Pyrlang is being actively developed while erlport is on “life-support”, the original developer hasn’t interacted with the project in more than 2 years
  • erlport (as the name says) implements the port interface, so you launch a Python process from Erlang and interact with it roughly like you would with an Erlang process, internally by talking with it over stdin/out
  • Pyrlang implements a full node in Python (you have to start the Python process separately and interact with it using Erlang’s distribution mechanism
  • erlport uses a pure-python ETF serialisation while Pyrlang uses a Rust implementation that is very likely to be a lot faster
  • erlport is not async, to interact with Python you will always call a function

We have been using erlport for quite a while now in production. It works in general but the installation is a bit more hassle than it should be as it requires the (manual) installation of the erlport Python part.

I like the fact that you can start up erlport as a simple sub-process, though it shouldn’t be too hard to either add this functionality to Pyrlang (the port protocol is really simple and very close to how nodes talk to each other) or to start a Pyrlang node on demand from Erlang and just supervise the process as such.

bottlenecked

bottlenecked

Calling python/other_language code from Elixir could be more hassle than its worth, as it could complicate development and deployment (environment setup, packaging etc.)

So if you’re already using a service oriented architecture, I’d think about simply exposing functionality of your python services through eg HTTP or RabbitMq and consuming that from all-Elixir apps.

That could give you a nice separation and the confidence to introduce an unfamiliar language to your workplace (in an non threatening way to other devs too) and get a feel for it on something small/contained before deciding about full-on investment.

peerreynders

peerreynders

FYI: Pyrlang

  • I haven’t used it
  • I don’t know what state the project is in.
OvermindDL1

OvermindDL1

Using a BEAM/Erlang/Elixir Port is how you’d communicate, and you can use whatever API style you want, but if you want it as ‘native’ as possible then something like the erlport library for python makes it as ‘native’ as possible to the BEAM (it treats a python system like just another module). In some cases other format can be faster though, it all depends on the data you are transferring.

Where Next?

Popular in Questions Top

jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set? Thanks.
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
makeitrein
Hey all, just started picking up Elixir last week and am writing a scraper as a learning project. Baby step #1 is extracting the number ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> someth...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

Other popular topics Top

srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 49522 488
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

We're in Beta

About us Mission Statement