Python
The Python node runs a Python script as a step in a workflow, with variables you map in as JSON.
Screenshot placeholder
The palette describes it as "Run Python".
When to use it
Use it when you need a custom calculation or data change written in Python. If you want to choose the language on the node, or use TypeScript, use the Code node.
Settings
| Field | What it does | Notes |
|---|---|---|
| Python code | Your script | Hint "Write your script below" |
| Input mapping (JSON) | The variables made available to the script | Hint "Variables available in script". Default {} |
| Output key | The name the result is stored under | Default script_output in the form. A new node starts with py_output |
A new node starts with this code:
def run(input: dict) -> dict:
# Your logic here
return {"result": input}
Inputs and outputs
| Handle | Where | Purpose |
|---|---|---|
| Input | Top | The step that comes before |
| Output | Bottom | Continues the workflow with the script's result |
The node card shows a "Python" tag.
Example
This is an illustrative example. You want to work out a total from a list of amounts.
- In Input mapping (JSON), map the amounts from the previous step into a variable.
- In Python code, add them up and return the total.
- Read the total in the next step using the Output key.
Tips
- Keep the function name
run, as in the starter code. - Make sure Input mapping (JSON) is valid JSON.
- Use the Code node if you need to install packages from the settings panel.