Python Task

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

Overview

This node executes custom Python 3.10 code once per execution, allowing users to manipulate the input data items by adding, removing, changing, or replacing them. It is useful for scenarios where complex data transformations or computations need to be performed using Python within an n8n workflow. For example, users can run Python scripts to process JSON data, perform calculations, or integrate with Python libraries to enrich workflow data.

Use Case Examples

  1. Transforming input JSON data using Python logic.
  2. Performing calculations or data enrichment on workflow items.
  3. Running Python scripts that return modified or new items for further workflow processing.

Properties

Name Meaning
Python Code The Python code to execute. This code runs once and should return an array of items, each containing a 'json' property with the data to output.

Output

JSON

  • json - The main output data structure. Each item must contain a 'json' object representing the processed data.

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, the node throws an error with the exit code and message.
  • Ensure Python 3.10 is installed and accessible in the system PATH.
  • Check that the Python code returns a valid JSON array of items, each with a 'json' object.
  • If 'continueOnFail' is enabled, errors are returned as items with an 'error' property instead of stopping execution.

Links

Discussion