Fork of naskio/n8n-nodes-python - Python Function node for n8n with raw script execution and output.
Execute pure Python scripts in n8n and get raw execution results
This fork provides a fundamentally different approach to Python execution in n8n:
Original Node | This Fork (Raw) |
---|---|
Item-by-item processing | Single script execution |
Returns transformed items | Returns execution metadata |
Uses python-fire wrapper | Direct Python execution |
Hidden stdout/stderr | Full stdout/stderr capture |
Fire-based argument passing | Direct variable injection |
✅ Single Execution: Script runs once regardless of input item count
✅ Raw Output: Access to stdout, stderr, and exit codes
✅ Direct Input: All input items available as input_items
variable
✅ Environment Variables: Access to custom environment variables
✅ Configurable Python: Choose Python executable path
✅ Execution Metadata: Timestamps, success status, error details
The node returns a single item with execution results:
{
"exitCode": 0,
"stdout": "Output from print() statements",
"stderr": "Error messages and warnings",
"success": true,
"error": null,
"inputItemsCount": 3,
"executedAt": "2024-01-01T12:00:00.000Z"
}
# Available variables:
# - input_items: list of all input data
# - env_vars: dict of environment variables
import json
import sys
# Process input data
print(f"Processing {len(input_items)} items")
results = []
for item in input_items:
# Your processing logic here
processed = {"original": item, "processed": True}
results.append(processed)
# Output results (will appear in stdout)
print(json.dumps(results, indent=2))
# Exit with success
sys.exit(0)
npm install @zgxsuerwtmrhjzt/n8n-nodes-python-raw
Add to your n8n Dockerfile:
RUN cd /usr/local/lib/node_modules/n8n && npm install @zgxsuerwtmrhjzt/n8n-nodes-python-raw
See DEVELOPMENT_SETUP.md for development environment setup.
- Python 3.6+ installed and accessible
- n8n running environment
Write your Python script directly. Available variables:
-
input_items
: List of input data from previous nodes -
env_vars
: Dictionary of environment variables
Specify the Python executable:
-
python3
(default) python
/usr/bin/python3
/path/to/conda/envs/myenv/bin/python
Use the PythonEnvVars credential to provide environment variables to your script.
import json
import statistics
# Analyze input data
numbers = [item.get('value', 0) for item in input_items]
result = {
"count": len(numbers),
"mean": statistics.mean(numbers) if numbers else 0,
"median": statistics.median(numbers) if numbers else 0
}
print(json.dumps(result))
import requests
import json
# Call external API
response = requests.get("https://api.example.com/data")
if response.status_code == 200:
print(json.dumps(response.json()))
sys.exit(0)
else:
print(f"API call failed: {response.status_code}", file=sys.stderr)
sys.exit(1)
import os
import json
# Process files
processed_files = []
for item in input_items:
if 'filename' in item:
if os.path.exists(item['filename']):
processed_files.append(item['filename'])
result = {"processed_files": processed_files}
print(json.dumps(result))
This fork is based on n8n-nodes-python by Mehdi Nassim KHODJA.
Apache 2.0 with Commons Clause - see LICENSE.md
- Fork this repository
- Make your changes
- Update package.json with your npm username
- Test your changes
- Submit a pull request
For issues specific to this fork, please create an issue in this repository. For general n8n questions, refer to the n8n documentation.
Note: This is a fork with significant modifications. For the original item-processing behavior, use the original package.