跳到正文
Skillpedia
通用编程48k · #5269

n8n-code-python

它能做什么

这段代码可以帮你为自动化工具 n8n 编写 Python 指令。它会说明在 n8n 里使用 Python 能做什么、不能做什么,重点讲标准库中有哪些可用内容。

适用场景

  • ✓当你需要为 n8n 编写 Python 代码时。
  • ✓当你想知道可以使用哪些 Python 库时。
  • ✓当你想了解 Python 在 n8n 代码节点中是如何运行的时。

技能链接

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/n8n-code-python/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/n8n-code-python/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“在 n8n 的 Python 代码节点里,我该怎么使用“json”模块?”

每周 5 个新技能,1 分钟读完。

工作原理

它的工作方式是讲解 n8n 中 Python 的规则和限制。它会列出可以使用的库(例如“json”和“datetime”),以及不能使用的库(例如“requests”或“pandas”)。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Python Code Node (Beta)

Expert guidance for writing Python code in n8n Code nodes.


Detailed Guide

Read the detailed guide before executing this skill. It retains the complete procedure and reference material. Treat its safety, prerequisites, and validation requirements as mandatory. For focused work, load the relevant sections; for end-to-end work, read the guide completely.

Critical Limitation: No External Libraries

MOST IMPORTANT PYTHON LIMITATION: Cannot import external packages

What's NOT Available

# ❌ NOT AVAILABLE - Will raise ModuleNotFoundError
import requests  # ❌ No
import pandas  # ❌ No
import numpy  # ❌ No
import scipy  # ❌ No
from bs4 import BeautifulSoup  # ❌ No
import lxml  # ❌ No

What IS Available (Standard Library)

# ✅ AVAILABLE - Standard library only
import json  # ✅ JSON parsing
import datetime  # ✅ Date/time operations
import re  # ✅ Regular expressions
import base64  # ✅ Base64 encoding/decoding
import hashlib  # ✅ Hashing functions
import urllib.parse  # ✅ URL parsing
import math  # ✅ Math functions
import random  # ✅ Random numbers
import statistics  # ✅ Statistical functions

Workarounds

Need HTTP requests?

  • ✅ Use HTTP Request node before Code node
  • ✅ Or switch to JavaScript and use $helpers.httpRequest()

Need data analysis (pandas/numpy)?

  • ✅ Use Python statistics module for basic stats
  • ✅ Or switch to JavaScript for most operations
  • ✅ Manual calculations with lists and dictionaries

Need web scraping (BeautifulSoup)?

  • ✅ Use HTTP Request node + HTML Extract node
  • ✅ Or switch to JavaScript with regex/string methods

See: STANDARD_LIBRARY.md for complete reference


When to Use Python vs JavaScript

Use Python When:

  • ✅ You need statistics module for statistical operations
  • ✅ You're significantly more comfortable with Python syntax
  • ✅ Your logic maps well to list comprehensions
  • ✅ You need specific standard library functions

Use JavaScript When:

  • ✅ You need HTTP requests ($helpers.httpRequest())
  • ✅ You need advanced date/time (DateTime/Luxon)
  • ✅ You want better n8n integration
  • ✅ For 95% of use cases (recommended)

Consider Other Nodes When:

  • ❌ Simple field mapping → Use Set node
  • ❌ Basic filtering → Use Filter node
  • ❌ Simple conditionals → Use IF or Switch node
  • ❌ HTTP requests only → Use HTTP Request node

Limitations

  • Use this skill only when the task clearly matches the scope described above.
  • Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
  • Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.
常见问题

我可以使用“requests”或“pandas”这类外部库吗?

不可以。在 n8n 的 Python 代码节点中,你不能导入外部库,只能使用 Python 的标准库。

什么是“标准库”?

标准库是安装 Python 时自带的一组模块,例如“json”、“datetime”、“math”等。

在 n8n 中,什么时候应该用 JavaScript 而不是 Python?

在 n8n 中,大多数任务都推荐使用 JavaScript,尤其是当你需要发送 HTTP 请求,或使用更高级的日期和时间功能时。

详情

作者的原始描述

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.

repo: sickn33/agentic-awesome-skills

热度

GitHub 星标
48k
排名
#5269
许可证
MIT
更新时间
2026/10/15

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能