pyjs is a modern pybind11 + emscripten embind based Python <-> JavaScript foreign function interface (FFI) for wasm/emscripten compiled Python. The API is loosely based on the FFI of pyodide.
- Python 3.14, emscripten 6,
wasm32andwasm64 - runs in the browser main thread and in web workers
- asyncio support:
awaitJavaScript promises from Python and Python coroutines from JavaScript - tested in Chromium, Firefox and WebKit (Safari)
- distributed via emscripten-forge
See the documentation. Or go directely to the playground to try it out.
Access JavaScript from Python:
import pyjs
# hello world
pyjs.js.console.log("Hello, World!")
# create a JavaScript function to add two numbers
js_function = pyjs.js.Function("a", "b", """
console.log("Adding", a, "and", b)
return a + b
""")
# call the function
result = js_function(1, 2)Access Python from JavaScript:
// hello world
pyjs.eval("print('Hello, World!')")
// eval a python expression and get the result
const py_list = pyjs.eval("[i for i in range(10)]")
// access
console.log(py_list.get(0)) // same as py_list[0] on the python sideBuilding, testing, benchmarking and building the docs all go through pixi tasks (only pixi >= 0.84 is needed), the CI runs the same tasks:
pixi run build wasm32 # build pyjs
pixi run test wasm64 # build + run the tests in the browser
pixi run test wasm32 "chromium firefox webkit"
pixi run bench wasm32 # FFI / asyncio benchmarks
pixi run docs # sphinx docs + playground
pixi run npm-package # npm packageSee development for details.