@pyscript/bridge
v0.2.2
Published
A JS based way to use PyScript modules
Maintainers
Readme
@pyscript/bridge
Import Python utilities directly in JS
// main thread
const { ffi: { func_a, func_b } } = await import('./test.js');
// test.js
import bridge from 'https://esm.run/@pyscript/bridge';
export const ffi = bridge(import.meta.url, { type: 'mpy', worker: false });
// test.py
def func_a(value):
print(f"hello {value}")
def func_b():
import sys
return sys.versionOptions
- pyscript: the release version to automatically import if not already available on the page. If no version is provided the developers' channel version will be used instead (for developers' purposes only).
- type:
pyby default to bootstrap Pyodide. - worker:
trueby default to bootstrap in a Web Worker. - config: either a string or a PyScript compatible config JS literal to make it possible to bootstrap files and whatnot. If specified, the
workerbecomes implicitlytrueto avoid multiple configs conflicting on the main thread. - env: to share the same environment across multiple modules loaded at different times.
Tests
Run npx mini-coi . within this folder to then reach out http://localhost:8080/test/ that will show:
PyScript Bridge
------------------
no configThe test.js files uses the following defaults:
pyscriptas"2025.8.1"typeas"mpy"workerasfalseconfigasundefinedenvasundefined
To test any variant use query string parameters so that ?type=py will use py instead, worker will use a worker and config will use a basic config that brings in another file from the same folder which exposes the version.
To recap: http://localhost:8080/test/?type=py&worker&config will show this instead:
PyScript Bridge
------------------
3.12.7 (main, May 15 2025, 18:47:24) ...Please note when a config is used, the worker attribute is always true.
