from d2b import D2BClient

client = D2BClient(api_key="d2b_pat_...", base_url="https://d2b.dev")

wb = client.workbooks.create(title="monthly-sales")["id"]

# 1) a spreadsheet made for people in → typed tables (raw kept, lineage from day one)

client.sources.upload(wb, "sales_2026-06.xlsx", wait=True)

# 2) logic as a transform — {{ arg }} bindings keep lineage

client.transforms.create(

wb, name="agg/monthly", kind="sql", artifact_name="product_sales",

template='CREATE TABLE "{{ artifact_name }}" AS '

'SELECT product, sum(amount) AS revenue FROM "{{ src }}" GROUP BY 1',

args={"src": "sales"},

)

# 3) back to humans as Excel, 4) a named, revertible version

xlsx = client.export.tables(wb, tables=["product_sales"])

client.versions.commit(wb, "2026-06")