export v0.1.1 Export.Python

Wrapper for ruby.

Example

defmodule SomePythonCall do
  use Export.Python

  def call_python_method
    # path to our python files
    {:ok, py} = Python.start(python_path: Path.expand("lib/python"))

    # call "upcase" method from "test" file with "hello" argument
    py |> Python.call("test", "upcase", ["hello"])

    # same as above but prettier
    py |> Python.call(upcase("hello"), from_file: "test")
  end
end

Summary

Functions

Start Python instance with the default options

Start Python instance with options. The instance will be registered with name. The options argument should be a map with the following options

Start Python instance with name and options. The instance will be registered with name. The options argument should be a map with the following options

The same as start/0 except the link to the current process is also created

The same as start/1 except the link to the current process is also created

The same as start/2 except the link to the current process is also created

Stop Python instance

Functions

call(instance, file, function, arguments)

Call Python function.

Parameters

  • instance: pid witch is returned by one of the start function
  • file: file to run ruby function from
  • function: name of the function
  • arguments: arguments to pass to the function

Example

# call "upcase" method from "test" file with "hello" argument
py |> Python.call("test", "upcase", ["hello"])
start()

Start Python instance with the default options.

Returns {:ok, pid}.

Examples

iex> Export.Python.start()
{:ok, pid}
start(options)

Start Python instance with options. The instance will be registered with name. The options argument should be a map with the following options.

Python options

  • python: Path to the Python interpreter executable
  • python_path: The Python modules search path. The Path variable can be a string in PYTHONPATH format or a list of paths.
start(name, options)

Start Python instance with name and options. The instance will be registered with name. The options argument should be a map with the following options.

Python options

  • python: Path to the Python interpreter executable
  • python_path: The Python modules search path. The Path variable can be a string in PYTHONPATH format or a list of paths.
start_link()

The same as start/0 except the link to the current process is also created.

start_link(options)

The same as start/1 except the link to the current process is also created.

start_link(name, options)

The same as start/2 except the link to the current process is also created.

stop(instance)

Stop Python instance

Macros

call(instance, expression, list)

Call Python function.

Parameters

  • instance: pid witch is returned by one of the start function
  • expression: function expression to execute in ruby world
  • from_file: file to run ruby function from

Example

# call "upcase" method from "test" file with "hello" argument
py |> Python.call(upcase("hello"), from_file: "test")