Python Code in Workflows
Python Nodes
Overview

The Python node allows executing custom Python code which makes it an essential tool for adding flexible, custom logic to your workflows. This node is ideal for running data processing, API interactions and other custom Python functions while ensuring safe execution through restricted imports and controlled built-in functions.
Configuration
Name: Customizable name for identifying this node.
Source Code: The Python code to execute, provided in the run function format.
Example:
def run(input_data: dict):
if input_data["is_request_call_allowed"]:
import requests
response = requests.get(input_data["url"])
if response.status_code in input_data["allowed_status_codes"]:
return response.json()
If no custom input transformer is specified for a Python node, the passed data can be accessed using the input_data["input_data"]
structure.
Description: Short description of the node’s functionality.
Input
input_data: Dictionary containing key-value pairs for the code execution. For example, in the provided code, input_data might contain keys like
url
,is_request_call_allowed
, andallowed_status_codes
.
Output
content: The output of the run function. This can be any Python-compatible data structure, such as string, integer, list, or dict. The output can then be transferred to other nodes in the workflow or traced for debugging.
Execution Environment and Security
This node uses a restricted Python environment:
Allowed Imports: Only specific modules are permitted for import, such as requests, json, math, datetime, and other utility libraries listed here. Custom imports outside of the allowed modules will raise an ImportError.
Restricted Built-ins: Only safe and limited built-in functions are available for use (e.g.,
len
,map
,sum
, etc.), while potentially unsafe functions are disabled. Custom or restricted access guards (_getattr_
,_getitem_
,_getiter_
) are enforced to prevent unauthorized actions.
Usage Example

Drag and Drop the Python node from the toolbox.
Write the required python code within the run function format in the Source Code section.
Connect an Input node to pass inputs (
url
,is_request_call_allowed
, andallowed_status_codes
) into input_data for the Python node.Connect an Output node or other downstream nodes to process the content output generated by the Python node, allowing easy integration with subsequent steps in your workflow.
Last updated