Run custom Python code for advanced logic, data processing, and computations
The Python node lets you write and execute custom Python code within your flow. Use it when built-in nodes aren’t enough — complex data transformations, math, string parsing, conditional logic, or anything that’s easier to express in code.
Data from previous nodes is available through the input variable — a dictionary containing the output of every upstream node:
# Access data from a previous node (ID: 1, label: "Fetch Users")users = input["1_Fetch Users"]["body"]["data"]# Access form dataname = input["1_Form"]["form_data"]["name"]
users = input["1_API"]["body"]["users"]# Filter to active users and extract relevant fieldsactive_users = [ { "name": f"{u['first_name']} {u['last_name']}", "email": u["email"], "role": u.get("role", "member") } for u in users if u.get("active") is True]output = { "users": active_users, "total": len(active_users)}
Parse a CSV string
import csvimport iocsv_text = input["1_Request"]["body"]["csv_data"]reader = csv.DictReader(io.StringIO(csv_text))records = [row for row in reader]output = { "records": records, "count": len(records)}
Aggregate and compute
orders = input["1_Fetch Orders"]["body"]["orders"]total_revenue = sum(o["amount"] for o in orders)avg_order = total_revenue / len(orders) if orders else 0high_value = [o for o in orders if o["amount"] > 500]output = { "total_revenue": round(total_revenue, 2), "average_order": round(avg_order, 2), "high_value_count": len(high_value), "order_count": len(orders)}
Build a dynamic payload
form = input["1_Form"]["form_data"]# Build different payloads based on form inputif form.get("type") == "bug": output = { "channel": "#bugs", "priority": "high", "message": f"Bug report from {form['name']}: {form['description']}" }else: output = { "channel": "#feedback", "priority": "normal", "message": f"Feedback from {form['name']}: {form['description']}" }
The Python node runs in a sandboxed environment with access to Python’s standard library, including:
json — JSON parsing and serialization
re — Regular expressions
datetime — Date and time operations
math — Mathematical functions
csv — CSV reading and writing
io — String I/O
hashlib — Hashing (MD5, SHA256, etc.)
base64 — Base64 encoding/decoding
urllib.parse — URL encoding/decoding
collections — Useful data structures
External packages (like requests or pandas) are not available. For HTTP calls, use a Request node before or after the Python node. For data manipulation, Python’s built-in capabilities are sufficient for most use cases.
If your Python code raises an exception, the node’s failure path fires. The error message is available to downstream nodes on the failure path.Write defensive code when working with data that might be missing or malformed: