コンテンツにスキップ

Python コード

Python は Pyodide(WebAssembly にコンパイルされた CPython)を通じて、 別のスレッドで実行されます。お使いのマシンに Python は不要です。

シンボル役割
input入力ポートで受け取った値
vars実行変数の辞書
print(...)実行ログに書き込みます
最後の式その値が result ポートに送られます
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 の標準ライブラリが使えます。jsonredatetimehashlibbase64itertoolscollections など。

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

ボックスの packages フィールドに宣言してください。初回実行時に PyPI から ダウンロードされてキャッシュされ、以降はオフラインで読み込まれます。

timeout の超過や実行の停止は、KeyboardInterrupt によって処理を中断し、 必要であればスレッドを終了させます。