0CodeKit icon

0CodeKit

A toolbox of no-code utilities

Actions108

Overview

This node provides a versatile "Code" resource operation to run Python code snippets within the workflow. It allows users to execute custom Python scripts dynamically, optionally passing variables into the script for more flexible and context-aware execution.

Common scenarios where this node is beneficial include:

  • Running data transformation or analysis scripts written in Python.
  • Executing Python code that interacts with external APIs or services.
  • Automating tasks that require Python's extensive libraries.
  • Testing or prototyping Python code snippets directly inside an n8n workflow.

For example, you could write a Python script to process incoming JSON data, perform calculations, or manipulate strings, then output the results for further processing downstream.

Properties

Name Meaning
Code The Python code snippet to execute. This is a required multiline string input where you write your Python script.
Code Variables A collection of named variables to pass into the Python code. Each variable has:
- Variable Name or ID: Selects a variable defined in the code editor or specify an expression.
- Value: The value assigned to the variable, passed into the Python environment during execution.

Output

The node outputs a JSON array containing the result(s) returned by the executed Python code. The exact structure depends on what the Python script returns but typically includes the processed data or any output generated by the script.

If multiple items are processed, the output will be an array of results corresponding to each input item.

There is no indication that this node outputs binary data.

Dependencies

  • Requires an API key credential for authentication with the external service powering the code execution (referred generically as "an API key credential").
  • The node internally calls an external API endpoint to run the Python code, so internet connectivity and valid credentials are necessary.
  • No additional local dependencies are required since the execution happens remotely.

Troubleshooting

  • Common issues:
    • Invalid Python syntax in the provided code will cause execution errors.
    • Passing undefined or mismatched variable names in "Code Variables" may lead to runtime errors.
    • Network or authentication failures if the API key credential is missing or invalid.
  • Error messages:
    • Syntax errors from Python code will be returned as error messages; review and correct the code accordingly.
    • Authentication errors indicate problems with the API key credential setup.
    • Timeout or network errors suggest connectivity issues with the external service.
  • To resolve errors, verify the Python code correctness, ensure all variables used in the code are properly defined and passed, and confirm the API key credential is configured correctly in n8n.

Links and References

  • n8n Expressions Documentation — for using expressions in variable definitions.
  • General Python documentation or tutorials for writing valid Python code snippets.

Discussion