Python Code
The Python Code node allows you to write and execute Python scripts directly within your workflow. Unlike traditional automation tools that require a server, this node runs entirely inside your browser using Pyodide.
This is perfect for cleaning data, performing calculations, or using advanced math libraries without your data ever leaving your computer.
How it works
Section titled “How it works”The node receives data from the previous step as a list of items. You can modify these items, create new ones, or filter them out using standard Python syntax. Because it uses Pyodide, you have access to the standard Python library and several powerful scientific packages.
graph LR
A --> B{Python Code Node}
B --> C
style B fill:#ffd43b,stroke:#333,stroke-width:2px
Setup guide
Section titled “Setup guide”- Add the node: Locate the Python Code node under the “Core” category and add it to your workflow canvas.
- Write your script: Enter your Python code in the editor. By default, the node provides a template to help you get started.
- Access data: Use the built-in
itemsvariable to interact with the data flowing into the node. - Return results: Your script must return a list of dictionaries (objects) so the next node can understand the data.
Basic example
Section titled “Basic example”If you want to add a new field to every item passing through, you can use a simple loop.
# 'items' is the list of data coming from the previous stepnew_items = []
for item in items: # Add a new field called 'status' item['status'] = 'processed'
# Calculate a new total price item['grand_total'] = item['price'] * 1.2
# Add the updated item to our list new_items.append(item)
# Always return the modified listreturn new_itemsInput Data:
Imagine you have a list of products, each with a price.
Output Result: After the code runs, each product will still have its price, but now it also has:
- A
statusfield set to “processed”. - A
grand_totalfield calculated as 1.2 times the price.
Using powerful libraries
Section titled “Using powerful libraries”One of the biggest advantages of the Python Code node is the support for heavy-duty data libraries. These are pre-loaded and ready to use:
| Library | Best for |
|---|---|
| Pandas | Complex table manipulation and data analysis. |
| NumPy | High-performance mathematical operations. |
| Matplotlib | Generating charts and visualizations. |
Common tasks
Section titled “Common tasks”Filtering items
Section titled “Filtering items”You can easily remove items that don’t meet a specific condition.
# Only keep items where the price is greater than 50return [item for item in items if item['price'] > 50]Formatting text
Section titled “Formatting text”Clean up names or labels before sending them to a database.
for item in items: item['name'] = item['name'].strip().title()return itemsImportant limitations
Section titled “Important limitations”- Browser Only: This code executes on your machine. If you share a workflow, the recipient’s browser will run the code when they trigger it.
- External Requests: Standard Python
requestsare not supported. Use our(/nodes/builtin/browser/click/) or(/nodes/builtin/core/http/) to fetch data from the web.