PyMiniRacer (Original - Deprecated)

0.6.0 · deprecated · verified Mon Apr 13

PyMiniRacer is a Python library that provides a minimal and modern embedded V8 JavaScript engine for Python. It allows Python applications to execute JavaScript code, supporting the latest ECMAScript features and Web Assembly. Developed by Sqreen, this original project is at version 0.6.0 and has been superseded by the `mini-racer` library under a new maintainer.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a `MiniRacer` context and execute basic JavaScript code using `eval()` and `call()`. `eval()` is suitable for primitive return types, while `call()` is used for composite types like objects, which are serialized via JSON.

from py_mini_racer import MiniRacer

# Create a new MiniRacer context
ctx = MiniRacer()

# Evaluate JavaScript code
result = ctx.eval("1 + 1")
print(f"1 + 1 = {result}")

# Evaluate more complex JavaScript with variables
ctx.eval("var x = {company: 'Acme'};")
company_name = ctx.eval("x.company")
print(f"Company name: {company_name}")

# Use .call() for composite types, .eval() for primitives
def_func = ctx.eval("var fun = () => ({ foo: 1 });")
composite_result = ctx.call("fun")
print(f"Composite result: {composite_result}")

view raw JSON →