Skip to main content

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 DOMdocument, window, and ~190 constructors (URL, Headers, Event, DOMRect, …). document.createElement(...).appendChild(...) builds a real object tree.

  • An event loopPromise (with all / allSettled / race / any), async / await, setTimeout / setInterval, queueMicrotask. Microtasks run before timers.

  • ES modulesimport / export from .js files; a bare specifier resolves to a Python module.

  • ffi — call native C libraries through ctypes, no compiler:

    const libc = ffi.loadLibrary("c");
    libc.abs.argtypes = [ffi.types.int];
    libc.abs.restype  = ffi.types.int;
    libc.abs(-42);                       // 42
    
  • Host bindingsfs, path, sh (shell), http + an async fetch, os (Node-flavoured), process, WebSocket (a real RFC 6455 client), say / notify / open, hash, atob / btoa.

  • pypy.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

myjs-0.0.2.tar.gz (18.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

myjs-0.0.2-py3-none-any.whl (17.8 kB view details)

Uploaded Python 3

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

Hashes for myjs-0.0.2.tar.gz
Algorithm Hash digest
SHA256 484a4e28725e12131d0a467b3c26b2cc09177bd6638f0fd9a76fc8d62e6bc7fb
MD5 92b5feae29f34718404d5397414f9ba6
BLAKE2b-256 d31593e2b727e60a0ecf40ed6d4d54ed08cae1ad2087c1e093a57ac4c2f5c2d4

See more details on using hashes here.

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

Hashes for myjs-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 dd88e3d86f833c833d508fa2f2391e03aa03d9b259f0cdf72634c4ba48f9bf4e
MD5 625f43fa328605c09cca8c9b88074ce2
BLAKE2b-256 aeda8101d085002fdb5b658e887f49a14f6d144bbac9db4598400c6af9bc8f57

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page