References
The pysandbox
library exports two classes: PyMainThreadSandbox
and PyWorkerSandbox
.
PyMainThreadSandbox
will execute python code on the main thread while PyWorkerSandbox
will execute python code in a web worker if crossOriginIsolated.
Both classes shares an identical interface and can be instantiated by passing in PySandboxOptions.
The init
function takes an optional argument that will be passed in to polyscript’s define/XWorker interface for convinence.
exec
takes the python code to be executed, as well as an optional DOM id as target if the code is expected to render an image or output some content.
installPackages
will use Pyodide’s micropip to install packages for you.
findImports
will output a list of imports made by the python code. Note that imports are not same as packages and may conclude custom modules like js
or python stdlib.
formatCode
uses black
for format your codeblock.
Example Usage: