Python in n8n's Code node: what works, what doesn't, and the alternatives
By Clément Lacaille (Tech-Bharat) · Published 27 July 2026 · updated 17 November 2026 · 8 min read · how we build and test
Server-Side Automation — €29
PDF guide in English on this topic · 30 pages · October 2026 edition · 14-day guarantee
Yes, the n8n Code node supports Python: since n8n 2.0 the Python option runs native CPython in a task runner, separate from the main n8n process, and the older Pyodide version was removed. The frame is tight: only two variables (_items and _item), no module allowed by default, and on a self-hosted instance a runners container in external mode.
n8n's Code node is best known for its JavaScript, but a selector at the top of the panel offers a second language: Python. For data teams and developers who think in list comprehensions rather than .map(), the temptation to write all transformation logic in Python is strong. It's possible, but within a tighter frame than it looks, and most tutorials still describe the Pyodide Python that n8n 2.0 removed. This guide covers what actually works on n8n 2, the concrete limits, and the serious alternatives when Python is genuinely required.

How n8n 2 runs Python: a task runner, no more Pyodide
Before n8n 2.0, the Python option ran through Pyodide, CPython compiled to WebAssembly inside the n8n process. That implementation was removed in n8n 2.0. Python now runs as a real Python process in a task runner, separate from the main n8n process (in a workflow file, the node's language is stored as "language": "pythonNative"). Three consequences:
- On a self-hosted instance, Python needs runners in external mode. The official n8n image contains no Python: in the default internal mode, a Python Code node fails with "Python runner unavailable: Python 3 is missing from this system". The fix is a second container from the
n8nio/runnersimage, at the same version as n8n, connected to n8n's task broker (N8N_RUNNERS_MODE=externalon n8n, a sharedN8N_RUNNERS_AUTH_TOKEN). - Nothing is allowed by default. The runners image's configuration file,
/etc/n8n-task-runners.json, sets both Python allowlists (N8N_RUNNERS_STDLIB_ALLOWandN8N_RUNNERS_EXTERNAL_ALLOW) to empty strings. Loops,sum(),len(), dicts andround()work;import jsonis refused with "Import of standard library module 'json' is disallowed", andopen()is not even defined. - On n8n Cloud, according to n8n's documentation, Python in the Code node cannot import any library, standard or third-party.
It is real CPython (the runners image ships Python 3.13), but in a locked-down sandbox that you open module by module.
The data-access syntax: _items, _item and brackets
In JavaScript, the Code node exposes $input, $json, $('Node Name'), $now. Native Python gets far less: only two variables.
| Mode | JavaScript | Python (n8n 2) |
|---|---|---|
| Run Once for All Items | $input.all() |
_items |
| Run Once for Each Item | $json |
_item["json"] |
| Another node's output | $('Get Customer').all() |
not available |
| Current date | $now |
not available |
The _input.all() and _json syntax found in older tutorials belonged to Pyodide and no longer exists. Items are plain dictionaries, so bracket notation is mandatory: _items[0].json.name fails with 'dict' object has no attribute 'json'; write _items[0]["json"]["name"].
The node must still return a list of dictionaries with a json key (and optionally binary). Forgetting that envelope remains mistake number one, in Python just as in JavaScript:
# Run Once for All Items — minimal structure
results = []
for item in _items:
results.append({
"json": {
"email": item["json"].get("email", "").strip().lower()
}
})
return results
In Run Once for Each Item, _item is the current item: modify it and return _item.
Three concrete examples
Transforming items with a list comprehension
The map/filter pattern reads very naturally in Python, and needs no import:
# Keep only orders > $100 and compute a discounted price
return [
{
"json": {
**item["json"],
"price_discounted": round(item["json"]["total"] * 0.9, 2)
}
}
for item in _items
if item["json"].get("total", 0) > 100
]
It's the direct equivalent of .filter().map() in JavaScript, a matter of taste and team habit, not capability.
Deduplicating on a key
A classic after combining several sources with a Merge node: removing duplicates on the email field while keeping the first occurrence. set() is a built-in, so this also works with the default empty allowlists:
seen = set()
unique = []
for item in _items:
key = item["json"].get("email", "").strip().lower()
if key and key not in seen:
seen.add(key)
unique.append({"json": item["json"]})
return unique
Parsing inconsistent dates
The standard library's datetime module makes date cleanup more pleasant than in vanilla JavaScript, but it is an import: on a self-hosted instance, add datetime to N8N_RUNNERS_STDLIB_ALLOW in the env-overrides of the runners' configuration file first (setting it as a container environment variable is not enough, the file wins). On n8n Cloud, this example will not run.
from datetime import datetime
FORMATS = ["%d/%m/%Y", "%Y-%m-%d", "%d %b %Y"]
def parse_date(raw):
for fmt in FORMATS:
try:
return datetime.strptime(raw.strip(), fmt).date().isoformat()
except (ValueError, AttributeError):
continue
return None
return [
{"json": {**item["json"], "date_normalized": parse_date(item["json"].get("date"))}}
for item in _items
]
This kind of normalization is exactly what you'd place before an Excel or CSV export node, so every row shares the same date format.

The real limits to know before writing everything in Python
Empty allowlists by default. Every standard-library module (json, re, datetime…) and every third-party package must be allowed explicitly in the runners' configuration file. List what you need rather than using *: with N8N_RUNNERS_STDLIB_ALLOW=*, code in the Code node can use os, subprocess and make HTTP calls from the runners container.
pandas and numpy: self-hosted only, and not out of the box. They are not installed in n8nio/runners. You build a runners image that installs them with uv pip install, then allow them, along with the modules pandas imports itself. Our guide to native Python with pandas and numpy walks through the Dockerfile and the allowlist.
Fewer helpers than JavaScript. No $now, no access to another node's output, no $execution: if your logic needs them, compute them upstream (an Edit Fields node, an expression) or stay in JavaScript.
Runner settings matter. A Code node task stops after N8N_RUNNERS_TASK_TIMEOUT (300 seconds by default in n8n 2.45.7), and the runners container needs its own GENERIC_TIMEZONE, otherwise dates computed in code follow America/New_York.
No network or files by design. No requests, no open(). External calls go through a dedicated node, HTTP Request with its pagination handling, integration nodes, and so on. The Python Code node is for transforming data, not fetching it.
When to prefer JavaScript (spoiler: by default)
JavaScript remains the sensible default for the Code node: all n8n variables, no allowlist to maintain, no extra container, and nearly all community examples are written in JS.
Should you therefore force a Python team to write JavaScript? Not necessarily. A classic study by Lutz Prechelt, An Empirical Comparison of Seven Programming Languages (IEEE Computer, 2000 — see the study), compared the same programs written in seven languages and reached a now-famous conclusion: the variance in productivity and quality between developers far exceeds the variance between languages. In other words, the dominant factor isn't the language — it's how well the person writing it masters it. For a Code node doing pure data transformation, pick the language your team reads and debugs fastest — both get the job done.
So the real dividing line isn't "JS or Python" but "Code node or not": as soon as the logic requires network, files, or libraries you can't install in the runners (always the case on Cloud), neither language is enough.
When Python is truly required: the two serious alternatives
A FastAPI or Flask microservice called via HTTP Request
The cleanest architecture: your Python code runs in its own service (with pandas, scikit-learn, pdfplumber — whatever you need), exposed over HTTP, and n8n calls it like any other API. It is also the only route to the full Python ecosystem on n8n Cloud.
# minimal FastAPI microservice
from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI()
class Payload(BaseModel):
items: list[dict]
@app.post("/transform")
def transform(payload: Payload):
# here: pandas, ML, the entire Python ecosystem
return {"items": [enrich(i) for i in payload.items]}
On the n8n side, an HTTP Request node POSTs the items and collects the result. Remember to configure timeout and retry on that call, and to protect the endpoint with a token stored in an n8n credential rather than hardcoded. This is the approach you'll find in advanced document pipelines: the RAG Assistant Pack ($119) follows exactly this separation principle — n8n orchestrates, while heavy processing (embeddings, extraction) is delegated to specialized services called over HTTP.
The Execute Command node on a self-hosted instance
On a self-hosted instance, the Execute Command node can run a script directly: python3 /scripts/transform.py. It requires no extra service, but comes with non-negotiable precautions:
- the node is unavailable on n8n Cloud, blocked by default since n8n 2.0, and runs commands with the n8n process's privileges — never inject a value coming from a webhook without strict validation (command injection risk);
- the official n8n image has no Python and no package manager: Python and its dependencies go into a custom image you version;
- wrap the call with an Error Workflow: a script exiting with an error code must not fail silently.
Our PDF guide Server-Side Automation runs both self-hosted routes on n8n 2.45.7: the external runners set-up, the exact allowlist pandas needed (and what it opens up), and a Python script on a CSV through Execute Command, with the real outputs.
Decision table: JS, Python in the Code node, or microservice
| Criterion | JavaScript (Code node) | Python (Code node, n8n 2) | Python microservice |
|---|---|---|---|
| Simple data transformation | ✅ Recommended default | ✅ Fine if the team is Python-first | ❌ Overkill |
| Set-up on self-hosted | None | External runners container, allowlists | A service to deploy |
| Standard library imports | ✅ | ⚠️ Each module to allow; none on Cloud | ✅ |
| pandas, numpy, ML | ❌ | ⚠️ Self-hosted only, custom runners image | ✅ Full ecosystem |
| Network / file access | ❌ (by design) | ❌ (unless you allow *) |
✅ |
| n8n variables ($now, other nodes) | ✅ | ❌ (_items, _item only) |
Passed in the payload |
| Works on n8n Cloud | ✅ | ✅ without imports | ✅ (service hosted separately) |
In summary
Since n8n 2.0, the Code node's Python is native CPython in a task runner, and Pyodide is gone: read items with _items or _item and brackets, forget _input.all() and _json. Out of the box it can loop, filter, deduplicate and add up, but cannot import anything, json included; on a self-hosted instance you open modules one by one in the runners' configuration file, and pandas needs a custom runners image. On n8n Cloud, or the day your logic needs network, files or the whole Python ecosystem, don't bend the Code node: a FastAPI microservice called via HTTP Request, or a well-guarded Execute Command on self-hosted, will do the job cleanly and durably.
FAQ
Frequently asked questions
Can you actually use Python in n8n?
Yes. Since n8n 2.0, the Code node's Python option runs native CPython in a task runner; the old Pyodide (WebAssembly) Python was removed. Only two variables exist: _items (Run Once for All Items) and _item (Run Once for Each Item), read with brackets: item["json"]["email"]. On a self-hosted instance, Python needs an external runners container (n8nio/runners image), because the official n8n image has no Python.
Can you import pandas or numpy in n8n's Python Code node?
Not by default. In the stock n8nio/runners image, both allowlists are empty: even import json is refused, and pandas and numpy are not installed. On a self-hosted instance you can build a runners image with pandas and numpy and allow them in the runners' configuration file; on n8n Cloud, the documentation says no library can be imported, standard or third-party.
Why does import json fail in the Python Code node?
Because the runners image's configuration file, /etc/n8n-task-runners.json, sets N8N_RUNNERS_STDLIB_ALLOW and N8N_RUNNERS_EXTERNAL_ALLOW to empty strings for Python. The error reads « Import of standard library module 'json' is disallowed ». Setting the variable on the runners container is not enough: the file's env-overrides win, so the allowlist has to be changed in that file.
Should you pick JavaScript or Python for the Code node?
JavaScript is the recommended default: it has every n8n variable ($json, $now, $('Node')…), while Python only gets _items and _item, and JavaScript needs no allowlist to be useful. Python makes sense when your team is clearly more fluent in it, or when you need a library such as pandas on a self-hosted instance where you control the runners image.