Js2Py
raw JSON → 0.74.1 verified Mon Apr 27 auth: no python maintenance
JavaScript to Python translator and JavaScript interpreter written in pure Python. Converts JavaScript code to Python (execjs) or executes it directly. Version 0.74.1, maintenance mode with no new features.
pip install js2py-3-13 Common errors
error SyntaxError: Unexpected token '=>' ↓
cause Arrow functions are ES6 and not supported.
fix
Rewrite arrow functions as regular functions or use a transpiler like Babel.
error ImportError: cannot import name 'PyJsImportError' ↓
cause Old import path from js2py.translators.
fix
Use
from js2py import PyJsException or catch general exceptions. Warnings
deprecated Js2Py is in maintenance mode; no new features or major fixes. Consider alternatives like pyexecjs or Node.js subprocess for modern JavaScript. ↓
fix Use pyexecjs or call Node.js directly.
gotcha ES6+ features (e.g., arrow functions, const/let, classes) are not fully supported. May throw SyntaxError. ↓
fix Transpile modern JS to ES5 (using Babel) before passing to Js2Py.
deprecated The top-level `require()` function is experimental and may not work with CommonJS modules. ↓
fix Prefer `EvalJs` with manual script loading.
Imports
- EvalJs
from js2py import EvalJs - translate_js
from js2py import translate_js - require
from js2py import require
Quickstart
from js2py import EvalJs
context = EvalJs()
context.execute("var x = 10; var y = 20;")
result = context.x + context.y
print(result) # 30