n8n-code-python

Guidance for writing Python in n8n Code nodes, the parts of n8n workflows where code processes incoming data. It explains the input and output format, available standard-library tools, and important limitations.

In plain words
What is it for?
Use it when transforming workflow items with Python, accessing n8n input data, handling webhook bodies, or deciding whether JavaScript would be a better choice.
Why use it?
It prevents common mistakes such as returning the wrong data shape, reading webhook data from the wrong place, or importing libraries that n8n does not provide.

Skill for Claude CodeCodex

Part of the n8n-autopilot plugin — 24 skills, 12 agents, 4 hooks shipped together

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/neurawork-git/n8n-autopilot/n8n-code-python
Any agent
npx skills add neurawork-git/n8n-autopilot --skill n8n-code-python
Clone the repo
git clone --depth 1 https://github.com/neurawork-git/n8n-autopilot

Made for: Claude Code, Codex.

Or install n8n-autopilot, the plugin that ships this one along with the rest of its 24 skills, 12 agents, 4 hooks.

Per session 52 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,349 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 1 finding. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00052 $0.01349
Opus 5 $0.00026 $0.00674
Sonnet 5 $0.00010 $0.00270
Haiku 4.5 $0.00005 $0.00135

Measured 3d ago against content hash 237e194803dd, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

n8n-code-python scanned grade A with 1 finding against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Makes network callslowCapability

Not a fault in itself. Listed so you know the mod talks to something, and to what.

import urllib.parse
skills/n8n-code-python/SKILL.md · 224 lines

How it starts

The opening of the file, as written. The whole thing — 224 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Python Code Node (Beta)

Expert guidance for writing Python code in n8n Code nodes.


JavaScript First

Use JavaScript for 95% of use cases. Only use Python when:

  • You need specific Python standard library functions (e.g. statistics)
  • You're significantly more comfortable with Python syntax
  • You're doing data transformations better suited to Python

JavaScript has $helpers.httpRequest(), Luxon DateTime, and better n8n docs.


Quick Start

# Basic template for Python Code nodes
items = _input.all()

processed = []
for item in items:
    processed.append({
        "json": {
            **item["json"],
            "processed": True,
            "timestamp": datetime.now().isoformat()
        }
    })

return processed

Essential Rules

  1. Consider JavaScript first
  2. Access data: _input.all(), _input.first(), _input.item
  3. CRITICAL: Return [{"json": {...}}] format
  4. CRITICAL: Webhook data is under _json["body"]
  5. CRITICAL LIMITATION: No external libraries — no requests, pandas, numpy

CRITICAL: No External Libraries

# ❌ NOT AVAILABLE
import requests   # ModuleNotFoundError
import pandas     # ModuleNotFoundError

# ✅ AVAILABLE (standard library only)
import json
import datetime
import re
import base64
import hashlib
import urllib.parse
import math
import random
import statistics

Workarounds:

  • Need HTTP requests? → Use HTTP Request node before Code node (or switch to JavaScript)
  • Need pandas? → Use statistics module for basic stats, or switch to JavaScript

Data Access

# All items
all_items = _input.all()

# First item
first_item = _input.first()
data = first_item["json"]

# Each item mode
current_item = _input.item

# Other nodes
webhook_data = _node["Webhook"]["json"]
http_data = _node["HTTP Request"]["json"]

CRITICAL: Webhook Data

# ❌ WRONG
name = _json["name"]        # KeyError!

# ✅ CORRECT
name = _json["body"]["name"]

# ✅ SAFER
name = _json.get("body", {}).get("name", "Unknown")

Read the full file on GitHub · 224 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 3d ago First seen · 224 lines · 52 tokens per session scan A 237e194803dd

Subscribe to this mod's changes

n8n-code-python is a skill published in the GitHub repository neurawork-git/n8n-autopilot (18 stars, last pushed 1mo ago), licensed MIT. It adds 52 tokens to every session and 1,349 once invoked, about $0.0003 per session on Opus 5. A static security scan graded it A with 1 finding (makes network calls). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories

n8n-code-tool

Write JavaScript or Python for the n8n Custom Code Tool (@n8n/n8n-nodes-langchain.toolCode) — the AI-agent-callable tool, NOT the workflow Code node. Use when building a Code Tool attached to an AI Agent, writing code that an LLM will invoke, parsing the query input, returning a string result, defining an input schema…

czlonkowski/n8n-skills · 221 tokens

n8n-code-python

Write Python code in n8n Code nodes. Use when writing Python in n8n, using input/json/node syntax, working with standard library, or need to understand Python limitations in n8n Code nodes. Use this skill when the user specifically requests Python for an n8n Code node. Note — JavaScript is recommended for 95% of use…

czlonkowski/n8n-skills · 157 tokens

n8n-code-python

Write Python code in n8n Code nodes. Use when writing Python in n8n, using input/json/node syntax, working with standard library, or need to understand Python limitations in n8n Code nodes. Use this skill when the user specifically requests Python for an n8n Code node. Note — JavaScript is recommended for 95% of use…

czlonkowski/n8n-mcp · 157 tokens

n8n-code-python

Write correct Python for n8n Code nodes. Use Python when you need libraries or prefer Python syntax.

walidboulanouar/n8n-claude-code-template · 0 tokens

bump-dependency

Bumps a Python package dependency across Home Assistant Core integrations, regenerates core requirement files, runs verification tests and prek lint, and prepares a pull request with proper release/compare links.

home-assistant/core · 42 tokens

biopython

Comprehensive molecular biology toolkit. Use for sequence manipulation, file parsing (FASTA/GenBank/PDB), phylogenetics, and programmatic NCBI/PubMed access (Bio.Entrez). Best for batch processing, custom bioinformatics pipelines, BLAST automation. For quick lookups use gget; for multi-service integration use…

K-Dense-AI/scientific-agent-skills · 76 tokens