n8n-code-python

Write Python code for n8n Code nodes using standard library and data access patterns.

2|Updated Jan 12, 2026
One-click install
npx skills add https://github.com/mdc159/cbass --skill n8n-code-python-mdc159
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: n8n-code-python
Source: https://github.com/mdc159/cbass/tree/main/.claude/skills/n8n-mcp-skills-v1.0.0/skills/n8n-code-python
Command: npx skills add https://github.com/mdc159/cbass --skill n8n-code-python-mdc159

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing Python in n8n Code nodes fails frequently because of hidden constraints: no external libraries, webhook data nested under body, strict return format requirements, and confusing data access syntax. This Skill provides the patterns, error fixes, and standard library reference needed to write working Python Code nodes. ## Core Features & Use Cases - Data Access Patterns: Complete guidance on _input.all(), _input.first(), _input.item, and _node references, including the critical webhook body nesting gotcha. - Error Prevention: Solutions for the top 5 Python Code node errors including ModuleNotFoundError, KeyError, IndexError, missing returns, and incorrect return formats. - Standard Library Reference: Documents available modules (json, datetime, re, base64, hashlib, urllib.parse, statistics) with workarounds for missing libraries like requests and pandas. - Use Case: You need to aggregate webhook submissions, filter records by regex patterns, and compute statistics in an n8n workflow. Use this Skill to write a Python Code node that safely accesses _input.all(), transforms items with list comprehensions, and returns properly formatted [{"json": {...}}] output. ## Quick Start Ask the AI to write a Python Code node for n8n that filters incoming webhook items by a field value and returns aggregated statistics.

Frequently Asked Questions about n8n-code-python

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I access webhook data in an n8n Python Code node?

Access webhook data through the body property: use _input.first()["json"].get("body", {}) to safely retrieve the payload. Webhook nodes nest all POST data, query parameters, and JSON under the body key, so direct field access raises KeyError.

Can I use requests or pandas in n8n Python Code nodes?

No, n8n Python Code nodes only support the standard library; importing requests, pandas, or numpy raises ModuleNotFoundError. Use the HTTP Request node for API calls, n8n database nodes for queries, or switch to JavaScript which offers $helpers.httpRequest.

Should I use Python or JavaScript in n8n Code nodes?

JavaScript is recommended for about 95% of use cases because it includes $helpers.httpRequest and the Luxon date library. Use Python only when you need standard library modules like statistics, re, or hashlib, or when your team prefers Python syntax.

What return format does the n8n Python Code node require?

The Code node must return a list of dictionaries where each item wraps data in a json key, like return [{"json": {"result": value}}]. Returning a plain dictionary, string, or None causes workflow execution failures.

Why does my n8n Python Code node throw KeyError?

KeyError occurs when accessing dictionary keys that may not exist, such as item["json"]["name"]. Use the .get() method with defaults, like item["json"].get("name", "Unknown"), and remember webhook fields live under the body property.

What is the difference between _input.all() and _input.item in n8n?

_input.all() returns every item from the previous node and works in Run Once for All Items mode, while _input.item returns the current item only in Run Once for Each Item mode. Using _input.item in All Items mode returns None and causes AttributeError.