Example
This example demonstrates how to use the Python Agent to take two values as input and output the sum of two input values.
Drag the Python Agent onto the canvas, link the input endpoint to our simulated numeric data and the output to the event printer, and save the Data Stream.

Select the Agent and click Configure. Keep the default Collection.

Tick Use Environment Variables. Alternatively, you could enter the Python Home and Path values manually.

Type the Python Version which installed on the Stream Host machine.

Drag a Python code file to the Agent Python File property. The input mapping grid will be auto-populated with the input values from the file. In this case, the code calculates the sum of two numbers.

Map each input to an attribute from the input payload. In this case, set num1 to Reading1 and num2 to Reading2.

Enter the name of the output variable and select it's data type. In this case, the value is saved in the variable sum, with a type of Double. This can be confirmed by looking at the Python file.

The output name must match the variable name in the Python file.
Apply the changes, save the Data Stream and publish it.

Let's look at the Live Data View. The Sum column is appended to the incoming events. It contains the Python file's variable, which is the sum of Reading1 and Reading2.

File | Link | Security Key |
---|---|---|
Data Stream | Python Example.xuc | C0mp|ex123 |
Python Code File | simplemaths.py | |
Last modified 9mo ago