Write Python code in n8n Code nodes. Use when writing Python in n8n, using _input/_json/_node syntax, working with standard library, or need to understand Python limitations in n8n Code nodes.
Add this skill
npx mdskills install czlonkowski/n8n-code-pythonComprehensive Python guidance for n8n with clear patterns, critical limitations, and practical workarounds
Expert guidance for writing Python code in n8n Code nodes.
Use JavaScript for 95% of use cases.
Python in n8n has NO external libraries (no requests, pandas, numpy).
When to use Python:
When to use JavaScript (recommended):
_input.all(), _input.first(), _input.item_json["body"][{"json": {...}}]This skill emphasizes error prevention:
These 5 errors are the most common in Python Code nodes.
This skill activates when you:
Example queries:
Quick start and overview
Complete data access patterns
_input.all() - Process all items_input.first() - Get first item_input.item - Current item (Each Item mode)_node["Name"] - Reference other nodesAvailable Python modules
10 production-tested patterns
Top 5 errors with solutions
This skill works with:
get_node_essentialsAfter using this skill, you should be able to:
_input.all(), _input.first(), _input.item_json["body"][{"json": {...}}].get() for dictionary accessall_items = _input.all()
first_item = _input.first()
current_item = _input.item # Each Item mode only
other_node = _node["NodeName"]
webhook = _input.first()["json"]
body = webhook.get("body", {})
name = body.get("name")
# ✅ Use .get() with defaults
value = data.get("field", "default")
# ❌ Risky - may raise KeyError
value = data["field"]
# ✅ Correct format
return [{"json": {"result": "success"}}]
# ❌ Wrong - plain dict
return {"result": "success"}
# ✅ Available
import json
import datetime
import re
import base64
import hashlib
# ❌ NOT available
import requests # ModuleNotFoundError!
import pandas # ModuleNotFoundError!
import numpy # ModuleNotFoundError!
webhook = _input.first()["json"]
body = webhook.get("body", {})
return [{
"json": {
"name": body.get("name"),
"email": body.get("email"),
"processed": True
}
}]
all_items = _input.all()
active = [
{"json": {**item["json"], "filtered": True}}
for item in all_items
if item["json"].get("status") == "active"
]
return active
import statistics
all_items = _input.all()
amounts = [item["json"].get("amount", 0) for item in all_items]
return [{
"json": {
"total": sum(amounts),
"average": statistics.mean(amounts) if amounts else 0,
"count": len(amounts)
}
}]
import json
data = _input.first()["json"]["body"]
json_string = data.get("payload", "{}")
try:
parsed = json.loads(json_string)
return [{"json": parsed}]
except json.JSONDecodeError:
return [{"json": {"error": "Invalid JSON"}}]
Problem: No requests library
Workaround: Use HTTP Request node or JavaScript
Problem: No pandas or numpy
Workaround: Use list comprehensions and standard library
Problem: No psycopg2, pymongo, etc.
Workaround: Use n8n database nodes (Postgres, MySQL, MongoDB)
Problem: No beautifulsoup4 or selenium
Workaround: Use HTML Extract node
[{"json": {...}}]if items:)Use Python when:
Use JavaScript instead when:
Beginner:
_input patterns.get()Intermediate: 4. Study STANDARD_LIBRARY.md - Know what's available 5. Try COMMON_PATTERNS.md examples - Use proven patterns 6. Learn ERROR_PATTERNS.md - Avoid common mistakes
Advanced: 7. Combine multiple patterns 8. Use standard library effectively 9. Know when to switch to JavaScript 10. Write production-ready code
Questions?
Related Skills:
Version: 1.0.0 Status: Production Ready Compatibility: n8n Code node (Python mode)
Part of the n8n-skills project.
Conceived by Romuald Członkowski
Remember: JavaScript is recommended for 95% of use cases. Use Python only when you specifically need Python's standard library features.
Install via CLI
npx mdskills install czlonkowski/n8n-code-pythonN8n Code Python is a free, open-source AI agent skill. Write Python code in n8n Code nodes. Use when writing Python in n8n, using _input/_json/_node syntax, working with standard library, or need to understand Python limitations in n8n Code nodes.
Install N8n Code Python with a single command:
npx mdskills install czlonkowski/n8n-code-pythonThis downloads the skill files into your project and your AI agent picks them up automatically.
N8n Code Python works with Claude Code, Claude Desktop, Cursor, Vscode Copilot, Windsurf, Continue Dev, Codex, Gemini Cli, Amp, Roo Code, Goose, Opencode, Trae, Qodo, Command Code. Skills use the open SKILL.md format which is compatible with any AI coding agent that reads markdown instructions.