Importing Python Objects in JavaScript
It may be useful for some applications to extract objects from Python via JavaScript.
Once PyScript has been loaded, we can extract objects from its global scope. If we have objects in the Python global scope:
We can retrieve a reference to this Python object by name using pyscript.interpreter.globals.get(name)
:
Once Pyodide has been loaded, we can extract objects from its global scope. If we have objects in the Python global scope, we can extract them in JavaScript using pyodide.globals.get(...)
: