跳转到内容

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 中断执行, 必要时再结束该线程。