View Source Doumi.Port
Doumi.Port
is a helper library that facilitates the usage of Python in Elixir powered by Erlport, NimblePool.
도우미(Doumi) means "helper" in Korean.
why-pool
Why pool?
https://medium.com/stuart-engineering/how-we-use-python-within-elixir-486eb4d266f9
Every time we run Python code through ErlPort, ErlPort starts an OS process, this is rather inefficient and expensive. To avoid this trap, we went looking for some pooling mechanism ...
why-nimblepool
Why NimblePool?
https://github.com/dashbitco/nimble_pool#nimblepool
You should consider using NimblePool whenever you have to manage sockets, ports, or NIF resources and you want the client to perform one-off operations on them. For example, NimblePool is a good solution to manage HTTP/1 connections, ports that need to communicate with long-running programs, etc.
usage
Usage
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
installation
Installation
The package can be installed by adding doumi_port
to your list of dependencies in mix.exs
:
def deps do
[
{:doumi_port, "~> 0.2.0"},
# To support Python >= 3.11, erlport should be overridden
# https://github.com/erlport/erlport/pull/13
{:erlport, github: "nallwhy/erlport", ref: "6f5cb45", override: true}
]
end
todo
TODO
- [x] Support use macro
- [ ] Support Ruby
- [ ] Support mix tasks that help setup Python, Ruby in applications
doumi
Doumi*
All Doumi libraries:
- Doumi.Phoenix.SVG: A helper library that generates Phoenix function components from SVG files.
- Doumi.Phoenix.Params: A helper library that supports converting form to params and params to form
- Doumi.URI.Query: A helper library that encode complicated query of URI.
copyright-and-license
Copyright and License
Copyright (c) 2023 Jinkyou Son (Json)
This work is free. You can redistribute it and/or modify it under the terms of the MIT License. See the LICENSE.md file for more details.