Python

Live provides a console to execute python code via REST integration

Dependencies required:

live-python-server-1.0.0+

plugin-py-1.1.0+

live-3.24.0+

The python server can run via Docker container image available on Intelie Marketplace with some code validation and common machine learning libraries pre installed:

  • Tensorflow/Keras

  • Numpy

  • Pandas

  • Scikit-Learn

  • Matplotlib

  • Pytorch

The integration does not support image rendering.

First install plugin-py and check that is valid at the admin of plugins:

Configure the server host name and port:

The option to open python console will be available at the header:

It is possible to execute code or drag and drop a python file into the console area:

The result will be shown for each print statement call invocation:

It is possible to clear, export, copy and paste files on the upper options:

Python Exceptions are captured and indicated in the response:

There are also a few modules, which are considered harmful, that are restricted by default:

If the option “persist as result event” is checked the result will be persisted as events on Live storage. It is possible to custom the event_type to be persisted or use default “py”:

By executing the query __src:'pysrc' __type:'py' on pipes console it is possible to see the persisted results:

It is possible to execute for example Tensorflow and Keras statements and save results as other event types:

By consuming the evets with __src:’pysrc’ it is possible to find result events with different event_types:

Reading data from Live storage

By executing run_query inside the console it is possible to retrieve data from events with Live incoming events:

from pipes.query import run_query

data = run_query(expression="=> random() * 200 as value every 2 seconds", span="last 10 seconds")

for i in data: print(data)

Or it is possible to retrieve data from an asset:

from pipes.query import run_query

data = run_query(expression="=> well('mywell') at the end", span="")

for i in data: print(data)

Structured result

For structured result as a object use send_event method specifying the object with fields as example below:

Multiple files persistence

Live provides the multiple files support for executing and saving python statements

plugin-py-1.3.0+ required

Last updated