{"id":6352,"library":"dukpy","title":"DukPy","description":"DukPy is a simple, lightweight JavaScript interpreter for Python, embedding the Duktape JavaScript engine. It allows executing JavaScript code directly from Python applications. As of version 0.5.1, it supports modern Python versions (up to 3.14) and maintains a steady release cadence, often aligning with new Python releases or Duktape engine updates.","status":"active","version":"0.5.1","language":"en","source_language":"en","source_url":"https://github.com/amol-/dukpy","tags":["javascript","interpreter","duktape","javascript-engine","embedding"],"install":[{"cmd":"pip install dukpy","lang":"bash","label":"Install DukPy"}],"dependencies":[],"imports":[{"symbol":"evaljs","correct":"import dukpy; dukpy.evaljs(...)"}],"quickstart":{"code":"import dukpy\n\n# Basic JavaScript evaluation\nresult = dukpy.evaljs(\"1 + 2\")\nprint(f\"1 + 2 = {result}\")\n\n# Passing data to JavaScript\nresult = dukpy.evaljs(\"a + b\", data={'a': 10, 'b': 20})\nprint(f\"a + b (with data) = {result}\")\n\n# Calling Python functions from JavaScript\ndef my_python_sum(x, y):\n    return x + y\n\njs_code = \"var sum = my_python_sum(5, 7); sum;\"\nresult = dukpy.evaljs(js_code, python_functions={'my_python_sum': my_python_sum})\nprint(f\"JS calling Python function = {result}\")","lang":"python","description":"Demonstrates basic JavaScript evaluation, passing data from Python to JavaScript, and calling Python functions from within JavaScript."},"warnings":[{"fix":"Upgrade Python to version 3.7 or newer. If legacy Python is unavoidable, use an older DukPy version (not recommended).","message":"Support for older Python versions (2.x, 3.4-3.6) has been deprecated and eventually removed. Modern versions of DukPy require Python 3.7+.","severity":"breaking","affected_versions":"<0.3.0"},{"fix":"Upgrade to DukPy 0.4.0 or newer, which switched to CESU-8 encoding for better Unicode handling.","message":"Versions prior to 0.4.0 might crash or produce incorrect output when handling JavaScript strings containing unicode emoji or other non-Basic Multilingual Plane (BMP) characters, due to encoding issues.","severity":"gotcha","affected_versions":"<0.4.0"},{"fix":"Upgrade to DukPy 0.2.2 or newer to benefit from the memory leak fix.","message":"Versions prior to 0.2.2 contained a memory leak in the `dukpy.evaljs` function, which could lead to increased memory consumption in long-running applications.","severity":"gotcha","affected_versions":"<0.2.2"},{"fix":"Upgrade to DukPy 0.3.1 or newer for improved error messages, and always double-check function names when setting up Python callbacks.","message":"When using `python_functions` to expose Python callables to JavaScript, ensure the function name matches exactly. Older versions (pre-0.3.1) might provide less informative error messages if the function is not found.","severity":"gotcha","affected_versions":"<0.3.1"},{"fix":"Ensure a C compiler is installed, or use an environment where pre-built wheels are provided (e.g., common Linux distros, macOS, Windows with official Python releases).","message":"If pre-built wheels are not available for your specific platform/Python version, `pip install dukpy` will attempt to build from source, which requires a C compiler (e.g., GCC or Clang) installed on your system.","severity":"gotcha","affected_versions":"All versions (when building from source)"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z"}