Open wiwichips opened 1 year ago
Oh Here's more information on PythonMonkey for reference:
SpiderMonkey is only a js interpreter (FFI from python to node), but no js2py translator
Sadly in PythonMonkey no any kind of context support. One global context for all.
In js2py with some hacks possible create multiply contexts.
This Pull Request suggests the usage of PythonMonkey, a Python Library for executing JavaScript in Python.
I'm happy to receive any feedback on this suggestion and modify it wherever appropriate.
PythonMonkey's API is similar to Js2Py's and its JavaScript engine is fully compatible with the newest updates to JavaScript since it leverages SpiderMonkey.
Below I'll list some examples using PythonMonkey to serve as a rationale for why it should be recommended in Js2Py's README.
Check out this Google Colab for examples on how to use PythonMonkey: https://colab.research.google.com/drive/1INshyn0gNMgULQVtXlQWK1QuDGwdgSGZ?usp=sharing
Installation
Install with:
(works with Python 3.8+ and requires npm to be installed on the system during install).
Simple Examples
toUpperCase
Example:Passing a Function Example:
PythonMonkey supports arbitrarily deeply nested JS->Py->JS->Py->... function calling between Python and JavaScript functions.
Loading a JavaScript Module in Python Example:
my-javascript-module.js
main.py
Python Loading a JavaScript Module Loading a Python Module Using CommonJS Example:
my-python-module.py
my-javascript-module.js
main.py
WebAssembly & Promise Example
Another interesting side effect of it using SpiderMonkey under the hood is that it also supports WebAssembly for free.
Here is an example: