{"id":21895880,"url":"https://github.com/seahoh/jsengine","last_synced_at":"2025-04-15T16:38:54.726Z","repository":{"id":62572753,"uuid":"444770000","full_name":"SeaHOH/jsengine","owner":"SeaHOH","description":"JSEngine is a simple wrapper of Javascript engines.","archived":false,"fork":false,"pushed_at":"2023-01-01T07:22:23.000Z","size":69,"stargazers_count":15,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-30T04:44:38.033Z","etag":null,"topics":["chakra","engine","execjs","javascript","js","node","quickjs","v8"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SeaHOH.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-01-05T10:59:21.000Z","updated_at":"2023-06-29T17:38:28.000Z","dependencies_parsed_at":"2023-01-31T21:01:43.116Z","dependency_job_id":null,"html_url":"https://github.com/SeaHOH/jsengine","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SeaHOH%2Fjsengine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SeaHOH%2Fjsengine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SeaHOH%2Fjsengine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SeaHOH%2Fjsengine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SeaHOH","download_url":"https://codeload.github.com/SeaHOH/jsengine/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249109808,"owners_count":21214227,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chakra","engine","execjs","javascript","js","node","quickjs","v8"],"created_at":"2024-11-28T13:41:03.464Z","updated_at":"2025-04-15T16:38:54.708Z","avatar_url":"https://github.com/SeaHOH.png","language":"Python","readme":"# JSEngine\n\nThis is a simple wrapper of Javascript engines, it wraps the Javascript\ninterpreter for Python use.\n\nThere are two ways to call interpreters, via dynamic library loading is internal\ncall which is faster than the other one, via subprocess is external call.\n\n- System's built-in Javascript interpreter:\n\n    **macOS**: JavascriptCore  \n    **Linux**: Gjs on Gnome, CJS on Cinnamon, etc.  \n    **Windows**: Chakra (internal call, but not applicable to Windows 7)  \n\n- Python bindings (Recommend, internal call):\n\n    [QuickJS](https://github.com/PetterS/quickjs)  \n    [PyChakra](https://github.com/zhengrenzhe/PyChakra)  \n    [PyMiniRacer (V8)](https://github.com/sqreen/PyMiniRacer)\n    (Caused by [a scope issue](https://github.com/sqreen/PyMiniRacer/issues/148),\n    its work process is similar to external call now, to fix the scope issue,\n    [Esprima](https://github.com/Kronuz/esprima-python) is needed)  \n\n- Any installed external Javascript interpreters, e.g.\n\n    SpiderMonkey, Node.js, QuickJS, etc.\n\nJSEngine used to be part of [YKDL](https://github.com/SeaHOH/ykdl),\nwhich created by [@coslyk](https://github.com/coslyk).\n\n\n# Installation\nInstall from \n[![version](https://img.shields.io/pypi/v/jsengine)](https://pypi.org/project/jsengine/)\n[![package format](https://img.shields.io/pypi/format/jsengine)](https://pypi.org/project/jsengine/#files)\n[![monthly downloads](https://img.shields.io/pypi/dm/jsengine)](https://pypi.org/project/jsengine/#files)\n\n    pip install jsengine\n\nOr download and Install from source code\n\n    python setup.py install\n\n# Compatibility\n- Python \u003e= 2.7\n\n\n# Usage\n\n```python\nimport jsengine\njsengine.eval('\"Hello, world!\"')  # =\u003e 'Hello, world!'\n```\n\nUse a JSEngine context.\n\n```python\ntry:\n    ctx1 = jsengine.jsengine()\nexcept jsengine.RuntimeError:\n    ...  # do something if useless\n\nif jsengine.JSEngine is None:\n    ...  # do something if useless\nelse:\n    ctx2 = jsengine.JSEngine(\"\"\"\n            function add(x, y) {\n                return x + y;\n            }\n            \"\"\")\n\nctx1.eval('1 + 1')  # =\u003e 2\n\n# call funtion\nctx2.call(\"add\", 1, 2)  # =\u003e 3\n\n# append new script\nctx1.append(\"\"\"\n    function square(x) {\n        return x ** 2;\n    }\n    \"\"\")\nctx1.call(\"square\", 9)  # =\u003e 81\n```\n\nUse a specified external Javascript interpreter.\n\n```python\nbinary = binary_name or binary_path\nkwargs = {\n    'name': 'None or any string',  # see ExternalInterpreterNameAlias.keys()\n    'tempfile': True,              # use tempfile or not. Default is False, fallback is True\n    'evalstring': True,            # can run command string as Javascript or can not,\n                                   # just like '-e script_code'\n                                   # instead of True, supported argument can be passed,\n                                   # e.g. '--eval', '--execute'\n    'args': [args1, args2, ...]    # arguments used for interpreter\n}\n\n# case 1\ninterpreter = jsengine.ExternalInterpreter.get(binary, **kwargs)\nif interpreter:\n    # found\n    ctx = jsengine.ExternalJSEngine(interpreter)\n\n# case 2\nif jsengine.set_external_interpreter(binary, **kwargs):\n    # set default external interpreter OK\n    ctx = jsengine.ExternalJSEngine()\n\n# case 3, maybe get default fallback instead of your specified\ntry:\n    ctx = jsengine.ExternalJSEngine(interpreter=binary, **kwargs)\nexcept jsengine.RuntimeError:\n    ...  # do something if useless\n```\n\nUse threading lock. Javascript source itself always be ran in single threaded,\nthat just make the APIs can be used in multithreadeding.\n```python\njsengine.set_threading(True)   # MUST enable befor using, it's disabled by default\n\nctx_quickjs = jsengine.QuickJSEngine()\nctx_chakra = jsengine.ChakraJSEngine()   # internal chakra will create an extra thread per context\nctx_v8 = jsengine.V8JSEngine()\nctx_exter = jsengine.ExternalJSEngine()  # external interpreter will be called one by one with context\n\n...  # do multithreading\n\njsengine.set_threading(False)  # disable is not necessary\n```\n\n\n# Internal VS. External\n|                 | QuickJSEngine  | ChakraJSEngine | V8JSEngine (esprima) | V8JSEngine \\**       | ExternalJSEngine     |\n| --------------- | :------------: | :------------: | :------------------: | :------------------: | :------------------: |\n| Load backend on | import         | import or init | init                 | init                 | every fetch result   |\n| Loading speed   | fastest        | fast           | very slow with py3   | fast                 | very slow            |\n| Performance     |                | highest        | high                 | low, if much results | low, if much results |\n| Fetch result    | run the passed | run the passed | run the passed       | run all/full source  | run all/full source  |\n\n\\* Fetch results means call `eval()/call()`.  \n\\** V8JSEngine is now similar to ExternalJSEngine which caused by scope issue.  \n\n\n# License\nJSEngine is released under the [MIT License](https://github.com/SeaHOH/jsengine/blob/master/LICENSE).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseahoh%2Fjsengine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fseahoh%2Fjsengine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseahoh%2Fjsengine/lists"}