ExamplesExample

Example: summarise a list of records

Most automations are data in, data out: rows from a query, a file or an API arrive, get reshaped, and leave for the next step. This example does the reshaping on a list you pass as an input, so it runs anywhere, and returns a list of objects that the editor shows as a sortable table.

What you will learn
  • Take a list of objects as an input
  • Return rows that the editor shows as a table

A list in, rows out

A parameter typed as a list of dictionaries gets a JSON editor in the Inputs card, prefilled with the default. A result that is a list of objects opens as a table with search, sort and CSV export — and, in a flow, a loop can iterate it row by row.

Inputs
Configure the data for this run.
VisualJSON
namestringrequiredtext value
timesintegeroptional1
shoutbooleanoptional
false
toneenumoptionalwarm
tagslist[str]optional
["vip", "newsletter"]
Fill name to run
greet.py
1from typing import Literal2 3def main(4    name: str,5    times: int = 1,6    shout: bool = False,7    tone: Literal["warm", "formal"] = "warm",8    tags: list[str] = [],9):10    word = "Hello" if tone == "warm" else "Good day"11    text = f"{word}, {name}!"12    if shout:13        text = text.upper()14    return {"greetings": [text] * times, "tags": tags}
Python 3.15LSP
A list parameter gets a JSON editor; a list of objects comes back as a table.

The code

summary.py
DEFAULT = [
    {"city": "Recife", "total": 120.5},
    {"city": "Curitiba", "total": 89.9},
    {"city": "Recife", "total": 59.9},
]

def main(orders: list[dict] = DEFAULT):
    by_city = {}
    for o in orders:
        c = by_city.setdefault(o["city"], {"city": o["city"], "orders": 0, "total": 0.0})
        c["orders"] += 1
        c["total"] = round(c["total"] + o["total"], 2)
    rows = sorted(by_city.values(), key=lambda r: -r["total"])
    print(f"{len(orders)} orders, {len(rows)} cities")
    return rows

Three details make the result easy to use downstream. Every row has the same keys, so it reads as columns. Totals are rounded to cents, because adding prices in floating point leaves long tails like 180.39999. And the rows are sorted with the biggest city first, so the table answers the obvious question before anyone clicks a header. The log line goes to Logs and never mixes with the rows.

  1. Paste the code and press Run with the default list.
  2. Edit the JSON in the orders field — add a city — and run again.

Take it further

Feed it real rows: put a SQL step before it in a flow and bind its orders input to the query’s rows, or schedule it and e-mail the table — see the report example.