domains / software-engineering / n8n-python-code-node / n8n-code-python
The two copies describe different n8n Python runtimes and contradict each other on core facts. The first copy (czlonkowski) targets n8n 2.x native Python (pythonNative), where legacy helpers like _input/_json are gone, only _items/_item exist, and imports are blocked by default. The second copy (sickn33) targets the older Pyodide 'Python (Beta)' node, where _input/_json/_node are valid and standard library imports like json/datetime/re are available. Because they disagree on the available variables, the import policy, and the node version, crowning one would hide a real alternative for users on the other version.
| Repository | Path |
|---|---|
| czlonkowski/n8n-skills | skills/n8n-code-python/SKILL.md |
| sickn33/agentic-awesome-skills | plugins/agentic-awesome-skills-claude/skills/n8n-code-python/SKILL.md |
| Role | Repository | Path |
|---|---|---|
| peer | czlonkowski/n8n-skills | skills/n8n-code-python/SKILL.md |
| peer | sickn33/agentic-awesome-skills | plugins/agentic-awesome-skills-claude/skills/n8n-code-python/SKILL.md |
| adapter | sickn33/agentic-awesome-skills | plugins/agentic-awesome-skills/skills/n8n-code-python/SKILL.md |
| adapter | sickn33/agentic-awesome-skills | skills/n8n-code-python/SKILL.md |
# n8n Python Code Node
## Determine the Node Version
1. Check the n8n version and the Code node's `language` setting.
- If `language` is `"pythonNative"` (n8n 2.x), follow the **Native Python** section.
- If the node is labeled "Python (Beta)" or uses Pyodide, follow the **Legacy Pyodide** section.
## Native Python (n8n 2.x, `pythonNative`)
1. **Variables:** Use only `_items` (Run Once for All Items) or `_item` (Run Once for Each Item). Each is a plain dict with `"json"` and `"pairedItem"` keys. Access via dict syntax: `it["json"]["field"]`.
2. **Imports:** Blocked by default. Do not use `import` unless the self-hosted admin has allowlisted modules. Verify with a test node if unsure.
3. **Sandbox Limits:** `eval`, `exec`, `open`, `class` definitions, and `__class__` access are denied. Use `isinstance`, dict methods, and functions instead of classes.
4. **No n8n Helpers:** `$('Node')`, `$jmespath`, Luxon, and `this.helpers.httpRequest` are unavailable. Use JavaScript or other nodes for these tasks.
5. **Return Shape:** Return a list of dicts (all-items mode) or a single dict (each-item mode). Include `"pairedItem"` if downstream nodes use `$('Node').item`.
## Legacy Pyodide (Python Beta)
1. **Variables:** Use `_input`, `_json`, `_node`, `_now`, `_today`, and `_jmespath` as needed.
2. **Imports:** Standard library modules (`json`, `datetime`, `re`, `base64`, `hashlib`, `urllib.parse`, `math`, `random`, `statistics`) are available. External packages are not.
3. **Workarounds:** Use the HTTP Request node for HTTP calls, the HTML Extract node for scraping, and JavaScript for advanced date/time or n8n-specific helpers.
## General Guidance
- Prefer JavaScript or native n8n nodes (Set, Filter, IF, HTTP Request, Crypto, Date & Time) when they can accomplish the task.
- Use Python only when the user explicitly requests it or when the logic maps well to Python-specific standard library features (e.g., `statistics`).
- Test-run the node to verify behavior, especially for `pairedItem` handling in native Python.