I’ve recently released v0.2.0 of my Python interop library, Snex.
This version rolls up all work-in-progress improvements that have been driven by half a year of use in a production Elixir system. Finally had some time to fully clean them up, and release a version that I’m proud of.
Snex is a library for interfacing with Python code in a tightly integrated way. The code is run by sidecar Python interpreters, managed by an Elixir runtime, and communicating through a light Snex Python runtime.
A big design goal of the library is to achieve devx similar to pythonx, while avoiding GIL-related issues and maintenance burdens of C-level integration - where both the BEAM and CPython APIs are constantly moving targets.
Highlights
-
Run multiple Python interpreters in separate OS processes, preventing GIL issues from affecting your Elixir application.
-
Leverages
uvto manage Python versions and dependencies, embedding them into your application’s release for consistent deployments. -
A powerful and efficient interface with explicit control over data passing between Elixir and Python processes.
-
Supports custom Python environments,
asynciocode, and integration with external Python projects. -
Built on stable foundations, so future versions of Python or Elixir are unlikely to require Snex updates to use - they should work day one!
Quick example
defmodule SnexTest.NumpyInterpreter do
use Snex.Interpreter,
pyproject_toml: """
[project]
name = "my-numpy-project"
version = "0.0.0"
requires-python = ">=3.10,<3.15"
dependencies = ["numpy>=2"]
"""
end
{:ok, inp} = SnexTest.NumpyInterpreter.start_link()
{:ok, env} = Snex.make_env(inp)
{:ok, 6.0} =
Snex.pyeval(env,
"""
import numpy as np
matrix = np.fromfunction(lambda i, j: (-1) ** (i + j), (s, s), dtype=int)
""",
%{"s" => 6},
returning: "np.linalg.norm(matrix)")
Links
GitHub: GitHub - kzemek/snex:
Easy and efficient Python interop for Elixir
Hex: snex | Hex
HexDocs: snex v0.2.0 — Documentation






















