Does a pure Python-based JavaScript engine exist?

Looking for JavaScript interpreter in Python

I’m wondering if anyone knows about a JavaScript engine that’s built entirely using Python code. I don’t need it to be fast or production-ready. Even if the performance is really poor, that would be totally fine for my needs.

I’ve been searching around but most of the solutions I find seem to use native extensions or bindings to existing C-based engines. What I’m specifically looking for is something that’s implemented completely in Python without any C dependencies.

Has anyone come across such a project? I’m curious about both full ECMAScript implementations and even partial ones that cover the basic language features. Any pointers would be really helpful.

Yeah, there’s SlimJS - a pure Python JavaScript implementation that’s buried in GitHub archives. Haven’t seen updates in years, but it’s 100% Python with zero external dependencies. Found it while digging into AST parsing stuff. It handles basic variables, functions, and simple control flow. Performance is absolutely awful though - we’re talking orders of magnitude slower than native engines - but it works. There’s also PyJamaScript, which was basically an academic project. The author built a minimal JS parser and interpreter using just Python’s standard library. Super limited and pretty much useless outside of learning, but still. Both prove you can build pure Python JS engines, but modern JavaScript is so complex that you’d need serious performance sacrifices for any complete implementation.

The Problem:

You need a JavaScript interpreter written entirely in Python, even if it’s slow and not suitable for production use. Most readily available solutions rely on native extensions or bindings to existing C-based engines, and you’re specifically seeking a pure Python implementation.

:thinking: Understanding the “Why” (The Root Cause):

Pure Python JavaScript interpreters exist because it’s theoretically possible to implement a JavaScript engine using only Python’s standard library. However, JavaScript’s complexity (especially features introduced in later ECMAScript versions) makes achieving reasonable performance in a pure Python implementation incredibly challenging. Native C/C++ engines (like V8 used in Chrome or SpiderMonkey in Firefox) are significantly faster due to their low-level optimization capabilities. Your requirement for a pure Python solution prioritizes ease of dependency management and understanding over performance.

:gear: Step-by-Step Guide:

While a completely full-featured, pure Python JavaScript engine with good performance is unlikely to exist, several projects offer partial implementations suitable for learning or very limited tasks. Here’s how you can explore them:

Step 1: Explore Available Options:

Several pure Python JavaScript interpreters are available, albeit with limitations:

  • SlimJS: A project found in GitHub archives (check for availability), this engine handles basic JavaScript features like variables, functions, and control flow. Expect extremely poor performance.
  • PyJamaScript (or similar academic projects): These often focus on implementing a minimal JavaScript parser and interpreter as learning exercises. Functionality will be very limited.
  • JSPyBridge: A more capable option focusing on proper handling of object prototypes and closures. Still expect significantly lower performance compared to native engines.
  • PyJSCore (and similar educational projects): Some university projects implement a substantial portion of ECMAScript features in pure Python. Code quality might be better than other options, but still lacks production-ready robustness and performance.

Step 2: Choose a Project and Install:

Based on your specific needs and complexity of the JavaScript you need to interpret, select one of the projects mentioned above. Follow the project’s installation instructions, usually found on its GitHub repository (or wherever it’s hosted). This might involve using pip install <package_name>.

Step 3: Test and Evaluate:

Once installed, test the interpreter with simple JavaScript code snippets to assess its capabilities and limitations. Be aware of significant performance limitations, especially with more complex scripts. If the project is suitable for educational purposes, use it to learn how JavaScript engines work. For production purposes, you will likely need an alternative strategy.

:mag: Common Pitfalls & What to Check Next:

  • Limited ECMAScript Support: Pure Python interpreters often lack support for many modern JavaScript features (ES6+, async/await, etc.).
  • Performance Bottlenecks: Expect significantly slower execution compared to native engines. If performance is critical, a pure Python solution is not recommended.
  • Maintenance: Many of these projects are under-maintained or abandoned, increasing the risk of encountering bugs or encountering difficulties when seeking support.

:speech_balloon: Still running into issues? Share your (sanitized) config files, the exact command you ran, and any other relevant details. The community is here to help!

Had this exact problem a few months ago when parsing JavaScript config files in Python. Tried PyMiniRacer first - says it’s pure Python but still uses V8 bindings underneath. Ended up with Js2Py, which actually has a pure Python mode. Performance sucks and ECMAScript support is incomplete, but it handled basic JS syntax fine for what I needed. Worked well for simple expressions and function calls. There’s also PyV8 - older project with some pure Python parts, but development died years ago. Documentation’s pretty sparse. Honestly, you’ll hit walls fast with any pure Python JS engine. They can’t handle closures, prototypal inheritance, or ES6+ stuff. But if you just need basic math, simple conditionals, and variable assignments, they’ll do the job.

Found JSPyBridge during my compiler course - it’s a pure Python JavaScript interpreter that’s way more capable than the basic ones everyone mentions. Uses Python’s AST modules for parsing and handles object prototypes and closures pretty well. Slow as hell but much more complete than SlimJS or those academic projects. Also check out PyJSCore (different from what nina mentioned). It’s an educational project from some university that implements tons of ECMAScript features in pure Python. Code quality’s actually good and well documented. Both are maintenance nightmares for production, but they’re solid for experimenting or learning. You won’t get stuck with just basic math and variables.

Yeah, there are a few pure Python JS engines out there. I’ve messed around with PyJavaScriptCore - it’s all Python, no C bindings. Pretty basic though.

There’s also PyJS Engine, someone’s side project. Does simple expressions and function calls but chokes on complex stuff.

Honestly though, these pure Python engines are a headache. Slow, buggy, and you’ll waste more time debugging than getting work done.

I hit this same wall when I needed JS execution in our Python app. Instead of fighting these limited engines, I used a Latenode workflow to handle the JavaScript properly.

Just send your JS code to the workflow and get results back instantly. No performance headaches, no weird compatibility issues, supports modern JavaScript features. Integrates with Python through simple API calls.

Way better than trying to make pure Python implementations work for real projects.

Check out pyduktape2 - it’s got a pure Python fallback when the C extension isn’t available. Made for educational use but runs basic JS without native dependencies. Skulpt’s another option. It’s built for running Python in browsers, but the JS parsing parts are pure Python and might work for what you need.

This topic was automatically closed 6 hours after the last reply. New replies are no longer allowed.