Python

Live provides a console to execute python code via REST integration

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:

Python plugin valid at the admin

Configure the server host name and port:

Python server host and port configuration

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:

Python console

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

Python console results and expressions

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

Python console actions

Python Exceptions are captured and indicated in the response:

Python console exceptions

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

Restricted modules

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”:

Event persitence

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

Events consumed

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

Tensorflow and Keras machine learning libraries code execution

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

Events consumed 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:

Python console structured result

Multiple files persistence

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

Python tree of files and actions

Last updated

Was this helpful?