Registry / web-framework / py-mini-racer

py-mini-racer

JSON →
library0.6.0pypypi✓ verified 24d ago

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.

pip install py-mini-racer
INSTALL
IMPORT
SIG · PY-MINI-RACER
P
py-mini-racer
web-frameworkpythonv0.6.0
Install
1.7s avg
Import
280ms
Disk
33MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.6.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.244s · 36.2MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.7s · import 0.316s · 35MB
33MB installed
● package 33MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

MiniRacer
from py_mini_racer import MiniRacer
The primary class for interacting with the V8 engine.

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}")
Debug
Known issues
breakingThe `py-mini-racer` library (sqreen/PyMiniRacer) is deprecated and no longer actively maintained. The recommended successor project is `mini-racer` (bpcreech/PyMiniRacer), which provides updated V8 versions and continued development. Users are strongly encouraged to migrate.
fix
Migrate to the `mini-racer` library by installing `pip install mini-racer` and updating import statements if necessary. Consult the `mini-racer` documentation for migration details.
affects: <=0.6.0
breakingAs of v0.6.0, V8 was switched to single-threaded mode by default to prevent crashes after process forks. If your application relied on multi-threaded V8 operations within the same process or expected specific behavior after forking, this change might affect stability or performance.
fix
Review application architecture for multi-process or multi-threaded JavaScript execution. If multi-threading within V8 is critical, investigate the `mini-racer` successor which might offer different configuration options or alternative solutions.
affects: 0.6.0
breakingVersion 0.6.0 switched V8 to strict mode by default. JavaScript code that previously ran without issues in non-strict mode (e.g., using undeclared variables, duplicate parameter names) might now throw errors.
fix
Ensure all JavaScript code executed within PyMiniRacer is compliant with ECMAScript strict mode. This typically involves fixing common JavaScript 'sloppy mode' practices.
affects: 0.6.0
gotchaBuilding PyMiniRacer from source is a resource-intensive process, requiring several GB of disk space and approximately 60 minutes. Furthermore, the V8 build system historically required a Python 2.7 executable.
fix
Prefer installing pre-built wheels (`pip install py-mini-racer`). If building from source is necessary, ensure you have sufficient disk space, time, and the correct Python 2.7 environment for the V8 build steps (even if using Python 3 for the final package). Consider using the `mini-racer` package, which has more modern build processes.
affects: <=0.6.0
gotchaThe `eval()` method in `py-mini-racer` only supports returning primitive data types (numbers, strings, buffers). To return composite types like JavaScript objects or arrays, you must use the `call()` method.
fix
Use `ctx.call("functionName", args...)` when expecting JavaScript objects, arrays, or other composite structures as return values. Use `ctx.eval("jsExpression")` for primitive returns.
affects: <=0.6.0
gotchaThis version of PyMiniRacer does not support attaching Python objects or functions to the JavaScript context, meaning you cannot directly call Python code from JavaScript.
fix
Design your application to handle callbacks from JavaScript to Python using alternative mechanisms (e.g., polling for results, or re-evaluating context in Python). The successor `mini-racer` introduced `wrap_py_function` for this functionality in v0.12.0.
affects: <=0.6.0
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'py_mini_racer'
The `py-mini-racer` library is deprecated and no longer actively maintained; it has been superseded by the `mini-racer` library. Users often encounter this when trying to install the old package or when pre-built wheels are unavailable for their environment, leading to build failures.
fix
Migrate to the `mini-racer` library by installing `pip install mini-racer` and updating import statements from `from py_mini_racer import MiniRacer` to `from mini_racer import MiniRacer`.
AttributeError: 'NoneType' object has no attribute 'mr_free_context'
This error occurs when the `MiniRacer` context's internal C++ extension (`self.ext`) is improperly initialized or has been prematurely deallocated during Python's garbage collection, leading to attempts to call a method on a `None` object. This often points to memory management issues within the deprecated `py-mini-racer` library.
fix
Explicitly manage the `MiniRacer` instance's lifecycle or, more reliably, migrate to the actively maintained `mini-racer` library which has improved memory management and provides a context manager for proper teardown.
Segmentation fault (core dumped)
Segmentation faults in `py-mini-racer` typically arise from incorrect memory handling within the embedded V8 engine, especially in complex scenarios involving multi-threading, process forks, or non-deterministic object destruction. Version 0.6.0 defaulted to single-threaded V8 to reduce such occurrences.
fix
Ensure JavaScript execution is isolated to single threads or separate processes. For robust solutions and improved stability, migrate to the `mini-racer` library, which features significant enhancements in threading and memory management to prevent such crashes.
TypeError: 'MiniRacer' object does not support item assignment
The original `py-mini-racer` library (version 0.6.0) was not designed to directly expose Python objects or functions to the JavaScript context through simple item assignment, which is a common expectation based on other V8 bindings.
fix
For `py-mini-racer`, direct Python-to-JavaScript callbacks are not supported. If this functionality is required, migrate to the `mini-racer` library (version 0.12.0 and above), which introduced the capability to expose asynchronous Python functions to the JavaScript context.
Upgrade
Version history
0.6.0latest on PyPI · released Apr 22, 2021
Audit
Dependencies
libgccoptionalRequired for Alpine Linux if building from source or for specific wheels.
libstdc++optionalRequired for Alpine Linux if building from source or for specific wheels.
Agent activity
16 hits · last 30 days
node
14
Resources
py-mini-racer — pip install py-mini-racer · libregistry