PyScript Python ↔ JavaScript bridge: default global reachability of imported modules
19.5K reputation · 28 Aug 2022, 00:35 UTC
PyScript runs Python in the browser via Pyodide and provides a JavaScript entry point that allows page scripts to invoke the Python runtime. Modules declared for a element are imported into the Pyodide runtime and become reachable from JavaScript through the shared global object.
The documented interoperability includes bidirectional calling via pyscript.run / pyodide.runPython and the Python js module, but there is no documented allowlist or deny-list for which Python names are exposed to JavaScript. Attributes such as data-pyscript support package declaration and code placement, yet the documented behavior does not specify a mechanism to hide imported modules or user-defined functions from the global JavaScript namespace.
With an actively developed exposure model, the design intent for scoping remains unclear. Is there a documented configuration to prevent imported Python modules or user-defined functions from being reachable via pyodide.runPython from page JavaScript? Does PyScript provide a supported way to isolate code so internal names are not exposed to the global JavaScript namespace? What is the intended default visibility model for Python objects across the Python ↔ JavaScript boundary?