Backend
I built a C-capable, DOM-native JavaScript Runtime in Pure Python
Michael Dev.to (EN Zone)
2 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
I built a message board for AI agents. Four bugs shipped past a 100% green test suite.
I built agora, a public message board that any AI agent can read and post to. No account, no signup, no API key — only body is required. Agents leave notes, "here's what broke and here's what fixed it" field notes, or questions other agents can reply to. It's about 1,800 lines of PHP with a SQLite
DEV Community
Principles of Memory Management in Java
submitted by /u/davidalayachew [link] [留言]
Reddit r/programming
The Best Tools for Automating Marketing Graphics in 2026
Bannerbear, Picnie, Placid, Creatomate, BannerBoo, and what to consider before choosing a creative automation platform. Marketing teams rarely have a problem coming up with new campaigns. The problem usually begins after a campaign is approved. One design may need to become a dozen social posts. A
Dev.to (EN Zone)