Erlang Python
Apache 2.0Bidirectional integration between Erlang and Python. Call Python from Erlang. Call Erlang from Python. True parallelism.
Bidirectional Integration
Erlang / Elixir
- py:call()
- py:eval()
- py:async_call()
- py:stream()
Shared State (ETS)
Accessible from both sides
Python
- from erlang import func
- erlang.call()
- state_get/set()
- state_incr()
Features
True Parallelism
Sub-interpreters (Python 3.12+) or free-threaded Python (3.13+). No GIL contention.
Async/Await
Call Python async functions, gather results, stream from async generators.
Dirty NIF Execution
Python runs on dirty schedulers. Never blocks the BEAM.
Bidirectional Calls
Python calls Erlang. Erlang calls Python. Reentrant callbacks supported.
Streaming
Iterate over Python generators chunk-by-chunk. Memory efficient.
AI/ML Ready
Examples for embeddings, semantic search, RAG, and LLMs.
Code Examples
%% Call Python functions from Erlang
{ok, 4.0} = py:call(math, sqrt, [16]).
%% Evaluate expressions
{ok, 45} = py:eval(<<"sum(range(10))">>).
%% Async calls
Ref = py:call_async(math, factorial, [100]),
{ok, Result} = py:await(Ref).
%% Stream from generators
{ok, [0,1,4,9,16]} = py:stream_eval(<<"(x**2 for x in range(5))">>). # Python calling Erlang functions
from erlang import my_func, state_get, state_set
# Call registered Erlang functions
result = my_func(10, 20)
# Use shared state (ETS-backed)
state_set('user:123', {'name': 'Alice', 'score': 100})
user = state_get('user:123')
# Atomic counters
from erlang import state_incr
count = state_incr('page_views') %% Register Erlang functions callable from Python
py:register_function(my_func, fun([X, Y]) -> X + Y end).
%% Python can now import and call it
py:exec(<<"
from erlang import my_func
result = my_func(10, 20) # Returns 30
">>). Parallelism Modes
| Mode | Python Version | Parallelism |
|---|---|---|
| Free-threaded | 3.13+ (nogil) | True parallel, no GIL |
| Sub-interpreter | 3.12+ | Per-interpreter GIL |
| Multi-executor | Any | GIL contention (fallback) |
Use Cases
ML/AI Integration
Use PyTorch, TensorFlow, sentence-transformers, or any ML library. Run inference, generate embeddings, build RAG pipelines.
- + Semantic search
- + RAG with LLMs
- + Embeddings at scale
BEAM Parallelism
Fan out Python work across lightweight Erlang processes. 10x speedup for parallel workloads.
- + Process-per-request
- + Parallel map
- + Linear scaling
Async I/O
Call Python async functions with async_call/async_await. Stream from async generators.
- + aiohttp requests
- + Async database queries
- + Concurrent API calls
Data Processing
Leverage pandas, numpy, scipy for computation. Erlang handles orchestration.
- + Pandas DataFrames
- + NumPy arrays
- + Scientific computing
Installation
{deps, [
{erlang_python, {git, "https://github.com/benoitc/erlang_python.git", {branch, "main"}}}
]}. Requires Erlang/OTP 27+ and Python 3.12+