n8n-code-python

Write n8n Python Code node transformations with correct data access and return structure.

Updated May 12, 2026
One-click install
npx skills add https://github.com/contenido-wq/aivi_core --skill n8n-code-python-contenido-wq
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: n8n-code-python
Source: https://github.com/contenido-wq/aivi_core/tree/main/.github/skills/n8n-code-python
Command: npx skills add https://github.com/contenido-wq/aivi_core --skill n8n-code-python-contenido-wq

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Prevents common n8n Python Code node failures by teaching the correct n8n data access patterns, return format, and Python limitations (no external libraries), so your workflows don’t break at runtime.

Core Features & Use Cases

  • Critical limitation guidance: avoids ModuleNotFoundError by steering you to standard-library-only Python or switching to JavaScript / dedicated n8n nodes for HTTP, databases, and other external-library needs.
  • Correct n8n data access: shows how to use _input.all(), _input.first(), _input.item (mode-aware), how to reference other nodes with _node, and the webhook “body” nesting gotcha.
  • Safe, production-ready patterns: provides tested transformation patterns (filtering, parsing, normalization, lookup, aggregation, comparison) and emphasizes .get()-based dictionary access and empty-input handling.
  • Top error prevention: explains and fixes the most frequent issues—wrong return shape, KeyError, IndexError, ModuleNotFoundError, and missing return.

Quick Start

Ask: "Give me Python Code node code for n8n that reads webhook JSON from _json['body'], safely extracts fields with .get(), and returns results as a list of {"json": ...} items."

Frequently Asked Questions about n8n-code-python

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

FAQPage Schema
Why does my n8n Python Code node fail with ModuleNotFoundError?

n8n Python Code nodes fail with ModuleNotFoundError because they only support the standard library, preventing external library imports. You must use standard-library-only Python or switch to JavaScript and dedicated n8n nodes for HTTP and database operations.

How do I return data from an n8n Python Code node without runtime errors?

To return data from an n8n Python Code node safely, always format your output as a list of items like [{"json": ...}]. Returning the wrong structure is a frequent cause of runtime failures, so strictly enforce this list format for all transformations.

How do I access webhook JSON payloads in an n8n Python Code node?

Access webhook JSON payloads in n8n Python Code nodes by referencing the nested _json['body'] dictionary. To prevent KeyError exceptions, safely extract fields from this payload using the .get() method instead of direct key access.

Can I use external Python libraries for data transformation in n8n?

You cannot use external Python libraries for data transformation in n8n because the Python environment is restricted to the standard library. For external-library needs, switch to JavaScript or use dedicated n8n nodes for tasks like HTTP requests.

What is the correct way to read input items in n8n Python Code nodes?

Read input items in n8n Python Code nodes using mode-aware functions like _input.all() for all items or _input.first() for the first item. In Each Item mode, use _input.item, and reference other nodes with the _node syntax.

What's the best way to handle empty inputs in n8n Python Code node transformations?

The best way to handle empty inputs in n8n Python Code node transformations is to apply safe, production-ready patterns that emphasize .get()-based dictionary access. This prevents IndexError and KeyError exceptions during filtering, parsing, and aggregation tasks.