Examples

The following examples can be found on this page:

CPU Only processing

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 and rename the Agent. Link the input endpoint to our simulated numeric data, and the output to the printer. Save the Data Stream.

Step 2: Configure General

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

Step 3: Configure Details

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

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

Refer to Pre-requisites for more information on using Environment Variables.

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.

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 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.

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

See the Import, Export, and Clone - XMPro article for steps to import a Data Stream.

GPU Accelerated Processing

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.

Refer to configuration to understand all configuration options of this Agent.

Follow the pre-requisites for GPU Accelerated processing before proceeding with the steps below.

Step 1: Add the Agent

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.

Step 2: Configure General

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

Step 3: Configure Details

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

Select the Python Home.

Refer to Pre-requisites for more information on Environment Variables.

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.

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 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.

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

See the Import, Export, and Clone - XMPro article for steps to import a Data Stream.

Last updated