Mini Racer is a minimal, modern embedded V8 JavaScript engine for Python. It allows executing JavaScript code directly within Python applications. As of version 0.14.1, it provides a stable API for evaluating JS, calling functions, and managing execution contexts. The project has a relatively frequent release cadence, with minor updates and bug fixes appearing every few weeks or months.
pip install mini-racerVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize a `MiniRacer` context, evaluate JavaScript code, call a JavaScript function with Python arguments, and handle JavaScript execution errors using `MiniRacerEvalError`.
Update your import statements from `import py_mini_racer; mr = py_mini_racer.MiniRacer()` to `from py_mini_racer import MiniRacer; mr = MiniRacer()`.
Wrap your `mr.eval()` and `mr.call()` calls in `try...except MiniRacerEvalError` blocks to catch and handle JS errors correctly.
Remove the `v8_args` parameter when initializing `MiniRacer`. Custom V8 arguments are no longer directly configurable via the constructor.
Do not pass a `timeout` argument to the `MiniRacer` constructor. The `timeout` parameter remains available for the `eval()` and `call()` methods for per-operation timeouts.
Instantiate a separate `MiniRacer` object for each thread that needs to execute JavaScript code. Alternatively, use a thread-safe mechanism like a queue or a lock to serialize access to a single instance.
Ensure you have installed the correct package with `pip install mini-racer` and then import it using `from py_mini_racer import MiniRacer`.
Install the required C++ build tools for your operating system (e.g., `xcode-select --install` on macOS, Build Tools for Visual Studio on Windows, `build-essential` on Debian/Ubuntu). Additionally, ensure `pip` is updated to allow for downloading pre-compiled wheels if available: `pip install --upgrade pip`.
Modify your JavaScript code to ensure that any values returned to Python are strictly JSON-serializable. For complex objects, explicitly serialize them to a string within JavaScript using `JSON.stringify()` before returning.
Ensure all JavaScript code and string inputs are consistently encoded, preferably in UTF-8. While `mini-racer` is designed to handle Unicode, verify your environment's locale settings support UTF-8, and if persistent issues arise, explicitly handle encoding and decoding within your Python application.
No dependency data recorded yet.