Python Runtime icon

Python Runtime

Execute Python scripts using system Python runtime

Overview

This node allows users to execute Python code or run Python script files directly from an n8n workflow using the system's Python runtime. It is useful for automating tasks that require Python scripting, such as data processing, calling Python libraries, or integrating Python-based logic into workflows.

Common scenarios include:

  • Running small Python snippets dynamically without creating separate files.
  • Executing existing Python scripts with optional command-line arguments.
  • Integrating Python computations or data transformations within an automation pipeline.

For example, a user can input a Python print statement to quickly generate output or specify a path to a Python file that performs complex data analysis.

Properties

Name Meaning
Python Code The Python code snippet to execute directly (used when operation is "Execute Script").
Command Arguments Additional command-line arguments to pass to the Python interpreter or script.
Python Path The system path or command to invoke the Python executable (default is python3).

Output

The node outputs an array of JSON objects, each containing:

  • stdout: The trimmed standard output produced by the Python execution.
  • stderr: The trimmed standard error output from the Python process.
  • success: A boolean indicating whether the execution was successful (true) or failed (false).
  • error: Present only if execution failed; contains the error message.

This output structure allows downstream nodes to handle both successful results and errors gracefully.

Dependencies

  • Requires a system Python runtime accessible via the specified Python Path (default: python3).
  • No additional external services or API keys are needed.
  • The environment where n8n runs must have permission to execute child processes.

Troubleshooting

  • Common issues:

    • Incorrect Python path: If the specified Python executable path is wrong or not installed, the node will fail to execute.
    • Syntax errors in Python code: Malformed Python code will cause execution errors.
    • File path errors (if running a file): Specifying a non-existent or inaccessible file path will result in failure.
  • Error messages:

    • Errors from the Python interpreter (e.g., syntax errors) appear in the stderr field.
    • Execution failures return success: false with an error message describing the problem.
  • Resolutions:

    • Verify the Python executable path is correct and accessible.
    • Test Python code independently before embedding it in the node.
    • Ensure file paths are absolute and accessible by the n8n process.
    • Use the Command Arguments property carefully to avoid injection or formatting issues.

Links and References

Discussion