What is the best way to return an array from JS? If I just return a JS array, I need to call .to_py() in python to make it useful. I would like to handle this in the JS code. If pyodide was accessible, I would call pyodide.toPy(). Is the pyodide runtime perhaps surfaced anywhere? Thanks!
At this time, PyScript does not publish a handle to Pyodide.
I think that will change when Pyodide version 0.21.3 is integrated into Pyscript.
If you’re experimenting, there are some (admittedly hacky) ways to work around this, by using JavaScript’s eval()
to export Python objects (or Pyodide objects, which can be imported within PyScript like pyodide.toPy) to the JavaScript namespace.
I wrote up some details on this process recently if you’re interested. Of course the cleaner way would be to have Pyodide exported from PyScript, but that’s not currently the case.