Let's Shape The Future Of Your Investments!
Natoque iaculis cursus augue urna commodo aptent morbi tortor porttitor quis ornare.
Below is a concise, copy-paste-ready cheat sheet for the most frequently used Python snippets inside n8n.
Each bullet = one mini-recipe.
Drop the code straight into the Code → Python node and run.
return {"newKey": item["json"]["oldKey"]}
return {"status": "paid", "source": "n8n"}
import datetime
return {"ts": datetime.datetime.utcnow().isoformat()}
return {"short": item["json"]["orderId"][-6:]}
return {"clean": item["json"]["title"].replace("\n", " ")}
return {"email": item["json"]["mail"].lower()}
amt = item["json"]["amount"]
return {"tag": "VIP" if amt > 1000 else "Normal"}
ok = [x for x in item["json"]["lines"] if x["status"] == "ok"]
return {"okLines": ok}
total = sum(float(l["price"]) for l in item["json"]["lines"])
return {"total": total}
seen = set()
uniq = [x for x in item["json"]["list"]
if x["id"] not in seen and not seen.add(x["id"])]
return {"uniq": uniq}
return {"text": f'{item["json"]["name"]} 的订单 {item["json"]["id"]} 已发货'}
import secrets, string
alphabet = string.ascii_uppercase + string.digits
return {"code": ''.join(secrets.choice(alphabet) for _ in range(8))}
import base64
return {"b64": base64.b64encode(item["json"]["text"].encode()).decode()}
import json
return {"str": json.dumps(item["json"], ensure_ascii=False)}
import json return json.loads(item["json"]["raw"])
import requests
r = requests.post("https://api.x.com", json=item["json"], timeout=10)
return r.json()
import os
return {"token": os.getenv("API_TOKEN")}
import csv, io
o = io.StringIO()
w = csv.DictWriter(o, fieldnames=["id", "amount"])
w.writeheader()
w.writerow(item["json"])
return {"csv": o.getvalue()}
import time time.sleep(0.3) return item["json"]
if not item["json"].get("email"):
raise ValueError("email missing")
Tips
return become is the new item.json for the next node.Execute Command node:pip install pandas
Happy automating!