Help us improve
Share bugs, ideas, or general feedback.
From n8n-autopilot
Provides guidance for writing Python code in n8n Code nodes, covering data access, return format, and limitations like no external libraries.
npx claudepluginhub neurawork-git/n8n-autopilot --plugin n8n-autopilotHow this skill is triggered — by the user, by Claude, or both
Slash command
/n8n-autopilot:n8n-code-pythonThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Expert guidance for writing Python code in n8n Code nodes.
Guides writing Python code in n8n Code nodes. Covers data access patterns, return format, standard library usage, and when to choose JavaScript instead.
Guides writing Python code for n8n Code nodes using _input.all(), _json syntax, standard library only, required output formats, and run modes for data processing.
Writes Python code for n8n Code nodes using _input syntax, standard library (regex, hashlib, statistics), and Run Once modes. Use when JS lacks needed features or user prefers Python.
Share bugs, ideas, or general feedback.
Expert guidance for writing Python code in n8n Code nodes.
Use JavaScript for 95% of use cases. Only use Python when:
statistics)JavaScript has $helpers.httpRequest(), Luxon DateTime, and better n8n docs.
# Basic template for Python Code nodes
items = _input.all()
processed = []
for item in items:
processed.append({
"json": {
**item["json"],
"processed": True,
"timestamp": datetime.now().isoformat()
}
})
return processed
_input.all(), _input.first(), _input.item[{"json": {...}}] format_json["body"]# ❌ NOT AVAILABLE
import requests # ModuleNotFoundError
import pandas # ModuleNotFoundError
# ✅ AVAILABLE (standard library only)
import json
import datetime
import re
import base64
import hashlib
import urllib.parse
import math
import random
import statistics
Workarounds:
statistics module for basic stats, or switch to JavaScript# All items
all_items = _input.all()
# First item
first_item = _input.first()
data = first_item["json"]
# Each item mode
current_item = _input.item
# Other nodes
webhook_data = _node["Webhook"]["json"]
http_data = _node["HTTP Request"]["json"]
# ❌ WRONG
name = _json["name"] # KeyError!
# ✅ CORRECT
name = _json["body"]["name"]
# ✅ SAFER
name = _json.get("body", {}).get("name", "Unknown")
# ✅ Single result
return [{"json": {"field": value}}]
# ✅ List comprehension
return [{"json": item["json"]} for item in _input.all()]
# ✅ Empty
return []
WRONG: return {"json": {...}} (no list), return [{"field": value}] (no json key)
Uses _input, _json, _node, _now helpers.
items = _input.all()
now = _now # Built-in datetime
return [{"json": {"count": len(items), "timestamp": now.isoformat()}}]
Uses _items, _item only — no helpers.
return [{"json": item["json"]} for item in _items]
Use Python (Beta) for better n8n integration.
items = _input.all()
total = sum(item["json"].get("amount", 0) for item in items)
valid = [item for item in items if item["json"].get("amount", 0) > 0]
return [{"json": {"total": total, "count": len(valid)}}]
import re
all_emails = []
for item in _input.all():
emails = re.findall(r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b', item["json"].get("text", ""))
all_emails.extend(emails)
return [{"json": {"emails": list(set(all_emails)), "count": len(set(all_emails))}}]
from statistics import mean, median, stdev
values = [item["json"].get("value", 0) for item in _input.all() if "value" in item["json"]]
if values:
return [{"json": {"mean": mean(values), "median": median(values), "stdev": stdev(values) if len(values) > 1 else 0}}]
else:
return [{"json": {"error": "No values found"}}]
[{"json": {...}}].get() to avoid KeyError_json["email"] ❌ → _json["body"]["email"] ✅.get() for dictionary accessvalue = item["json"].get("x") or 0print() (appears in browser console)import json # json.loads(), json.dumps()
from datetime import datetime, timedelta # datetime.now(), timedelta(days=1)
import re # re.findall(), re.sub()
import base64 # base64.b64encode(), b64decode()
import hashlib # hashlib.sha256(text.encode()).hexdigest()
import urllib.parse # urllib.parse.urlencode(), urlparse()
from statistics import mean, median, stdev