#Pyrlang vs erlport for calling python code from elixir

1 messages · Page 1 of 1 (latest)

jolly drift
#

We are new to elixir but experienced with python and have some erlang experience, we have a python project that is a reference implementation of the keri architecture (https://github.com/WebOfTrust/keripy). For ease of interoperability testing (and for scaffolding) we thought it would be nice to call into this python library to the pure functions (not the async workers) to help us move faster (and we'll be re-implementing our own state handling so it should be strictly calls into the functional units of this project).

For calling python from elixir we found that there's erlport and pyrlang which is what Google comes up with. However, erlport looks like a lot of work and overhead for what we'd like to do and pyrlang looks like it hasn't really been touched for quite a while. Was wondering what more experienced developers thought?

Do you have any strong opinions about which is better to do what we're trying to do?
Can you compare and contrast when/where what tradeoffs you'd consider when using pyrlang/erlport?
Are there any newer/better alternatives we might not know about?

We kinda thought there'd just be some FFI bindings and off we'd go but it looks like that's a heavier lift on the BEAM than in other languages.

Anyways, just trying to mine those more experienced before we start off on our journey. Thanks in advance.

jolly drift
#

Oh we just tried erlport and it doesn't even look like this runs on modern python 3.11 or BEAM. Is this the right understanding or is there a more updated version?

tribal nymph
#

which one did you use?

jolly drift
#

the erlport/erlport one. First we started with the hdima one but it didn't work either

tribal nymph
#

yeah, hdima is very, very old

#

there's python3 support in erlport/erlport, but I'm not sure about 3.11

#

what doesn't work?

#

(FWIW, I used it a long time ago, and had a lot of success)

jolly drift
#

erlport/erlport didn't have the same install instructions as the hdima repo. It pointed back to the old documentation though. Weren't really sure where to go.

#

pyrlang is giving us trouble too. We tried both out here just now

#

pyrlang the examples won't even work.

tribal nymph
#

pyrlang is a python erlang node right?

#

how did you start up erlport?

jolly drift
#

yeah, according to the documentation. in the examples

#

Like uhh erlang -env ERL_LIBS ../erlport --cookie something_or_other

#

something like that, whatever was in the documentation

#

but then when we did make example1 or what have you we'd get several python errors that we worked through and then an error communicating with the erlang node that we couldn't work through

tribal nymph
#

you run erlport via elixir, you don't need to start a node

jolly drift
#

hmm, I'm not sure. Maybe? We were just trying the install and simple examples and we couldn't get it to work in erlang even (which the examples were all geared to) we were gonna get to elixir but never got past that first step

tribal nymph
#

to translate the docs to elixir

{:ok, py_instance} = :python.start()
:python.call(py_instance, :sys, :version, [])
jolly drift
#

yeah, that's when we'd get an error in communication

tribal nymph
#

what's the error?

jolly drift
#

thanks for the help but I have to run at the moment, this is the error we were getting on erlang side and the python side from the first example

#

I will be back on later

tribal nymph
#

i'll be more help if you could get that in an elixir project and run it from there

#

also, you seem to be running pyrlang above and not erlport

jolly drift
#

oh my apologies, you're absolutely right. We attempted both. I'll get you the erlport error

#

oh right, the repo points to this documentation website http://erlport.org/downloads/

There is no makefile anymore in erlport/erlport so we didn't know how to advance from here. We tried rebar3 release but that didn't work rebar3 compile did work but then starting it in the shell didn't seem to work

tribal nymph
jolly drift
#

oh nevermind. Actually that seemed to work.

Erlang/OTP 26 [erts-14.2.1] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit:ns]

Interactive Elixir (1.16.1) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> :python.start()
{:ok, #PID<0.111.0>}
iex(2)>```
#

do you know if there's a more natural way to do that short of running iex with the -erl flag?

tribal nymph
#

yeah, don't do it that way

#

mix new erlport_test

#

that'll create a project

jolly drift
#

yeah we couldn't figure out how to build it with mix

tribal nymph
#

mix compile

#

then iex -S mix for a shell

jolly drift
#

mix compile gives

** (Mix) Could not find a Mix.Project, please ensure you are running Mix in a directory with a mix.exs file```
#

I could build a new project that I created with your above command

#

is that what you meant?

#

how do we add erlport as a dependency?

tribal nymph
#

let's start over

#

delete the erlport directory

#

mix new erlport_test

jolly drift
#

okay

tribal nymph
#

then cd erlport_test

jolly drift
#

sure

tribal nymph
#

then edit mix.exs

#
   defp deps do
     [
      {:erlport, "~> 0.11.0"}
     ]
   end
#

make deps that

jolly drift
#

okay

tribal nymph
#

then mix deps.get

#

mix compile

#

iex -S mix

#

now you can play with erlport

jolly drift
#

ahh got y a

#

that worked, thanks

tribal nymph
#

unlike python, elixir has a built-in dependency manager and build tool

#

so, then you should be able to do what we did above

#

(mix also allows you to build deployable releases)

jolly drift
#

word

#

thanks again. That's enough to get me started I think.

tribal nymph
#

ok, keep me posted