Registry / llm-agents / stpyv8

stpyv8

JSON →
library13.1.201.22pypypi✓ verified 22d ago

STPyV8 is a Python wrapper for the Google V8 JavaScript engine, enabling seamless interoperability between Python 3 and JavaScript. It serves as a modern fork of the original PyV8 project, continuously updated by Cloudflare to align with the latest Google V8 engine branches and Python 3 versions. The library receives frequent updates, often coinciding with new V8 releases, and provides pre-built wheels for various platforms.

pip install stpyv8
INSTALL
IMPORT
SIG · STPYV8
S
stpyv8
llm-agentspythonv13.1.201.22
Install
3.6s avg
Import
114ms
Disk
116MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v13.1.201.22 · 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.103.95 runs
build_error
glibc
py 3.103.95 runs
installs and imports cleanly · install 3.6s · import 0.114s · 118MB
116MB installed
● package 116MB
Code
Verified usage

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

STPyV8
import STPyV8
JSContext
from STPyV8 import JSContext
JSClass
from STPyV8 import JSClass

This example demonstrates how to initialize a V8 JavaScript context, evaluate a simple JavaScript expression, and export a Python class method to be callable from within the JavaScript context.

import STPyV8 with STPyV8.JSContext() as ctxt: result = ctxt.eval("'Hello, ' + 'STPyV8!'"); print(result) # Exporting a Python function to JavaScript class MyFunctions(STPyV8.JSClass): def multiply(self, a, b): return a * b my_funcs = MyFunctions() with STPyV8.JSContext(my_funcs) as ctxt: js_code = "this.multiply(5, 3);" multiplication_result = ctxt.eval(js_code) print(f"Multiplication result: {multiplication_result}")
Debug
Known issues
breakingSTPyV8 requires Python 3.9 or newer for recent versions. Attempting to install or use with older Python versions may lead to build failures or runtime errors.
fix
Ensure your Python environment is 3.9+ (e.g., `python3.9 -m pip install stpyv8`).
affects: <12.0.267.16
gotchaWhen building STPyV8 from source (e.g., if no pre-built wheel is available for your platform/Python version), you will need a C++ compiler (GCC/clang on Linux/macOS, MSVC on Windows), Python development headers, and potentially Boost libraries (though less common for recent versions).
fix
Refer to the official GitHub repository for detailed build instructions specific to your operating system. For many users, `pip install stpyv8` will automatically fetch a pre-built wheel, avoiding source compilation.
affects: All versions (when building from source)
gotchaFor complex JavaScript code, the underlying V8 engine may require an ICU data file (`icudtl.dat`). If this file is not correctly packaged with your STPyV8 installation (e.g., when building from source or with certain distribution methods), V8 operations can fail silently or with errors.
fix
Manually copy `icudtl.dat` to the appropriate STPyV8 ICU data folder (e.g., `/usr/share/stpyv8` on Linux, `/Library/Application Support/STPyV8/` on macOS). This file is usually included in zip releases alongside the wheels if manual installation is needed.
affects: All versions
gotchaSTPyV8's direct `eval()` might not fully support modern JavaScript ES Modules (`import`/`export` syntax) out-of-the-box, potentially leading to `SyntaxError: Cannot use import statement outside a module`.
fix
Consider bundling your JavaScript code using tools like Webpack or Rollup to produce a single, self-contained file without `import`/`export` statements. Alternatively, explore if V8's module loading capabilities can be exposed or configured within STPyV8's `JSContext`.
affects: All versions
gotchaThere are reported issues with STPyV8 in multi-threaded environments, including segmentation faults when used in separate threads. The presence of dual garbage collectors (Python and V8) can also lead to complexities and potential memory management issues in scenarios involving long-lived objects spanning both VMs.
fix
Exercise caution when using STPyV8 in threaded applications. If possible, isolate V8 context creation and usage to a single thread. Design your application to minimize long-lived Python objects exposed to JavaScript or vice-versa to mitigate potential GC conflicts. Monitor GitHub issues for updates on threading stability.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'stpyv8'
The `stpyv8` library is not installed in the current Python environment or the environment is not activated.
fix
Ensure the library is installed using pip: `pip install stpyv8`
Failed building wheel for stpyv8
Pre-built wheels for `stpyv8` are not available for your specific platform/Python version, or required build tools (like a C++ compiler and Python development headers) are missing.
fix
Update `pip` (`python -m pip install --upgrade pip`), install necessary build dependencies (e.g., `sudo apt-get install build-essential python3-dev` on Linux, XCode Command Line Tools on macOS), or check the `stpyv8` PyPI page for specific version requirements.
RuntimeError: V8 context is not entered.
An attempt was made to interact with the V8 JavaScript engine (e.g., evaluate code or assign variables) without an active V8 execution context.
fix
Wrap the JavaScript interaction code within a `with v8.JSContext():` block or explicitly call `context.enter()` before and `context.exit()` after the interaction.
TypeError: V8 arguments conversion error
A Python object was passed to a JavaScript function or assigned within the V8 context, but `stpyv8` failed to convert it into a compatible JavaScript type.
fix
Ensure that passed Python objects are basic types (numbers, strings, lists, dictionaries) that `stpyv8` can convert, or explicitly serialize complex objects into JSON strings before passing them to the V8 context.
Upgrade
Version history
13.1.201.22latest on PyPI · released Jan 9, 2025
Audit
Dependencies

No dependency data recorded yet.

Agent activity
34 hits · last 30 days
node
28
OpenAI (training)
1
Resources
stpyv8 — pip install stpyv8 · libregistry