Code Node
The code node is used to execute code within your workflows and provides full flexibility to connect to systems which aren't built-in integrations and to execute any custom functions.
Python Environment and Custom Packages
The code node provides a python environment and includes standard request-handling and commonly used libraries. It currently runs on Python 3.10.14. If a package is required which is not natively included in the python environment, you can install it using subprocess
:
import subprocess
import sys
# Ensure the steamspypi package is installed
def install_package(package_name):
try:
__import__(package_name)
except ImportError:
print(f"{package_name} not found. Installing...")
subprocess.check_call([sys.executable, "-m", "pip", "install", package_name])
install_package("steamspypi")
Replace steamspypi
with the name of the package you want to install.
Code Node Output
Output from the code node is a JSON object with the following structure:
"code_1": {
"data": {
"results": "Hello World from Function",
"stdout": "Hello World from standard output\n",
"stderr": "",
"error": "",
"sandbox_id": "sandbox-5067"
},
"error": null,
"successfull": true,
"successful": true
}
Referencing Code Output
When selecting the output of a code node in a downstream node, you are given 3 options:
code_node_name
code_node_name.data.stdout
code_node_name.data.results
Using Model Output in a Code Node
It's very common to take the output from a model node and pass it into a code node. This is often done to format the response, check for specific conditions or pass the response to custom integrations through APIs. The easiest way to do this is with the following:
model_output = f"""{{model_node}}"""
... the rest of your code ...
Last updated