n8n-code-python
यह क्या करती है
यह स्किल n8n 2.x के लिए Code नोड में Python कोड लिखने में मदद करती है। यह उन लोगों के लिए है जो JavaScript की जगह Python चाहते हैं या पुराने टेम्पलेट से कॉपी किया कोड ठीक कर रहे हैं।
कब इस्तेमाल करें
- ✓जब आप सिर्फ़ n8n Code नोड में Python चाहते हों।
- ✓जब n8n 2.x पर जाने के बाद पुराने टेम्पलेट का Python कोड NameError के साथ टूट जाए।
- ✓जब Python Code नोड सुरक्षा उल्लंघन, ब्लॉक किए गए इम्पोर्ट या गायब बिल्ट-इन फ़ंक्शन की रिपोर्ट करे।
Skill का लिंक
https://github.com/czlonkowski/n8n-skills/blob/main/skills/n8n-code-python/SKILL.mdइसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।
कैसे इस्तेमाल करें
सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।
पेस्ट करने के लिए तैयार मैसेज
Claude Code, Codex या Cursor के लिए: प्रोजेक्ट फ़ोल्डर में चलाएँ और skill इंस्टॉल हो जाएगी।
SKILL.md डाउनलोड करें और अपने एजेंट के skills फ़ोल्डर में रखें।
AI से क्या माँगें: उदाहरण
“मेरे n8n Python Code नोड में _input पर NameError आ रही है, नए वर्ज़न के लिए इसे कैसे अपडेट करूँ?”
हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।
यह कैसे काम करती है
यह समझाती है कि n8n 2.x में Python नेटिव रूप से चलता है और कम बिल्ट-इन सहायक हैं, नए इस्तेमाल होने वाले वेरिएबल दिखाती है, और बताती है कि मानक लाइब्रेरी के इम्पोर्ट डिफ़ॉल्ट रूप से ब्लॉक होते हैं।
तकनीकी सामग्री (मूल SKILL.md)
लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।
Python Code Node (native)
Since n8n 2.0 the Code node's Python runs as native Python in a task runner (language: "pythonNative"). The old Pyodide "Python (Beta)" is gone, and with it every n8n helper it had:
_input, _json, _node, _now, _today and _jmespath all raise NameError now. Code copied
from old templates, forum posts or older docs usually breaks on this.
JavaScript first — stronger than before
Native Python gives you two variables and plain Python, and by default no imports: no
json, datetime or re. Everything n8n-specific ($('Node'), $jmespath, Luxon,
this.helpers.httpRequest, static data) exists only in JavaScript. Use Python only when the user
explicitly asks for it. Even then, first check whether an expression, Edit Fields, or a native
node (Crypto, Date & Time, HTML, XML) does the job. See n8n-code-javascript and the transform
gatekeeper in n8n-expression-syntax.
Quick start
# Run Once for All Items (default mode)
return [
{"json": {"name": it["json"]["name"], "revenue": it["json"]["revenue"]}}
for it in _items
if it["json"].get("active")
]
# Run Once for Each Item
row = _item["json"]
return {"json": {**row, "name_upper": (row.get("name") or "").upper()}}
Node config: {"language": "pythonNative", "mode": "runOnceForAllItems" | "runOnceForEachItem", "pythonCode": "..."} on n8n-nodes-base.code typeVersion 2.
The only inputs: _items and _item
| Mode | Variable | Shape |
|---|---|---|
| Run Once for All Items | _items |
list of plain dicts {"json": {...}, "pairedItem": {...}} |
| Run Once for Each Item | _item |
one plain dict {"json": {...}, "pairedItem": {...}} |
- Each variable exists only in its own mode.
_itemsin each-item mode (or_itemin all-items mode) raisesNameError. - Dict access only.
it["json"]["name"]orit["json"].get("name").it.json.nameraisesAttributeError: 'dict' object has no attribute 'json'. - No other nodes. There is no
_node/$('Node')equivalent. If you need data from another branch, bring it in with Merge first, or read it in JavaScript. - Webhook payloads are under
["body"]:_items[0]["json"].get("body", {}).get("email"). - Binary data isn't covered here. Read and write binary in JavaScript (see n8n-binary-and-data).
- pairedItem: returning
_items/_itemkeeps it. When you build new dicts and downstream uses$('Node').item, add"pairedItem": {"item": i}to each returned item. That isn't verified on native Python yet, so test-run before relying on it. - Missing keys: prefer
.get(key, default).row["missing"]raisesKeyError.
Migration table for legacy code:
| Legacy (Pyodide) | Native |
|---|---|
_input.all() |
_items |
_input.first()["json"] |
_items[0]["json"] (guard if _items) |
_input.item / _json |
_item / _item["json"] |
_node["X"] |
not available: Merge upstream, or use JS |
_now, _today |
not available: pass {{ $now.toISO() }} in via Edit Fields, or use JS |
_jmespath(data, q) |
not available: $jmespath in an expression, or a comprehension |
item.json.field |
item["json"]["field"] |
Imports: blocked by default
Every import (standard library and third-party) is checked against an allowlist before the
code runs. The default allowlist is empty, so even import json rejects the whole node:
Security violations detected
Line 1: Import of standard library module 'json' is disallowed. Allowed stdlib modules: none
- n8n Cloud: no imports at all.
- Self-hosted: the admin can allowlist modules in the task-runner config (see
n8n-self-hosting →
TASK_RUNNERS.md). Some instances therefore allowjson,datetimeandre, and most don't. - Default to import-free code. If an import would really help, confirm it first: a
one-line test node
import json+return [{"json": {"ok": True}}], or ask the user. Never assume. - Without imports: parse JSON strings upstream (
{{ JSON.parse($json.payload) }}in Edit Fields). Do date math with the Date & Time node or Luxon in an expression. ISO-8601 strings still compare and sort correctly as plain strings. Use the Crypto node for hashing. requests,pandasandnumpyare never available unless the admin built a custom runner image. Use the HTTP Request node for HTTP.
Sandbox limits (these fail even without import
अक्सर पूछे जाने वाले सवाल
मेरा पुराना n8n Python कोड क्यों फ़ेल होता है?
_input जैसे पुराने सहायक वेरिएबल n8n 2.x में नहीं रहे, इसलिए कोड अपडेट करना होगा।
क्या मैं Python लाइब्रेरी इम्पोर्ट कर सकता हूँ?
मानक लाइब्रेरी इम्पोर्ट डिफ़ॉल्ट रूप से बंद हैं, इसलिए स्किल समझाती है कि कोड को कैसे एडजस्ट करना होगा।
क्या मुझे JavaScript की जगह Python चुनना चाहिए?
स्किल कहती है कि Python सिर्फ़ तभी इस्तेमाल करें जब आप उसे खास तौर पर चाहें, क्योंकि JavaScript के n8n फ़ीचर ज़्यादा हैं।
जानकारी
लेखक का मूल विवरण
Write Python in n8n Code nodes (native Python, `language` pythonNative, n8n 2.x). Use when the user explicitly wants Python in a Code node, when migrating old Pyodide/"Python (Beta)" code that used _input/_json/_node/_now, or when a Python Code node fails with NameError, "Security violations detected", "Import of standard library module … is disallowed", "__build_class__ not found", "A 'json' property isn't a dictionary", or "Python runner unavailable". Covers the only two variables (_items/_item), dict-only access, imports blocked by default, the sandbox's denied builtins, accepted return sha
repo: czlonkowski/n8n-skills
लोकप्रियता
- GitHub स्टार
- 6.6k
- रैंकिंग में स्थान
- #13869
- लाइसेंस
- MIT
- अपडेट की गई
- 24/10/2026
कमेंट
- …
इस repository की और skills
मिलती-जुलती skills
knowledge-automation
394kयह आपके एजेंट को एक नियमित काम सेट करने देती है जो समय-सारणी पर Knowledge vault में नई सामग्री जोड़ता है, फिर जांचता है कि काम चल रहा है।
knowledge-source-ingest
394kयह आपके एजेंट को चैट चैनल, फ़ीड या मेलबॉक्स से आई नई चीज़ों से Knowledge vault अपडेट रखने देती है, बिना वह दोबारा जोड़े जो पहले से है।
benchmark
280kयह आपके एजेंट को code की speed और performance नापने में मदद करता है। यह पक्का करने और धीमेपन की समस्याएँ ढूँढने में काम आता है।