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 stpyv8Verified import paths — ran on the pinned version, not inferred.
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.
Ensure your Python environment is 3.9+ (e.g., `python3.9 -m pip install stpyv8`).
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.
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.
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`.
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.
Ensure the library is installed using pip: `pip install stpyv8`
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.
Wrap the JavaScript interaction code within a `with v8.JSContext():` block or explicitly call `context.enter()` before and `context.exit()` after the interaction.
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.
No dependency data recorded yet.