Runs custom Python code. Useful for logic not covered by existing blocks.

Overview

The Python code block allows you to write Python code to extend your blueprint’s functionality.

Available variables and libraries

Python code block can access the following global variables and libraries:

Return values from the Python code block

To return a value from a Python code block and store it in the result execution environment variable, you must use the set_output function.

Anything that runs in the block but is not returned in the set_output function does not get passed to the next block.

Example: Calculate the average of a list of numbers and return the result

The example python code below shows how to return a value from the Python code block. It calculates the average of a list of numbers and returns the result the next block by using the set_output function.

The following Set state block stores the result in the final_result state variable to display in the UI.

def calculate_mean(numbers):
    return sum(numbers) / len(numbers)

average = calculate_mean(state["numbers"])
set_output(average)

Fields

NameTypeControlDefaultDescriptionOptionsValidation
CodeCodeTextarea-The code to be executed.--

End states

Below are the possible end states of the block call.

NameFieldTypeDescription
Success-successThe event handler execution was successful.
Error-errorThe event handler execution wasn’t successful.