Python Wrapper for Google V8 Engine

13.1.201.22 · active · verified Sun Apr 12

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.

Warnings

Install

Imports

Quickstart

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}")

view raw JSON →