Python code
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:
- State variables
- Execution environment variables
- Pre-installed Python libraries
- Functions you’ve defined in your
main.py
file
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.
Fields
Name | Type | Control | Default | Description | Options | Validation |
---|---|---|---|---|---|---|
Code | Code | Textarea | - | The code to be executed. | - | - |
End states
Below are the possible end states of the block call.
Name | Field | Type | Description |
---|---|---|---|
Success | - | success | The event handler execution was successful. |
Error | - | error | The event handler execution wasn’t successful. |