
N8n Code Python
Write correct Python inside n8n Code nodes when automation workflows need stdlib-heavy transforms the user explicitly wants in Python.
Overview
n8n-code-python is an agent skill for the Build phase that teaches how to write Python in n8n Code nodes using _input, json items, and stdlib within n8n’s beta Python limits.
Install
npx skills add https://github.com/czlonkowski/n8n-skills --skill n8n-code-pythonWhat is this skill?
- Documents n8n Python Code node basics: _input.all(), item json shape, and return processed arrays
- States JavaScript-first guidance—Python only when stdlib or user preference clearly wins
- Explains limitations versus JavaScript helpers (httpRequest, Luxon) so builders avoid wrong runtime choice
- Quick-start template for iterating items and attaching processed flags and ISO timestamps
- Skill recommends JavaScript for 95% of n8n Code node use cases
Adoption & trust: 2.6k installs on skills.sh; 5.3k GitHub stars; 2/3 security scanners passed (skills.sh audits).
What problem does it solve?
You asked your agent for Python in an n8n Code node and got broken syntax, wrong globals, or a language choice that skips n8n’s better JavaScript helpers.
Who is it for?
Builders maintaining n8n automations who insist on Python stdlib for a specific Code node step.
Skip if: Most n8n logic that should stay in JavaScript for helpers, Luxon dates, and community examples—the skill itself recommends JS for ~95% of cases.
When should I use this skill?
Write Python code in n8n Code nodes, use _input/_json/_node syntax, or need Python limitations in n8n when the user specifically requests Python.
What do I get? / Deliverables
You ship working Python Code node snippets—or a justified switch to JavaScript—with correct item iteration and return shapes for the workflow.
- Runnable Python Code node script returning processed item arrays
- Language-choice rationale when JavaScript is the better fit
Recommended Skills
Journey fit
How it compares
Companion to generic n8n JavaScript guidance—use when the user explicitly requests Python, not as the default automation language.
Common Questions / FAQ
Who is n8n-code-python for?
Solo builders and indie operators using n8n who need accurate Python inside Code nodes without relearning n8n’s item model.
When should I use n8n-code-python?
When wiring or debugging Build-phase n8n workflows and the user specifically wants Python, regex/hashlib/statistics-style stdlib, or _input/_json/_node syntax help.
Is n8n-code-python safe to install?
Check the Security Audits panel on this Prism page; workflow code can call network and process sensitive JSON, so review snippets before running in production n8n.
SKILL.md
READMESKILL.md - N8n Code Python
# Python Code Node (Beta) Expert guidance for writing Python code in n8n Code nodes. --- ## ⚠️ Important: JavaScript First **Recommendation**: Use **JavaScript for 95% of use cases**. Only use Python when: - You need specific Python standard library functions - You're significantly more comfortable with Python syntax - You're doing data transformations better suited to Python **Why JavaScript is preferred:** - Full n8n helper functions ($helpers.httpRequest, etc.) - Luxon DateTime library for advanced date/time operations - No external library limitations - Better n8n documentation and community support --- ## Quick Start ```python # Basic template for Python Code nodes items = _input.all() # Process data processed = [] for item in items: processed.append({ "json": { **item["json"], "processed": True, "timestamp": datetime.now().isoformat() } }) return processed ``` ### Essential Rules 1. **Consider JavaScript first** - Use Python only when necessary 2. **Access data**: `_input.all()`, `_input.first()`, or `_input.item` 3. **CRITICAL**: Must return `[{"json": {...}}]` format 4. **CRITICAL**: Webhook data is under `_json["body"]` (not `_json` directly) 5. **CRITICAL LIMITATION**: **No external libraries** (no requests, pandas, numpy) 6. **Standard library only**: json, datetime, re, base64, hashlib, urllib.parse, math, random, statistics --- ## Mode Selection Guide Same as JavaScript - choose based on your use case: ### Run Once for All Items (Recommended - Default) **Use this mode for:** 95% of use cases - **How it works**: Code executes **once** regardless of input count - **Data access**: `_input.all()` or `_items` array (Native mode) - **Best for**: Aggregation, filtering, batch processing, transformations - **Performance**: Faster for multiple items (single execution) ```python # Example: Calculate total from all items all_items = _input.all() total = sum(item["json"].get("amount", 0) for item in all_items) return [{ "json": { "total": total, "count": len(all_items), "average": total / len(all_items) if all_items else 0 } }] ``` ### Run Once for Each Item **Use this mode for:** Specialized cases only - **How it works**: Code executes **separately** for each input item - **Data access**: `_input.item` or `_item` (Native mode) - **Best for**: Item-specific logic, independent operations, per-item validation - **Performance**: Slower for large datasets (multiple executions) ```python # Example: Add processing timestamp to each item item = _input.item return [{ "json": { **item["json"], "processed": True, "processed_at": datetime.now().isoformat() } }] ``` --- ## Python Modes: Beta vs Native n8n offers two Python execution modes: ### Python (Beta) - Recommended - **Use**: `_input`, `_json`, `_node` helper syntax - **Best for**: Most Python use cases - **Helpers available**: `_now`, `_today`, `_jmespath()` - **Import**: `from datetime import datetime` ```python # Python (Beta) example items = _input.all() now = _now # Built-in datetime object return [{ "json": { "count": len(items), "timestamp": now.isoformat() } }] ``` ### Python (Native) (Beta) - **Use**: `_items`, `_item` variables only - **No helpers**: No `_input`, `_now`, etc. - **More limited**: Standard Python only - **Use when**: Need pure Python without n8n helpers ```python # P