Doumi.Port - A helper library that facilitates the usage of Python in Elixir

Doumi.Port is a helper library that facilitates the usage of Python in Elixir powered by Erlport, NimblePool.

It’s inspired by Export, but not just a wrapper of Erlport, will be a toolchain for using Python, Ruby in Elixir.

defmodule MyApp.Application do
  ...

  @impl true
  def start(_type, _args) do
    children = [
      ...
      {Doumi.Port.Pool, port: {Doumi.Port.Python, python_path: [...]}, name: MyApp.PythonPool}
    ]

    Supervisor.start_link(children, strategy: :one_for_one, name: MyApp.Supervisor)
  end
end

defmodule MyApp.Native do
  def add(a, b) do
    Doumi.Port.Pool.command(MyApp.PythonPool, :operator, :add, [a, b])
  end
end

> MyApp.Native.add(1, 2)
3

Thanks!

9 Likes

I will test it as soon as possible! :heart_eyes::heart_eyes:

I recommend you to link to the Doumi.Port repository and the Hex package in the post. It will be easier for the people to check them :smiling_face_with_three_hearts:.

1 Like

Oh, I forgot it. Thanks!!

1 Like

Nice, I might use it soon too…

I use poolboy with erlport, but I see You use nimble_pool instead :slight_smile:

1 Like

v0.2.0 is released!

use macro is added to make it easier.

defmodule MyApp.PythonPool do
  use Doumi.Port.Pool,
    port: {Doumi.Port.Python, python_path: [...]}
end

defmodule MyApp.Application do
  ...

  @impl true
  def start(_type, _args) do
    children = [
      ...
      MyApp.PythonPool
    ]

    Supervisor.start_link(children, strategy: :one_for_one, name: MyApp.Supervisor)
  end
end

defmodule MyApp.Native do
  def add(a, b) do
    MyApp.PythonPool.command(:operator, :add, [a, b])
  end
end
2 Likes

v0.4.0 is released!

  • It supports Ruby also.
  • mix doumi.port.init, mix doumi.port.setup is added.

# Create requirements.txt, .gitignores to ./priv/python

mix doumi.port.init --port python

# Add Python dependency

echo "pypdf2==3.0.1" >> ./priv/python/requirements.txt

# Install Python dependecies

mix doumi.port.setup --port python

You can install Python dependencies to your release with mix doumi.port.setup.

defmodule MyApp.MixProject do
  defp aliases do
    [
      ...,
      "release.setup": ["doumi.port.setup --port python", ...]
    ]
  end
end
...

# release setup (ex. install Python dependencies, compile assets)
RUN mix release.setup

...
4 Likes

there is an error when following the README

[notice] Application runtime_tools exited: :stopped
** (Mix) Could not start application doumi_port_demo: exited in: DoumiPortDemo.Application.start(:normal, [])
    ** (EXIT) an exception was raised:
        ** (KeyError) key :port not found in: [adapter: {Doumi.Port.Adapter.Python, [python_path: