{"id":4630,"library":"mini-racer","title":"Mini Racer","description":"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.","status":"active","version":"0.14.1","language":"en","source_language":"en","source_url":"https://github.com/bpcreech/PyMiniRacer","tags":["javascript","v8","embed","runtime","nodejs"],"install":[{"cmd":"pip install mini-racer","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"note":"Since v0.12.0, the `MiniRacer` class is directly importable from the `py_mini_racer` module. Previously, it was accessed as `py_mini_racer.MiniRacer`.","wrong":"import py_mini_racer; mr = py_mini_racer.MiniRacer()","symbol":"MiniRacer","correct":"from py_mini_racer import MiniRacer"},{"note":"Used for catching JavaScript execution errors.","symbol":"MiniRacerEvalError","correct":"from py_mini_racer import MiniRacerEvalError"}],"quickstart":{"code":"from py_mini_racer import MiniRacer, MiniRacerEvalError\n\n# Initialize a MiniRacer context\nmr = MiniRacer()\n\n# Evaluate JavaScript code to define a function\nmr.eval(\"function add(a, b) { return a + b; }\")\n\n# Call the JavaScript function with Python arguments\nresult = mr.call(\"add\", 1, 2)\nprint(f\"Result of add(1, 2): {result}\")\n\n# Evaluate a simple expression (e.g., getting V8 version)\njs_version = mr.eval(\"process.versions.v8\")\nprint(f\"V8 version: {js_version}\")\n\n# Demonstrate error handling\ntry:\n    mr.eval(\"throw new Error('Something went wrong!');\")\nexcep MiniRacerEvalError as e:\n    print(f\"Caught MiniRacerEvalError: {e}\")","lang":"python","description":"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`."},"warnings":[{"fix":"Update your import statements from `import py_mini_racer; mr = py_mini_racer.MiniRacer()` to `from py_mini_racer import MiniRacer; mr = MiniRacer()`.","message":"The import path for `MiniRacer` changed significantly. Direct class import `from py_mini_racer import MiniRacer` is now required.","severity":"breaking","affected_versions":">=0.12.0"},{"fix":"Wrap your `mr.eval()` and `mr.call()` calls in `try...except MiniRacerEvalError` blocks to catch and handle JS errors correctly.","message":"JavaScript errors no longer propagate as generic Python exceptions but raise a specific `MiniRacerEvalError`.","severity":"breaking","affected_versions":">=0.12.0"},{"fix":"Remove the `v8_args` parameter when initializing `MiniRacer`. Custom V8 arguments are no longer directly configurable via the constructor.","message":"The `v8_args` parameter was removed from the `MiniRacer` constructor.","severity":"breaking","affected_versions":">=0.13.0"},{"fix":"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.","message":"The `timeout` parameter was removed from the `MiniRacer` constructor. While it was briefly available in v0.12.x, it was removed from the constructor in v0.13.0.","severity":"breaking","affected_versions":">=0.13.0"},{"fix":"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.","message":"A `MiniRacer` instance is NOT thread-safe. Accessing a single instance from multiple threads concurrently can lead to crashes or undefined behavior.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}