benoitc

benoitc

Because it runs on the BEAM, you inherit Erlang/Elixir distribution for free.
Run Python on any node:

# Execute on remote node
:rpc.call(:"worker@host", :py, :call, [:numpy, :dot, [matrix_a, matrix_b]])

# Local call
{:ok, result} = :py.call(:sklearn, :fit, [model, data])

# Async task
{:ok, ref} = :py_event_loop.create_task(:heavy_compute, :run, [data])
# ... do other work ...
{:ok, result} = :py_event_loop.await(ref)

Key features:

  • Distributed by default via rpc:call
  • Async Task API (uvloop-inspired)
  • Channel API for bidirectional streaming
  • OWN_GIL subinterpreters (Python 3.12+)
  • Virtual environment management
  • ASGI/WSGI support

erlang_python 2.1 is out with async tasks and channel-based streaming.

Hex: erlang_python | Hex
GitHub:

https://github.com/benoitc/erlang-python

Apache 2.0 licensed.

First 6 of 6 Posts Switch mode

LostKobrakai

LostKobrakai

I’m curious about how this is different to pythonx?

benoitc

benoitc OP

erlang_python embeds Python with true parallelism via sub-interpreters (each with its own GIL) or free-threading (no GIL). You get bidirectional communication: channels, async/await, and Python calling back into Erlang. Pythonx is designed for Livebook/Elixir with a single Python interpreter and shared GIL, which is enough for notebooks but limited for concurrent production workloads.

Afaik erlang_python is built to run Python applications inside the Erlang VM and inherit its efficiency.

Asd

Asd

Nice library!

I tried to read the code, but the project is huge and NIF part is around 15k lines of C code (thats around 5% of whole OTP C code size).

I think that it was generated, given that project is +90k lines in a month from you. Given that, it is strange to see that it is 2.1.0 version already. For me it feels more like its pre 1.0.0 version, given that it was rapidly developed and I assume was not used by anybody except you yet

Do you have any benchmarks? I am curious about how it compares to Snex, which uses erlang ports to spawn multiple interpreters and has very very tiny NIF surface. I think that erlang-python should be faster

Do you use it in production? What’s your use-case?

benoitc

benoitc OP

you can run benchmarks in the example folder:

➜  erlang-python git:(main) ✗ escript examples/bench_channel_async.erl

========================================
Channel Benchmark: Sync vs Async
========================================

System Information:
  Erlang/OTP: 28
  Python: 3.9.6 (default, Dec  2 2025, 07:27:58)
[Clang 17.0.0 (clang-1700.6.3.2)]

Python channel helpers ready.

--- Sync Channel Benchmark ---
(Erlang send + NIF try_receive - pure Erlang)

    Size |   Throughput |     Avg (us)
--------------------------------------
      64 |     10416667 |         0.10
    1024 |      6180470 |         0.16
   16384 |       833472 |         1.20

--- Async Task API Benchmark ---
(py_event_loop:create_task + await using stdlib)

      Operation |   Throughput |     Avg (us)
--------------------------------------------
      math.sqrt |       101174 |         9.88
     concurrent |       374111 |         2.67

--- Sync vs Async Comparison ---
(Channel operations: NIF sync vs py:call)

Message size: 1024 bytes, Iterations: 1000

         Method |    Time (ms) |   Throughput
---------------------------------------------
       NIF sync |         0.20 |      5102041
   py:call sync |         4.38 |       228154
     async task |         8.10 |       123426
    spawn batch |         3.38 |       295508

NIF sync is 22.4x faster than py:call
NIF sync is 41.3x faster than async task
Spawn batch is 2.4x faster than sequential async

========================================
Benchmark Complete
========================================

It’s used in a coming product and you can find it used in barrel_embed and some other products like hornbeam. recently I only merged and fixed . I’m pushing version when i introduce breaking change, also. The moment I start to use it for supported products it becomes 1.0.

Asd

Asd

Oh, so it takes around 5ms to do py:call(math, sqrt, [2.0])! Thats very impressive. By the way, https://hornbeam.dev/ looks very cool and promising too!

I will try to play with it locally on my machine some time soon

gtcode

gtcode

This is really cool — there’s a lot of Python+Elixir crossover happening right now.

I built a Python FFI for Elixir: https://github.com/nshkrdotcom/snakebridge

Then put together a sample project to test whether pooling Python workers from the BEAM side buys anything over straight Python. Turns out non-GIL Python is pretty capable on its own: https://github.com/nshkrdotcom/slither

That said, the whole stack is still a prototype — glued together with gRPC and architecturally rough. Feel free to steal anything useful. Really glad to see your project.

— All posts loaded —

Where Next? Top

Trending in Announcing Top

bluzky
You may know https://ui.shadcn.com/, a UI component library for React. I really love it’s design style and components. I’ve built some co...
387 15136 120
New
woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination with...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
shahryarjb
The Chelekom project is a library of Phoenix and LiveView components generated via Mix tasks to fit developer needs seamlessly. One of i...
New
woylie
Phoenix components for pagination, sortable tables and filter forms with Flop and (optionally) Ecto. pagination cursor pagination sorta...
New
kip
Please say hi to a new lib, Astro that aims to deliver easy-to-consume astronomy calculations of practical use. For now it only calculat...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New

Other Trending Topics Top

juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
akoutmos
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
alexslade
Fly’s CEO posted this recently - Turn And Face The Strange · The Fly Blog It says that Fly is going all-in on sprites, which is a worry ...
New
bartblast
Hey folks, I just published a post about Hologram’s funding and where the project goes next - the short version: Curiosum as Main Spons...
New

We're in Beta

About us Mission Statement