Skip to content

Python code

Python runs through Pyodide — CPython compiled to WebAssembly — in a separate thread. No Python is required on your machine.

SymbolRole
inputThe value received on the input port
varsA dictionary of the run variables
print(...)Writes to the execution log
The last expressionIts value leaves on the result port
commandes = input["commandes"]
payees = [c for c in commandes if c["statut"] == "payee"]
total = sum(c["montant"] for c in payees)
print(f"{len(payees)} commandes payées, total {total} €")
{"nombre": len(payees), "total": total}

CPython’s standard library is available: json, re, datetime, hashlib, base64, itertools, collections

import hashlib, hmac
signature = hmac.new(
vars["secret"].encode(),
input["corps"].encode(),
hashlib.sha256,
).hexdigest()
{"signature": signature}

Declare them in the box’s packages field. They are downloaded from PyPI on the first run, cached, then loaded offline afterwards.

Exceeding the timeout or stopping the run interrupts execution with a KeyboardInterrupt, then terminates the thread if need be.