There is a new alternative to js2py called PythonMonkey which lets you import JavaScript files directly from Python and execute them.

https://github.com/Distributive-Network/PythonMonkey

JavaScript numar.js file:

module.exports = function numar(){
    return 1; //return 1 if the checkbox is
}

Python main.py file:

import pythonmonkey as pm
numar = pm.require('./numar')

print(numar()) # this outputs "1.0"
Answer from Will Pringle on Stack Overflow
Top answer
1 of 2
4

There is a new alternative to js2py called PythonMonkey which lets you import JavaScript files directly from Python and execute them.

https://github.com/Distributive-Network/PythonMonkey

JavaScript numar.js file:

module.exports = function numar(){
    return 1; //return 1 if the checkbox is
}

Python main.py file:

import pythonmonkey as pm
numar = pm.require('./numar')

print(numar()) # this outputs "1.0"
2 of 2
1

This is still an issue in js2py and this link may help you. https://github.com/PiotrDabkowski/Js2Py/issues/123#issuecomment-866218046

The only way to solve this is to modify translated file.

# translate myfunction.js, numar.js files to python
import js2py

js2py.translate_file('numar.js', 'numar.py')
js2py.translate_file('myfunction.js', 'myfunction.py')
// myfunction.js
var numar = require("./numar");
function myfunction() {
  var b = numar();
  return b;
}
// numar.js
function numar(){
    return 1; //return 1 if the checkbox is
}
# then modify translated myfunction.py file like this
__all__ = ['myfunction']

# Don't look below, you will not understand this Python code :) I don't.

from js2py.pyjs import *
from numar import numar
# setting scope
var = Scope( JS_BUILTINS )
set_global_object(var)

# Code follows:
var.registers(['numar', 'myfunction'])
@Js
def PyJsHoisted_myfunction_(this, arguments, var=var):
    var = Scope({'this':this, 'arguments':arguments}, var)
    var.registers(['b'])
    var.put('b', var.get('numar')())
    return var.get('b')
PyJsHoisted_myfunction_.func_name = 'myfunction'
var.put('myfunction', PyJsHoisted_myfunction_)
var.put('numar', numar.numar)
pass
pass


# Add lib to the module scope
myfunction = var.to_python()
# import in your code
from myfunction import myfunction

print(myfunction.myfunction())

You can find the code here.

https://github.com/lacmansoftware/python-js2py-require-solution

🌐
Medium
medium.com › @willkantorpringle › pythonmonkey-javascript-wasm-interop-in-python-using-spidermonkey-bindings-4a8efce2e598
PythonMonkey: JavaScript/WASM Interop in Python using SpiderMonkey Bindings
August 24, 2023 - Furthermore, JS2Py misses out on functionalities such as a WASM engine, support for the latest JavaScript specification (ECMA-262), and a powerful JIT, which come built-in with these engines. JavaScript Promises and Async/Await, which are used extensively in modern asynchronous JS programming, are also missing in JS2Py but are available in PythonMonkey.
🌐
Linux TLDR
linuxtldr.com › home › how to run javascript in python (with an example)
How to Run JavaScript in Python (with an Example)
July 29, 2025 - PythonMonkey supports and runs JavaScript code exclusively on the Mozilla SpiderMonkey engine. PyExecJS is popular, offering an API to run JavaScript code from Python using various engines like Node.js, JavaScriptCore, and Google V8.
🌐
GitHub
github.com › PiotrDabkowski › Js2Py
GitHub - PiotrDabkowski/Js2Py: JavaScript to Python Translator & JavaScript interpreter written in 100% pure Python🚀 Try it online:
In Js2Py all JavaScript objects are a subclass of PyJs object. For example JS Number is represented by PyJsNumber class. js2py.eval_js and js2py.EvalJs automatically tries to convert PyJs type to builtin python type.
Starred by 2.6K users
Forked by 278 users
Languages   JavaScript 65.1% | Python 34.9%
🌐
Pythonmonkey
pythonmonkey.io
PythonMonkey - JavaScript meets Python
PythonMonkey allows Python developers to use complex JavaScript libraries without awkward syntax or performance penalties.
🌐
PyPI
pypi.org › project › Js2Py
Js2Py
JavaScript is disabled in your browser. Please enable JavaScript to proceed · A required part of this site couldn’t load. This may be due to a browser extension, network issues, or browser settings. Please check your connection, disable any ad blockers, or try using a different browser
Find elsewhere
🌐
The New Stack
thenewstack.io › home › python meets javascript, wasm with the magic of pythonmonkey
Python Meets JavaScript, Wasm With the Magic of PythonMonkey - The New Stack
July 11, 2024 - Meanwhile, Pringle compared PythonMonkey to related projects like JS2PY, PyV8, and Metacall, highlighting PythonMonkey’s advantages in terms of performance and features.
🌐
YouTube
youtube.com › watch
Python 3 Script to Run Javascript Code Using js2py Library in ...
Enjoy the videos and music you love, upload original content, and share it all with friends, family, and the world on YouTube.
🌐
Medium
medium.com › analytics-vidhya › run-javascript-from-python-c0fe8f8aeb1e
Run Javascript from Python. Learn how to Run Javascript commands… | by Ayushi Rawat | Analytics Vidhya | Medium
November 15, 2020 - Js2Py is a Python module which can be used to translator JavaScript to Python & acts as a JavaScript interpreter written in 100% pure Python.
🌐
GitHub
github.com › Distributive-Network › PythonMonkey
GitHub - Distributive-Network/PythonMonkey: A Mozilla SpiderMonkey JavaScript engine embedded into the Python VM, using the Python engine to provide the JS host environment. · GitHub
PythonMonkey is a Mozilla SpiderMonkey JavaScript engine embedded into the Python Runtime, using the Python engine to provide the Javascript host environment.
Starred by 962 users
Forked by 43 users
Languages   C++ 53.0% | Python 30.4% | JavaScript 10.1% | Shell 4.0% | CMake 1.6% | HTML 0.7% | Makefile 0.2%
🌐
Snyk
snyk.io › advisor › js2py › js2py code examples
Top 5 Js2Py Code Examples | Snyk
import js2py import datetime now = datetime.datetime.now # the line below will # - build a 'compilation plan' by substituting strings and constants with placeholders # - then build the ast and emit the python code from that compilation plan # - then substitute back in the constants # This causes some regex overhead, but for js code with similar structure # subsequent translate_js calls are 20 times faster js2py.translate_js('name == "Robert" && age == 46', use_compilation_plan=True) # this lines below will re-use the compilation plan already laid out by the # statement above js2py.translate_js
🌐
LibHunt
libhunt.com › compare-Js2Py-vs-PythonMonkey
Js2Py vs PythonMonkey - compare differences and reviews? | LibHunt
July 27, 2025 - You could try something like this ...Dabkowski/Js2Py, but I think that you'd lose the libraries (including Phaser), so I honestly don't think this is something that is practical beyond a few lines of code. Once you learn Python, JS is not that difficult to pick up. Posts with mentions or reviews of PythonMonkey...