Javascript Python Bridge

JavaScript
Python
Bridge
GUI
Development
NPM
Modules
The JavaScript Python Bridge is a tool that bridges the gap between JavaScript and Python, enabling seamless integration between the two languages. This bridge can be installed through npm and provides functions for importing Python modules and accessing global variables in JavaScript. It opens up possibilities for GUI development using libraries like tkinter.
Published

September 17, 2022


jspybridge

javascript in python:

pip3 install javascript
from javascript import require, globalThis
chalk, fs = require("chalk"), require("fs")
print("Hello", chalk.red("world!"), "it's", globalThis.Date().toLocaleString())
fs.writeFileSync("HelloWorld.txt", "hi!")

access python from javascript:

npm i pythonia
import { python } from 'pythonia'
// Import tkinter
const tk = await python('tkinter')
// All Python API access must be prefixed with await
const root = await tk.Tk()
// A function call with a $ suffix will treat the last argument as a kwarg dict
const a = await tk.Label$(root, { text: 'Hello World' })
await a.pack()
await root.mainloop()
python.exit() // Make sure to exit Python in the end to allow node to exit. You can also use process.exit.