Skip to content
background-image background-image

Python Processor with Local Variables

Support for Local Variables was added to the Python Processor in version 3.2.0.

Let's go through an example of how Local Variables work with the Python Processor. This example demonstrates how Local Variables with nullable values are handled by the Python Processor. The code first logs the input data (expecting them to be empty), then outputs values for each data type, assuming they are initially null, and finally returns data with assigned values for each type. This shows that initially nullable fields can be populated with specific values.

If you prefer a more interactive learning experience, check out our video tutorial on the YouTube channel


Configuration

To start, let's create a Data Schema for Local Variables. Create a schema of all data types—nullable and non-nullable.

HELP_ExampleLibrary_LocalVariables_PythonVariables_LVSchema

Add Local Variables Schema to the Task, and fill in the default values for nullable variables.

HELP_ExampleLibrary_LocalVariables_PythonVariables_LVSchemaValues

Add a Task:

  • Connector: Python Processor
  • Connector action: Default action

Add a Step:

The Step does not require an input schema. Create an output schema "SchemaNull", wich will also consist of all data types, but only nullable ones.

HELP_ExampleLibrary_LocalVariables_PythonVariables_OutputSchema

  • Output schema: SchemaNull
  • Configuration:
import json

log.warn(f"InputData: {json.dumps(INPUT_DATA)} (Expect: null)");

log.warn(f"TextNull: ${LocalVariable.TextNull} "); 
log.warn(f"IntegerNull: ${LocalVariable.IntegerNull} "); 
log.warn(f"DoubleNull: ${LocalVariable.DoubleNull} "); 
log.warn(f"BooleanNull: ${LocalVariable.BooleanNull} "); 
log.warn(f"DateNull: ${LocalVariable.DateNull} "); 
log.warn(f"Base64Null: ${LocalVariable.Base64Null} "); 
log.warn(f"JsonNull: ${LocalVariable.JsonNull} "); 

return [
    { 
      "TextNull": "Alice",
      "IntegerNull": 999,
      "DoubleNull": 55.66,
      "BooleanNull": True,
      "DateNull": "10/16/2036 09:22:33",
      "Base64Null": "Alice",
      "JsonNull": "[]"
     }
]

Save the configuration.

HELP_ExampleLibrary_LocalVariables_PythonVariables_StepDetails

Now open Set local variables by clicking on the variable icon in the upper right corner of the Step details. Then Assign a specific value from checklist only for Nullable Variables. Save it.

HELP_ExampleLibrary_LocalVariables_PythonVariables_StepLVSchemaValues

Now we have completed all the settings. Let's close the step and Publish the Task. Start the Task and go to the History View.


Result

As a result, we have a successfully completed task. We can see that the values in the Local Variable Schema have changed to those we specified in the Step configuration. If we disable Local Variables for the Step, we will get the values assigned to the Local Variables in the Task.

HELP_ExampleLibrary_LocalVariables_PythonVariables_FinishedTask


This example illustrates how Local Variables with nullable values are processed by the Python processor, showing that initially nullable fields can be populated with specific values after configuration. It emphasizes the transition from null to defined values within the Local Variable Schema. That's all from this example.