Python Function

Run custom Python 3.10 code which gets executed once and allows you to add, remove, change and replace items

Overview

This node allows users to run custom Python 3.10 code within an n8n workflow. The Python code is executed once regardless of the number of input items, enabling users to manipulate, add, remove, or replace items in the workflow. It is useful for scenarios where complex data transformations or integrations with Python libraries are needed, such as data processing, calling Python APIs, or performing calculations that are easier in Python.

Use Case Examples

  1. Transforming input data using Python logic and returning modified items.
  2. Executing Python scripts that interact with external Python libraries or APIs.
  3. Performing batch data processing or complex calculations within a workflow.

Properties

Name Meaning
Python Code The Python code to execute. This code runs once and can manipulate the input items. It must return an array of items, each containing a 'json' property as an object.

Output

JSON

  • json - The main output data structure. It is an array of items, each with a 'json' property containing the processed data as an object.

Dependencies

  • Requires Python 3.10 installed on the system to execute the Python code.
  • Optionally uses environment variables provided via credentials for the Python environment.

Troubleshooting

  • Errors occur if the Python code does not return an array of items or if items do not have a 'json' object property.
  • If the Python script exits with an error code, the node throws an error with the exit code and message.
  • Ensure Python 3.10 is installed and accessible in the system PATH as 'python3'.
  • If environment variables are used, ensure they are correctly formatted and provided via credentials.

Links

Discussion