Python Integration
Mix.install([
{:py_cell, github: "NduatiK/py_cell"}
])
Introduction
This is an example of using the py_cell module. It allows for some level of integration with Python 3 code.
By installing the module, you gain access to the Python smart cell. This allows you to write python code and expose a single function within this code. That function can be executed by making a single call to PyCell.run/2
.
It uses the python3
command on the host machine to evaluate the python code, and has access to the modules available to this installation.
Function Call Example
require PyCell
code = """
def add(a, b):
return a + b
"""
PyCell.open_port("add", code)
PyCell.run("add", [1, 2])
Module Import Example
require PyCell
code = """
import math
def get_pi():
return math.pi
"""
PyCell.open_port("get_pi", code)
PyCell.run("get_pi", [])