$ show Distributive-Network/PythonMonkey
PythonMonkey is a Python C extension that embeds Mozilla's SpiderMonkey JavaScript engine, enabling seamless bidirectional interop between Python and JavaScript. It allows Python code to evaluate JS expressions, require CommonJS modules (including .py modules), and manipulate JS objects as native Python types via proxy objects with shared memory semantics. The library integrates JS promises and timers with Python's asyncio event loop, and provides a CLI tool (pmjs) similar to Node.js. The architecture is a native module with extensive C++ proxy handlers for type coercion, a CommonJS module system, and built-in JS modules (console, timers, URL, XMLHttpRequest). External dependencies include SpiderMonkey (built from source), Python 3.8–3.13, npm, cmake, and rust. The codebase is actively maintained by Distributive Corp. and reached MVP in September 2024, but carries medium technical drift due to tight coupling to a specific SpiderMonkey version and Python version shims.
The LLM identified 3 files worth highlighting for reuse:
Implements the ECMAScript JobQueue interface and bridges SpiderMonkey's promise/timer jobs to Python's asyncio event loop. This is a clean, self-contained abstraction that could be reused in other projects embedding a JS engine into Python, or adapted to bridge other async runtimes. It demonstrates non-obvious skill in reconciling two event loop models.
Provides macros and inline functions to abstract CPython API differences across versions 3.8–3.13, handling changes like Py_IsFinalizing, _PyDictViewObject, and PyLong_AsByteArray. This is a reusable pattern for any C extension that must support multiple Python versions, and is well-structured with clear version checks.
Defines a pattern for registering native C++ functions under JavaScript namespaces (e.g., 'utils', 'timers'), similar to Node.js internal bindings. The implementation is clean and could be extracted as a utility for other SpiderMonkey-based projects that need to expose native APIs to JS.