PythonRuntime runs Python code in a Pyodide environment inside a Worker thread. It supports CPU time budgets and bidirectional data exchange through globals.
Creating a runtime
APythonRuntime requires a system driver and a Pyodide runtime driver factory.
These exports are also available from
"secure-exec" for backward compatibility.exec vs run
Useexec() for side effects.
run() to get a value back. The last expression in the code is returned as value. You can also request specific globals.
Capturing output
Same pattern as Node. Use theonStdio hook.
Differences from Node runtime
- No
memoryLimit: Pyodide runs in a Worker thread, not a V8 isolate - No
timingMitigation: not applicable to the Pyodide environment run()returnsvalueandglobalsinstead ofexports- Globals exchange lets you pass data into and out of the Python environment