QuickJS Python Wrapper

1.19.4 · maintenance · verified Wed Apr 15

QuickJS is a Python wrapper around the QuickJS C library. It enables Python applications to execute JavaScript code and seamlessly translates Python types like str, float, bool, list, and dict to and from JavaScript. The library handles QuickJS's underlying thread-hostile nature by ensuring that all calls to the same JS runtime are managed within the same thread. The current version is 1.19.4, with releases occurring periodically, though the primary GitHub repository is currently archived.

Warnings

Install

Imports

Quickstart

This example demonstrates how to define and execute a simple JavaScript function using the `quickjs.Function` class. Python values are automatically converted to JavaScript types, and the return value is converted back to a Python type.

from quickjs import Function

# Create a callable JavaScript function from Python
f = Function("f", """
function adder(a, b) {
    return a + b;
}
function f(a, b) {
    return adder(a, b);
}
""")

# Call the JavaScript function from Python
result = f(1, 2)
print(f"Result of JavaScript function call: {result}")

assert result == 3

view raw JSON →