MR
Mayur Rathi
@czlonkowski
⭐ 40.7k GitHub stars

N8N Code Python

N8N Code Python is an code AI skill with a core value of Write Python code in n8n Code nodes. It helps developers solve real-world problems in the code domain, boosting efficiency, automating repetitive tasks, and optimizing workflows.

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.

Last verified on: 2026-07-07

Quick Facts

Category code
Works With Claude
Source sickn33/antigravity-awesome-skills
Stars ⭐ 40.7k
Last Verified 2026-07-07
Risk Level Low
mkdir -p ./skills/n8n-code-python && curl -sfL https://raw.githubusercontent.com/sickn33/antigravity-awesome-skills/main/skills/n8n-code-python/SKILL.md -o ./skills/n8n-code-python/SKILL.md

Run in terminal / PowerShell. Requires curl (Unix) or PowerShell 5+ (Windows).

Skill Content

# Python Code Node (Beta)


Expert guidance for writing Python code in n8n Code nodes.


---


⚠️ Important: JavaScript First


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

- You need specific Python standard library functions

- You're significantly more comfortable with Python syntax

- You're doing data transformations better suited to Python


**Why JavaScript is preferred:**

- Full n8n helper functions ($helpers.httpRequest, etc.)

- Luxon DateTime library for advanced date/time operations

- No external library limitations

- Better n8n documentation and community support


---


Quick Start


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

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

return processed

Essential Rules


1. **Consider JavaScript first** - Use Python only when necessary

2. **Access data**: `_input.all()`, `_input.first()`, or `_input.item`

3. **CRITICAL**: Must return `[{"json": {...}}]` format

4. **CRITICAL**: Webhook data is under `_json["body"]` (not `_json` directly)

5. **CRITICAL LIMITATION**: **No external libraries** (no requests, pandas, numpy)

6. **Standard library only**: json, datetime, re, base64, hashlib, urllib.parse, math, random, statistics


---


Mode Selection Guide


Same as JavaScript - choose based on your use case:


Run Once for All Items (Recommended - Default)


**Use this mode for:** 95% of use cases


- **How it works**: Code executes **once** regardless of input count

- **Data access**: `_input.all()` or `_items` array (Native mode)

- **Best for**: Aggregation, filtering, batch processing, transformations

- **Performance**: Faster for multiple items (single execution)


python
# Example: Calculate total from all items
all_items = _input.all()
total = sum(item["json"].get("amount", 0) for item in all_items)

return [{
    "json": {
        "total": total,
        "count": len(all_items),
        "average": total / len(all_items) if all_items else 0
    }
}]

Run Once for Each Item


**Use this mode for:** Specialized cases only


- **How it works**: Code executes **separately** for each input item

- **Data access**: `_input.item` or `_item` (Native mode)

- **Best for**: Item-specific logic, independent operations, per-item validation

- **Performance**: Slower for large datasets (multiple executions)


python
# Example: Add processing timestamp to each item
item = _input.item

return [{
    "json": {
        **item["json"],
        "processed": True,
        "processed_at": datetime.now().isoformat()
    }
}]

---


Python Modes: Beta vs Native


n8n offers two Python execution modes:


Python (Beta) - Recommended

- **Use**: `_input`, `_json`, `_node` helper syntax

- **Best for**: Most Python use cases

- **Helpers available**: `_now`, `_today`, `_jmespath()`

- **Import**: `from datetime import datetime`


python
# Python (Beta) example
items = _input.all()
now = _now  # Built-in datetime object

return [{
    "json": {
        "count": len(items),
        "timestamp": now.isoformat()
    }
}]

Python (Native) (Beta)

- **Use**: `_items`, `_item` variables only

- **No helpers**: No `_input`, `_now`, etc.

- **More limited**: Standard Python only

- **Use when**: Need pure Python without n8n helpers


python
# Python (Native) example
processed = []

for item in _items:
    processed.append({
        "json": {
            "id": item["json"].get("id"),
            "processed": True
        }
    })

return processed

**Recommendation**: Use **Python (Beta)** for better n8n integration.


---


Data Access Patterns


Pattern 1: _input.all() - Most Common


**Use when**: Processing arrays, batch operations, aggregations


python
# Get all items from previous node
all_items = _input.all()

# Filter, transform as needed

🎯 Best For

  • Claude users
  • Software engineers
  • Development teams
  • Tech leads

💡 Use Cases

  • Python code quality enforcement
  • Dependency management

📖 How to Use This Skill

  1. 1

    Install the Skill

    Copy the install command from the Terminal tab and run it. The SKILL.md file downloads to your local skills directory.

  2. 2

    Load into Your AI Assistant

    Open Claude and reference the skill. Paste the SKILL.md content or use the system prompt tab.

  3. 3

    Apply N8N Code Python to Your Work

    Open your project in the AI assistant and ask it to apply the skill. Start with a small module to verify the output quality.

  4. 4

    Review and Refine

    Review AI suggestions before committing. Run tests, check for regressions, and iterate on the skill output.

❓ Frequently Asked Questions

Is N8N Code Python compatible with Cursor and VS Code?

Yes — this skill works with any AI coding assistant including Cursor, VS Code with Copilot, and JetBrains IDEs.

Do I need specific dependencies for N8N Code Python?

Check the install command and Works With section. Most code skills only require the AI assistant and your codebase.

How do I install N8N Code Python?

Copy the install command from the Terminal tab and run it. The skill downloads to ./skills/n8n-code-python/SKILL.md, ready to use.

Can I customize this skill for my team?

Absolutely. Edit the SKILL.md file to add team-specific instructions, examples, or workflows.

⚠️ Common Mistakes to Avoid

Skipping validation

Always test AI-generated code changes, even for simple refactors.

Missing dependency updates

Check if the skill requires updated dependencies or new packages.

🔗 Related Skills