myjs
A JavaScript interpreter for Python. It runs a practical subset of ECMAScript against a server-side DOM, hands scripts an ffi bridge to native C libraries, and lets JavaScript reach the entire Python ecosystem.
pip install myjs
myjs # start a REPL
myjs script.js # execute a file
myjs -e "6 * 7" # evaluate a snippet
myjs --gui app.js # run, then show the DOM the script built in a native window
import myjs
myjs.eval("1 + 2 * 3") # -> 7
myjs.run("script.js")
s = myjs.Session() # an isolated global scope
s.eval("const x = 21;")
s.eval("x * 2") # -> 42
What a script can reach
-
The DOM —
document,window, and ~190 constructors (URL,Headers,Event,DOMRect, …).document.createElement(...).appendChild(...)builds a real object tree. -
An event loop —
Promise(withall/allSettled/race/any),async/await,setTimeout/setInterval,queueMicrotask. Microtasks run before timers. -
ES modules —
import/exportfrom.jsfiles; a bare specifier resolves to a Python module. -
ffi— call native C libraries throughctypes, no compiler:const libc = ffi.loadLibrary("c"); libc.abs.argtypes = [ffi.types.int]; libc.abs.restype = ffi.types.int; libc.abs(-42); // 42
-
Host bindings —
fs,path,sh(shell),http+ an asyncfetch,os(Node-flavoured),process,WebSocket(a real RFC 6455 client),say/notify/open,hash,atob/btoa. -
py—py.import("numpy"),py.eval(...),py.list(iter)→ the whole Python package index from JavaScript.
The language layer passes a curated test262-style battery: closures, classes (extends / super / fields / getters-setters / private / static), destructuring, generators, labelled break, async / await, and the Array / String / Object / Number / Math / JSON / RegExp built-ins. Not covered: real prototype chains, Proxy / Symbol, with.
Language embedding
s = myjs.Session(scope={"answer": 42})
s.eval("answer * 2") # -> 84
A JavaScript exception that escapes becomes myjs.JSError with js_name, js_line, and js_trace (the call stack).
How it is built
myjs is the runtime layer on top of the domonic-libs acorn port — a faithful Python port of the acorn parser plus a tree-walking evaluator — which in turn runs on domonic's DOM. Full reference: docs/myjs.md.
MIT licensed.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file myjs-0.0.2.tar.gz.
File metadata
- Download URL: myjs-0.0.2.tar.gz
- Upload date:
- Size: 18.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
484a4e28725e12131d0a467b3c26b2cc09177bd6638f0fd9a76fc8d62e6bc7fb
|
|
| MD5 |
92b5feae29f34718404d5397414f9ba6
|
|
| BLAKE2b-256 |
d31593e2b727e60a0ecf40ed6d4d54ed08cae1ad2087c1e093a57ac4c2f5c2d4
|
File details
Details for the file myjs-0.0.2-py3-none-any.whl.
File metadata
- Download URL: myjs-0.0.2-py3-none-any.whl
- Upload date:
- Size: 17.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dd88e3d86f833c833d508fa2f2391e03aa03d9b259f0cdf72634c4ba48f9bf4e
|
|
| MD5 |
625f43fa328605c09cca8c9b88074ce2
|
|
| BLAKE2b-256 |
aeda8101d085002fdb5b658e887f49a14f6d144bbac9db4598400c6af9bc8f57
|