Backend
I built a C-capable, DOM-native JavaScript Runtime in Pure Python
Michael Dev.to (EN Zone)
21 views
I just released myjs on PyPI (pip install myjs or pipx install myjs).
It’s a Python-native JavaScript runtime that bridges Python’s AST capabilities, native DOM primitives (domonic), and direct C-level Foreign Function Interface (FFI) bindings into a unified JavaScript execution scope.
🌐 The Pitch
Why build another JS interpreter?
In traditional stacks, if you want JavaScript to talk to native C libraries or manipulate server-side DOM structures, you end up juggling node-gyp, C++ addon build chains, or heavy IPC bridges like gRPC/REST between Node.js and Python.
myjs collapses all of that into a single, pure-Python process.
Because myjs parses JS (via an Acorn AST engine ported to Python) and executes it directly inside Python’s host scope, JavaScript code gains direct access to:
Python’s DOM Tree: Real-time DOM manipulation via domonic.
C Libraries & Shared Memory: Direct low-level access to system .so, .dylib, and .dll binaries via Python’s ctypes/cffi.
Python Standard Library: Clean mapping between JS scopes and host OS capabilities.
🚀 Quick Demo: C Memory, FFI, & DOM in JS
Here is what running a script in myjs looks like:
JavaScript
// myjs_demo.js
// 1. Call system C functions directly from JS without compilation!
const libc = ffi.loadLibrary('libc.dylib'); // Or 'c' / 'msvcrt'
const absVal = libc.abs(-42);
const sqrtVal = libc.sqrt(2);
window.console.log('C abs(-42) =', absVal);
window.console.log('C sqrt(2) =', sqrtVal);
// 2. Manipulate a native Python DOM tree via Hyperscript h()
function h(tag, props, ...kids) {
const el = document.createElement(tag);
for (const k in props) {
if (k === 'text') el.textContent = props[k];
else el.setAttribute(k, props[k]);
}
kids.forEach(c => el.appendChild(
typeof c === 'string' ? document.createTextNode(c) : c
));
return el;
}
document.body.appendChild(
h('main', { class: 'card' },
h('h1', { text: 'Executed by myjs' }),
h('p', { text: 'Real Python DOM tree rendered from JS!' })
)
);
window.console.log('DOM Tree:', document.body.outerHTML);
Run it via pipx:
Bash
$ pipx install myjs
$ myjs myjs_demo.js
Output:
Plaintext
C abs(-42) = 42
C sqrt(2) = 1.4142135623730951
DOM Tree =
Executed by myjs
Real Python DOM tree rendered from JS!
host = Darwin arm64 | python 3.13.12
💡 Key Features
Zero C-Compilers Required: Call C dynamic libraries, allocate raw C memory buffers, and pass function pointers straight from JS. Python’s runtime handles ABI resolution dynamically.
Pure Python Portability: Embeddable anywhere Python runs—no heavy binary blobs (like V8) required.
Direct DOM Integration: Mutate real domonic Python DOM nodes from within JS scripts.
📦 Try It Out
PyPI: https://pypi.org/project/myjs/
Installation: pip install myjs or pipx install myjs
I’d love to hear feedback, feature ideas, or wild use cases from anyone interested in language runtimes, Python/JS interop, or native FFI bindings!
Read original: https://dev.to/michael_b581c5c68faa9de1d/i-built-a-c-capable-dom-native-javascript-runtime-in-pure-python-b9c
Related
The benchmark everyone cited for "fastest backend" was archived in March, and the reason is the interesting part
Backend
56
Dev.to (EN Zone)
Finding Exoplanets in Noisy Data with Machine Learning
Backend
46
DEV Community
How to automatically find the batch size when using Accelerate with FSDP2? [D]
Backend
43
Reddit r/MachineLearning
Cross-Chain Bridge Risk Assessment: Aave V3
Backend
36
DEV Community
Comments0
No comments yet — be the first