n8n-code-python

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

Updated Aug 3, 2026
One-click install
npx skills add https://github.com/alvarocubacc/n8n-workflow-builder --skill n8n-code-python-alvarocubacc
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: n8n-code-python
Source: https://github.com/alvarocubacc/n8n-workflow-builder/tree/main/n8n-skills/skills/n8n-code-python
Command: npx skills add https://github.com/alvarocubacc/n8n-workflow-builder --skill n8n-code-python-alvarocubacc

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 common KeyError or IndexError crashes. This Skill provides the patterns and error prevention guidance needed to write working Python code in n8n on the first attempt. ## 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. - Standard Library Reference: Documents available modules (json, datetime, re, base64, hashlib, urllib.parse, statistics) and workarounds for missing libraries like requests and pandas. - Error Prevention: Covers the top 5 Python Code node errors (ModuleNotFoundError, missing return, KeyError, IndexError, wrong return format) with fixes. - Use Case: You need to aggregate amounts from 50 webhook submissions in an n8n workflow. Use this Skill to write a Python Code node that safely accesses _input.all(), sums values with .get() defaults, and returns the correct [{"json": {...}}] format. ## Quick Start Ask the AI to write a Python Code node that filters active items from the previous node and returns them with a processed timestamp.

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: _input.first()["json"]["body"]. The Webhook node nests all incoming payload data under body, so direct access like _json["email"] raises a KeyError. Use .get("body", {}) for safe access.

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

No, n8n Python Code nodes only support the standard library. External packages like requests, pandas, and numpy raise ModuleNotFoundError. Use the HTTP Request node for API calls 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 n8n helpers and the Luxon date library. Use Python only when you need standard library modules like statistics or re, or when your team is more comfortable with Python syntax.

Why does my n8n Python Code node return a format error?

The Code node requires returning a list of dictionaries each containing a json key: return [{"json": {...}}]. Returning a plain dictionary, a string, or a list without the json wrapper causes workflow execution to fail.

How do I avoid KeyError in n8n Python Code nodes?

Use the .get() method with default values instead of direct dictionary key access. For example, write item["json"].get("email", "unknown") rather than item["json"]["email"], which crashes when the field is missing.

What Python modules are available in n8n Code nodes?

Available standard library modules include json, datetime, re, base64, hashlib, urllib.parse, math, random, statistics, and collections. Database drivers, HTTP clients, and data analysis packages are not installed.