Python code
Python runs through Pyodide — CPython compiled to WebAssembly — in a separate thread. No Python is required on your machine.
The API
Section titled “The API”| Symbol | Role |
|---|---|
input | The value received on the input port |
vars | A dictionary of the run variables |
print(...) | Writes to the execution log |
| The last expression | Its value leaves on the result port |
Example
Section titled “Example”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}Standard library
Section titled “Standard library”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}External packages
Section titled “External packages”Declare them in the box’s packages field. They are downloaded from PyPI on the
first run, cached, then loaded offline afterwards.
Stopping and the timeout
Section titled “Stopping and the timeout”Exceeding the timeout or stopping the run interrupts execution with a
KeyboardInterrupt, then terminates the thread if need be.