Comment on page
Examples
The following examples can be found on this page:
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 and rename the Agent. Link the input endpoint to our simulated numeric data, and the output to the printer. Save the Data Stream.

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

Keep the default Use Server Variables (ticked) and the default Accelerator (CPU Only).

Select the Python Home, Python Path, and Python DLL Path.

Click Select File and locate your Python Script. 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 its 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 Agent Example.xuc | C0mp|ex123 |
Python Code File | simplemaths.py | |
This example demonstrates how to use the Python Agent to use a GPU to accelerate the process to take two values as input and output the sum of two input values.
Drag the Python Agent onto the canvas and rename the Agent. Link the input endpoint to our simulated numeric data and the output to the printer. Save the Data Stream.

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

Keep the default Use Server Variables (ticked), but set the accelerator to GPU Accelerated.

Select the Python Home.

Click Select File and locate your Python Script. 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 its 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.

In GPU Accelerated processing, you must print the output variable in the format print({VariableName}:{VariableValue}) inside your Python script.
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 Agent GPU Example.xuc | C0mp|ex123 |
Python Code File | simplemaths_gpu.py | |
Last modified 1mo ago