n8n-code-python

Write Python in n8n Code nodes with no-external-libraries constraint.

3|1|Updated Jan 14, 2026
One-click install
npx skills add https://github.com/echoleesong/claude-skills-plugin --skill n8n-code-python-echoleesong
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: n8n-code-python
Source: https://github.com/echoleesong/claude-skills-plugin/tree/main/skills/n8n-code-python
Command: npx skills add https://github.com/echoleesong/claude-skills-plugin --skill n8n-code-python-echoleesong

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Python in n8n Code nodes is constrained to the standard library and requires careful data access patterns and return formats. This guide helps you understand how to write reliable Python code inside n8n Code nodes within the no-external-libraries constraint.

Core Features & Use Cases

  • Clear data access patterns for _input.all(), _input.first(), and _input.item, plus safe handling of webhook data under ["body"].
  • Standard-library-first guidance for common tasks (json, datetime, re, base64, hashlib, urllib.parse) and defensive programming to avoid KeyError and IndexError.
  • Practical patterns and examples for data transformation, validation, aggregation, and secure integration with n8n nodes.
  • Quick-start approach to implement a simple Python Code node that reads from input, processes, and returns a properly formatted json-wrapped output.

Quick Start

Write a small Python Code node that reads all items via _input.all(), applies a transformation on each item, and returns a list of {"json": ...} objects.

Frequently Asked Questions about n8n-code-python

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

FAQPage Schema
How do I write Python in n8n Code nodes without external libraries?

Python in n8n Code nodes is constrained to the standard library, meaning you can only use built-in modules like json, datetime, re, base64, hashlib, and urllib.parse. You must also follow specific data access patterns and return properly formatted json-wrapped output arrays.

How do I access input data in n8n Python Code nodes?

Input data in n8n Python Code nodes is accessed via _input.all() for all items, _input.first() for the first item, or _input.item for the current item. Webhook data requires safely handling the _json["body"] structure to prevent KeyError.

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

The correct return format for n8n Python Code nodes is an array of {'json': ...} objects. Returning results in this json-wrapped array format ensures the output successfully passes to downstream nodes across both All Items and Each Item modes.

How do I prevent KeyError and IndexError in n8n Python scripts?

Preventing KeyError and IndexError in n8n Python scripts requires defensive programming when accessing data structures. Safe handling of webhook data under ["body"] and careful item access prevents common runtime errors within the no-external-libraries constraint.

Does n8n Python Code node support installing third-party packages?

The n8n Python Code node does not support third-party packages due to a strict no-external-libraries constraint. You must rely on standard library modules like json, datetime, re, base64, hashlib, and urllib.parse to execute data transformations.