What problem does it solve?
Python development inside n8n Code nodes is constrained by no external libraries, strict data-flow rules, and the need for a consistent return structure. This guide explains how to write robust Python code that runs safely within Code nodes while respecting n8n's data-passing conventions.
Core Features & Use Cases
- Standard library only environment: operate without external dependencies and leverage built-in modules like json, datetime, re, base64, hashlib, and more.
- Data access patterns: use _input.all(), _input.first(), _input.item, and _node to compose batch, single-item, or cross-node workflows.
- Webhook payload handling: correctly access webhook data via the body of the payload to avoid KeyError and misreads.
- Consistent return format: always return a list of objects with a single json key, e.g. [{"json": {...}}], for downstream nodes.
- Typical use cases: data transformation, validation, simple aggregations, and per-item processing within Code nodes.
Quick Start
Create a Python Code node, pull inputs with _input.all(), transform them, and return a properly formatted list of dictionaries with a 'json' key.