Thin Python wrapper of quickjs-ng
Actively maintained. Last release 13 days ago, commits in 4 of the last 26 weeks. A safe choice.
pip install quickjs-ngquickjs-ng
Python wrapper around quickjs-ng, the actively maintained fork of the QuickJS JavaScript engine.
Drop-in replacement for the archived quickjs package — import quickjs works unchanged.
Installation
pip install quickjs-ng
Requires CPython 3.10+ (3.10 is supported until its end of life on 2026-10-31) or PyPy 3.10/3.11. Pre-built wheels are available for Linux (x86_64, i686, aarch64), Windows (AMD64, x86), and macOS (arm64).
Usage
import quickjs
# Evaluate expressions
ctx = quickjs.Context()
ctx.eval("1 + 2") # => 3
# Call JS functions from Python
ctx.eval("function add(a, b) { return a + b; }")
add = ctx.get("add")
add(3, 4) # => 7
# Call Python functions from JS
ctx.add_callable("py_add", lambda a, b: a + b)
ctx.eval("py_add(3, 4)") # => 7
# Compile once, load many times (skips parsing; bytecode is only valid for the same build).
# Only load bytecode produced by trusted code with the
# same QuickJS build/binary configuration; never load bytecode from external or untrusted data.
code = ctx.compile("function add(a, b) { return a + b; }") # => bytes
quickjs.Context().eval_bytecode(code)
# Use the Function helper for thread-safe execution
f = quickjs.Function("f", "function f(x) { return x * 2; }")
f(21) # => 42
# Resource limits
ctx.set_memory_limit(1024 * 1024) # 1 MB
ctx.set_time_limit(5) # 5 seconds of CPU time
ctx.set_max_stack_size(512 * 1024) # 512 KB stack
Threading
Each Context owns an isolated QuickJS runtime — there is no shared state between contexts. A single Context is not thread-safe and must not be used from multiple threads.
Recommended patterns:
-
Context per thread — create a separate
Contextin each thread. No locking, no overhead, full parallelism: