n8n-code-python

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

1|1|Updated Dec 21, 2025
One-click install
npx skills add https://github.com/alexadark/shorts-generator --skill n8n-code-python
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: n8n-code-python
Source: https://github.com/alexadark/shorts-generator/tree/main/.claude/skills/n8n-code-python
Command: npx skills add https://github.com/alexadark/shorts-generator --skill n8n-code-python

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Python usage inside n8n Code nodes is limited by the lack of external libraries and the need to keep workflows robust. This Skill clarifies when Python is appropriate, how to access data from inputs and webhook bodies, and how to reason about Python's standard library within n8n, helping you automate data processing without breaking your automation.

Core Features & Use Cases

  • _input/_json/_node data access: Learn how to read and transform data from multiple sources in Python Code nodes.
  • Webhook gotcha: Webhook data is under _json["body"], not at the root of _json.
  • Error prevention: Understand and prevent the top 5 Python Code node errors (ModuleNotFoundError, Empty code / Missing return, KeyError, IndexError, Incorrect return format).
  • Standard library only: Use json, datetime, re, base64, hashlib, urllib.parse, math, random, statistics.
  • Guided patterns: Use _input.all() for batch processing, _input.first() for single item flows, and per-item mode when appropriate.

Quick Start

Start with a minimal Python Code node that reads all input items with _input.all(), performs a simple transformation, and returns the results in the required format. For example, add a timestamp and pass through fields.

Frequently Asked Questions about n8n-code-python

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

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

Python Code nodes in n8n run Python using only the standard library. Write your transformation logic using built-in modules like json, datetime, re, base64, and urllib.parse, then return results in the required format: a list of item objects with a json property containing your transformed data.

How do I access webhook body data in n8n Python Code nodes?

Webhook data in Python Code nodes is accessed via `_json["body"]`, not at the root of `_json`. Use this path to safely read incoming webhook payloads, then transform and return them in the standardized list format n8n expects.

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

Python Code nodes must return a list of item dictionaries in the form `[{"json": {...}}]`. Each item's json property holds your transformed data. This structured format ensures downstream nodes receive data in the expected schema.

When should I use Run All Items vs Run Each Item mode in n8n Python Code nodes?

Use `_input.all()` for batch processing when you need to transform multiple items together. Use `_input.first()` for single-item flows. Choose Run Each Item mode when your logic must execute once per input item rather than across the entire batch.

What are the most common errors in n8n Python Code nodes and how do I prevent them?

Top errors include ModuleNotFoundError (using external libraries), KeyError (accessing missing dictionary keys), IndexError (out-of-bounds list access), Empty code or Missing return, and incorrect return format. Prevent them by using only stdlib modules, validating data before access, and always returning the required list-of-dicts structure.

Can I use Python (Beta) and Python (Native) interchangeably in n8n Code nodes?

Python (Beta) and Python (Native) are different runtime options in n8n with distinct behavior and library support. Choose based on your workflow requirements and n8n's documentation for which runtime best suits your data processing, transformation, and webhook handling tasks.