n8n-code-python

Write Python code in n8n Code nodes using standard library data-access patterns.

4|2|Updated Dec 13, 2025
One-click install
npx skills add https://github.com/promptadvisers/n8n-powerhouse --skill n8n-code-python-promptadvisers
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: n8n-code-python
Source: https://github.com/promptadvisers/n8n-powerhouse/tree/main/.claude/skills/n8n-code-python
Command: npx skills add https://github.com/promptadvisers/n8n-powerhouse --skill n8n-code-python-promptadvisers

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Helps developers write Python code inside n8n Code nodes while understanding platform limitations (no external libraries) and applying safe data-access patterns.

Core Features & Use Cases

  • Data access patterns: _input.all(), _input.first(), _input.item, and _node references for cross-node data.
  • Webhook gotcha: webhook payloads live under the body key and must be accessed via _json["body"] with safe .get() usage.
  • Return discipline: always return a list of items with a top-level "json" key, enabling reliable downstream processing.
  • Standard library focus: guidance on using only Python's standard library (json, datetime, re, base64, hashlib, urllib.parse, math, random, statistics), with JavaScript preferred for most tasks.
  • Error prevention: practical patterns to avoid KeyError, IndexError, and missing returns, plus guidance on mode selection (All Items vs Each Item).

Quick Start

Create a Python Code node that reads all input items with _input.all(), processes each item by adding a timestamp, and returns the results in the required [{"json": {...}}] format.

Quick Start (single-sentence instruction)

Create a Python Code node that reads all input items with _input.all(), processes each item by adding a timestamp, and returns the results in the required [{"json": {...}}] format.

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 payload data in an n8n Python Code node?

Access webhook payloads in an n8n Python Code node by retrieving the body key via _json["body"] using safe .get() methods. This prevents KeyError exceptions and ensures reliable data extraction from incoming webhook requests.

What is the correct return format for Python Code nodes in n8n?

Return a list of items containing a top-level json key, formatted as [{"json": {...}}], from n8n Python Code nodes. This return discipline ensures reliable downstream processing across All Items and Each Item execution modes.

Can I use external Python packages in n8n Code nodes?

No, n8n Code nodes enforce a standard library only environment, forbidding external Python packages. Developers must use built-in modules like json, datetime, re, and hashlib, with JavaScript preferred for complex tasks requiring outside libraries.

What data access patterns are available for Python in n8n?

Data access patterns for Python in n8n include _input.all() for all items, _input.first for the initial item, _input.item for the current item, and _node references for cross-node data retrieval. These functions enable structured data handling within workflows.

How do I avoid KeyError and IndexError when writing Python in n8n?

Prevent KeyError and IndexError in n8n Python Code nodes by using safe dictionary access with .get() and validating item lists before processing. Selecting the correct execution mode between All Items and Each Item also prevents missing return errors.