Registry / http-networking / pyexecjs

pyexecjs

JSON →
library1.5.1pypypi✓ verified 89d ago

PyExecJS is a Python library (version 1.5.1) designed to run JavaScript code from Python by automatically picking the best available JavaScript runtime. It was developed as a port of Ruby's ExecJS, aiming to simplify JavaScript execution, particularly in environments like Windows XP where Node.js was not readily available. However, the library is officially End-of-Life (EOL) since 2018 and is no longer maintained, with its original purpose largely superseded by modern JavaScript runtime availability.

pip install PyExecJS
INSTALL
IMPORT
SIG · PYEXECJS
P
pyexecjs
http-networkingpythonv1.5.1
Install
2.5s avg
Import
49ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v1.5.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.051s · 19.4MB
glibc
py 3.10–3.920 runs
installs and imports cleanly · install 2.5s · import 0.047s · 20MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

execjs
✓ import execjs

This quickstart demonstrates the core functionalities of PyExecJS: `execjs.eval()` for simple JavaScript snippets and `execjs.compile()` followed by `ctx.call()` for more complex code with functions. It also shows how to (optionally) attempt to select a specific runtime, though proper runtime installation and environment configuration are external requirements.

import execjs import os # Basic evaluation result_eval = execjs.eval("'red yellow blue'.split(' ')") print(f"Eval result: {result_eval}") # Compiling and calling a function ctx = execjs.compile(""" function add(x, y) { return x + y; } """) result_call = ctx.call("add", 1, 2) print(f"Call result: {result_call}") # Selecting a specific runtime (requires runtime to be installed, e.g., Node.js) # You might need to set the environment variable or ensure Node.js is in PATH # os.environ["EXECJS_RUNTIME"] = "Node" # node_runtime = execjs.get() # if node_runtime: # print(f"Selected runtime: {node_runtime.name}") # print(f"Node.js eval result: {node_runtime.eval('1 + 2')}") # else: # print("Node.js runtime not found or configured.")
Debug
Known issues
breakingPyExecJS is End-of-Life (EOL) and no longer actively maintained since 2018. Bugs will not be fixed, and its original motivation (bridging JavaScript runtimes on Windows XP) is obsolete. Users are advised to use alternative libraries or directly interact with JavaScript runtimes via `subprocess`.
fix
Migrate to direct `subprocess` calls for Node.js, `python-uglifyjs`, `js2py`, or a specialized library for your specific use case.
affects: 1.5.1 and earlier
deprecatedThe JScript runtime (Microsoft Windows Script Host) is not supported due to security concerns. Attempting to use it will result in an `EnvironmentError`.
fix
Ensure Node.js, PyV8, or another supported JavaScript runtime is installed and available in your system's PATH, or explicitly configured for PyExecJS.
affects: All versions
gotchaPyExecJS communicates with JavaScript runtimes primarily via text, which can lead to performance overhead, especially for frequent or complex operations.
fix
For performance-critical applications, consider using a direct integration with a JavaScript engine (e.g., PyV8 if actively maintained, or a more performant JavaScript-Python bridge) or minimize the number of calls by processing larger batches of data within the JavaScript context.
affects: All versions
gotchaPyExecJS does not fully support runtime-specific features (e.g., Node.js environment variables or module loading mechanisms). It's designed as a generic adapter, which limits its utility for advanced Node.js interactions.
fix
If specific runtime features are required, it's recommended to bypass PyExecJS and invoke the JavaScript runtime directly using Python's `subprocess` module, allowing full control over the execution environment and arguments.
affects: All versions
Errors
Common errors & fixes
EnvironmentError: Your Javascript runtime 'JScript' not supported due to security concerns.
PyExecJS attempted to use the JScript runtime on Windows, which has been explicitly disabled due to security vulnerabilities or is no longer considered viable.
fix
Install a supported JavaScript runtime like Node.js and ensure it's accessible in your system's PATH. PyExecJS will automatically try to detect and use it. You can verify detected runtimes programmatically.
execjs.RuntimeUnavailableError: No runtime available
PyExecJS could not find any compatible JavaScript runtime (e.g., Node.js, PyV8, JavaScriptCore, SpiderMonkey) installed on the system, or they are not correctly configured/in the system's PATH.
fix
Install a JavaScript runtime like Node.js (`npm install -g node` or download from nodejs.org) and ensure it's added to your system's PATH. On macOS, JavaScriptCore is usually available. On systems where PyV8 is an option, ensure it's correctly installed and configured. Restart your environment after installation.
ProgramError: SyntaxError: Unexpected token var
This error often occurs when JavaScript code is passed incorrectly to `execjs.eval()` or `execjs.compile()`, or when there's an actual syntax error in the JavaScript string. A common mistake is trying to embed Python variables directly into the JavaScript string without proper concatenation or formatting.
fix
Ensure the JavaScript code passed is a valid, self-contained JavaScript string. If you need to include dynamic Python values, use f-strings or `.format()` to inject them into the JavaScript string before passing it to PyExecJS. For instance, `execjs.eval(f'"Hello, {python_var}!".length')`.
Upgrade
Version history
1.5.1latest on PyPI · released Jan 18, 2018
Audit
Dependencies
sixrequiredProvides Python 2 and 3 compatibility utilities.
Node.jsoptionalCommon JavaScript runtime used by PyExecJS.
PyV8optionalPython wrapper for Google V8 engine, can be used by PyExecJS.
Mozilla SpiderMonkeyoptionalJavaScript engine, can be used by PyExecJS.
PhantomJSoptionalA headless WebKit, can be used by PyExecJS.
Agent activity
13 hits · last 30 days
node
12
Resources
pyexecjs — pip install pyexecjs · libregistry