Python Function (Raw)

Run custom Python script once and return raw output (exitCode, stdout, stderr)

Overview

This node executes a custom Python script once, using the input data provided as a variable within the script. It is useful for scenarios where users want to run arbitrary Python code to process or analyze input data, perform custom computations, or integrate Python-based logic into their workflow. For example, users can manipulate input JSON data, call Python libraries, or generate custom output by writing their own Python code.

Use Case Examples

  1. Processing a list of input items to generate a summary report in Python.
  2. Running a Python script to transform input JSON data and output results.
  3. Executing custom Python code that interacts with environment variables and input data.

Properties

Name Meaning
Python Code The custom Python script to execute. The script runs once and receives input data as the variable 'input_items'. Environment variables are also available as 'env_vars'. This property allows multiline Python code input.
Python Executable The path to the Python executable to use for running the script. Can be 'python3', 'python', or a full path to a Python interpreter.

Output

JSON

  • exitCode - The exit code of the Python script process.
  • stdout - The standard output produced by the Python script.
  • stderr - The standard error output produced by the Python script.
  • success - Boolean indicating if the script exited successfully (exit code 0).
  • error - Error message if the script failed to execute properly.
  • inputItemsCount - The count of input items passed to the script.
  • executedAt - Timestamp when the script was executed.

Dependencies

  • Requires a Python interpreter available at the specified path.
  • Optionally uses environment variables from an API key credential to set environment variables for the Python process.

Troubleshooting

  • If the Python executable path is incorrect or Python is not installed, the node will fail to run the script.
  • If the Python script exits with a non-zero code, the node throws an error unless 'continue on fail' is enabled.
  • Errors in the Python code itself will cause the script to fail; users should ensure their Python code is syntactically correct and handles input data properly.
  • If environment variables are malformed or missing, the script may not behave as expected.

Discussion