Links

Example

This example demonstrates how to use the Python Agent to take two values as input and output the sum of two input values.
Refer to configuration to understand all configuration options of this Agent.

Step 1: Add the Agent

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.

Step 2: Configure General

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

Step 3: Configure Details

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.
Refer to Pre-requisites for more information on Environment Variables.
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.

Step 4: Mappings

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.

Step 5: Results

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.

Files

File
Link
Security Key
Data Stream
Python Example.xuc
C0mp|ex123
Python Code File
simplemaths.py
See the Import, Export, and Clone - XMPro article for steps to import a Data Stream.