/pyjs

Python ⇔ JavaScript bindings using high level embind and pybind11

Primary LanguagePythonMozilla Public License 2.0MPL-2.0

pyjs

CI CI

What is pyjs

pyjs is modern pybind11 + emscripten Embind based Python <-> JavaScript foreign function interface (FFI) for wasm/emscripten compiled Python.

The API is loosly based on the FFI of pyodide.

Full Documentation

See the documentation for a full documentation.

Try it out

To try it out, you can use the playground.

Quickstart

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 side