n8n-code-python

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

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Python can be used inside n8n Code nodes, but is constrained to the standard library and relies on explicit data access patterns. This skill provides guidance on writing Python in n8n Code nodes, safely accessing data via _input/_json/_node, and returning data in the required format.

Core Features & Use Cases

  • Official data access patterns: _input.all(), _input.first(), _input.item, and _node references.
  • No external libraries: standard library only (json, datetime, re, etc.) and how to work within that limitation.
  • Webhook gotcha: data from webhooks is nested under body.
  • Return format: always return a list of objects with a top-level json key.
  • Common patterns: safe dictionary access with .get(), handling empty lists, and error prevention.
  • Use Case: Transform a batch of items, validate per-item data, or compute simple statistics using Python's standard library.

Quick Start

Use this template to start coding: items = _input.all() processed = [] for item in items: processed.append({"json": {**item["json"], "processed": True}}) return processed

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 code in an n8n Code node?

To write Python code in an n8n Code node, use the standard library and access data via _input.all() or _input.first(). You must return a list of dictionaries, each containing a top-level json key.

Can I use external Python libraries in n8n Code nodes?

No, you cannot use external Python libraries in n8n Code nodes. Python execution is constrained to the standard library only, meaning you can use built-in modules like json, datetime, and re for data transformation.

How do I access webhook payload data using Python in n8n?

When processing webhook payload data using Python in n8n, remember the data is nested under the body field. Access it safely through _input and use dictionary .get() methods to prevent errors when fields are missing.

Why does my Python script in n8n return a data format error?

Your Python script in n8n returns a data format error because it must output data as a list of objects with a top-level json key. Ensure your code returns a structure like [{"json": your_data}] to match n8n's expected format.

What is the best way to transform items in batches using Python in n8n?

The best way to transform items in batches using Python in n8n is the All Items mode. Retrieve all items with _input.all(), iterate through them, append a processed flag inside a json key, and return the entire list.

Does n8n Python execution support lightweight analytics and data validation?

Yes, n8n Python execution supports lightweight analytics and data validation. Using standard library modules across All Items or Each Item modes, you can validate per-item data and compute simple statistics safely.