Python Raw icon

Python Raw

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

Python Raw

AI-generated

Overview

This node executes a custom Python script within an n8n workflow, allowing users to run Python code with access to input data, credentials, system environment variables, and binary files from previous nodes. It supports resource limits (memory and CPU), error handling options, output file processing, and detailed debugging modes. The node is useful for integrating Python-based data processing, automation, or custom logic into n8n workflows, such as data transformation, API interaction, or file manipulation.

Use Case Examples

  1. Processing input JSON data with Python to transform or analyze it.
  2. Using API keys from credentials to call external services within Python code.
  3. Handling binary files from previous nodes for image or document processing.
  4. Generating output files from Python scripts and automatically including them in workflow output.

Properties

Name Meaning
Include Input Variables Include input data from previous nodes as individual variables and an array of all input items.
Include Credential Variables Include variables from selected credentials as environment variables and individual variables in the script.
Include System Environment Include selected system environment variables from the n8n process in the script environment variables.
System Environment Variables Comma-separated list of system environment variable names to include when 'Include System Environment' is enabled.
Python Code The custom Python script code to execute.
Hide Variable Values Replace variable values with asterisks in generated scripts for security.
Python Executable Path to the Python executable to use for running the script.
Execution Timeout (minutes) Maximum time allowed for script execution before forcefully terminating it.
Memory Limit (MB) Maximum memory the Python script can use; exceeding this limit terminates the script.
CPU Limit (%) Maximum CPU usage percentage allowed for the script across all available cores.
Error Handling How to handle Python script errors and non-zero exit codes (return details, throw error, or ignore exit code).
Debug/Test Mode Choose debug and testing options for script development and troubleshooting.
Script Export Format File format for script export in debug mode (Python .py or text .txt).
Script Generation Options Options to include input items array, environment variables dictionary, and system environment variables in the generated script.
File Processing Configure processing of binary files from previous nodes, including access method, max file size, metadata inclusion, and auto-cleanup.
Output File Processing Configure automatic detection and processing of files generated by the Python script, including max file size, auto-cleanup, metadata inclusion, and file detection mode.
Parse Output How to parse the stdout output for easier data access (raw string, JSON, lines, or smart auto-detect).
Parse Options Options for parsing JSON output, including handling multiple JSON objects, stripping non-JSON text, and fallback on parse error.
Execution Mode Choose how many times to execute the Python script (once for all items or once per item).
Pass Through Input Data Include original input data in the output alongside Python script results.
Pass Through Mode How to include input data in the output when pass through is enabled (merge with result, separate field, or multiple outputs).
File Debug Options Advanced debugging options for file processing issues, including detailed info about input/output files, system info, and directory listings.

Output

JSON

  • exitCode - Exit code of the Python script execution (0 indicates success).
  • stdout - Standard output from the Python script execution as a string.
  • stderr - Standard error output from the Python script execution as a string.
  • success - Boolean indicating if the script executed successfully (exit code 0).
  • error - Error message if the script failed, otherwise null.
  • inputItemsCount - Number of input items processed by the script.
  • executedAt - Timestamp when the script execution completed.
  • includeInputVariables - Boolean indicating if input variables were included in the script execution.
  • parseOutput - Method used to parse the script's stdout output.
  • executionMode - Execution mode used (once for all items or once per item).
  • parsed_stdout - Parsed output from stdout if parsing was enabled and successful.
  • parsing_success - Boolean indicating if parsing of stdout was successful.
  • parsing_error - Error message if parsing of stdout failed.
  • outputFiles - Array of files generated by the Python script and processed as output.
  • outputFilesCount - Number of output files processed.
  • fileDebugInfo - Detailed debug information about file processing if enabled.
  • pythonError - Detailed Python error information if the script failed.
  • detailedError - Detailed error message including exit code and Python error details.
  • outputFileError - Error message related to output file processing if any.
  • outputFileProcessing - Configuration details about output file processing if enabled.

Dependencies

  • Python executable (configurable path)
  • Optional credentials for environment variables

Troubleshooting

  • Ensure the Python executable path is correct and accessible.
  • Check that the Python script syntax is valid; syntax errors are reported in stderr.
  • If using credentials, verify they are properly configured and accessible.
  • Memory and CPU limits may cause script termination if exceeded; adjust limits accordingly.
  • Output file processing requires correct expected filename configuration.
  • Debug modes can help diagnose issues by providing detailed execution and environment information.

Discussion