type

PyFuncs

const class PyFuncs : Obj

Axon functions for py

methods

py

Create a new PySession instance.

pyDefine

Define a variable to be available to python code running in the session.

pyEval

Evalue the given python statement in the session, and return the result.

pyExec

Execute the given python code in the session and return the python session.

pyInit

Initialize the python session by calling the given func to do any one-time setup of the python session.

pyTimeout

Set the timeout for pyEval().

Slot Details

py

@Axon { admin=true }
static PySession py(Dict? opts := null)

Create a new PySession instance. Options:

  • image: name of the Docker image to run. By default, the lib will try to run the following images in this order:
    1. ghcr.io/haxall/hxpy:<ver> (where ver = current library Haxall version)
    2. ghcr.io/haxall/hxpy:latest
    3. ghcr.io/haxall/hxpy:main
  • network: the name of the Docker network you want the container to join.
  • logLevel: log level of the hxpy python process in Docker. Valid values are WARN, INFO, DEBUG, (default='WARN')

The default timeout for pyEval() is 5min. Use pyTimeout() to change this timeout.

Sessions created in the context of a task are persistent, meaning they will not be closed until the task is killed.

pyDefine

@Axon { admin=true }
static PySession pyDefine(PySession py, Str name, Obj? val)

Define a variable to be available to python code running in the session.

pyEval

@Axon { admin=true }
static Obj? pyEval(PySession py, Str stmt)

Evalue the given python statement in the session, and return the result. The session will be closed unless it is running in a task.

pyExec

@Axon { admin=true }
static PySession pyExec(PySession py, Str code)

Execute the given python code in the session and return the python session. Note: python exec() does not return a value, so use pyEval() if you need the result of running a python statement. This method is primarily useful for declaring functions that you want available when using pyEval().

pyInit

@Axon { admin=true }
static PySession pyInit(PySession py, Fn fn)

Initialize the python session by calling the given func to do any one-time setup of the python session. If pyInit() has already been called on this session, then the callback is not invoked.

Typically, this func is used in the context of a task since the python session in a task is persistent. This allows to do any one-time pyExec() or pyDefine() when the task is first creatd.

pyTimeout

@Axon { admin=true }
static PySession pyTimeout(PySession py, Number? val)

Set the timeout for pyEval().