deno-vm


Namedeno-vm JSON
Version 0.6.0 PyPI version JSON
download
home_pagehttps://github.com/eight04/deno_vm
SummaryA binding to Deno + worker-vm, helps you execute JavaScript safely.
upload_time2024-03-04 12:17:58
maintainer
docs_urlNone
authoreight
requires_python
licenseMIT
keywords deno js sandbox execute javascript
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            deno_vm
========

.. image:: https://readthedocs.org/projects/deno-vm/badge/?version=latest
   :target: https://deno-vm.readthedocs.io/en/latest/?badge=latest
   :alt: Documentation Status
   
.. image:: https://github.com/eight04/deno_vm/actions/workflows/test.yml/badge.svg
   :target: https://github.com/eight04/deno_vm/actions/workflows/test.yml
   :alt: test

A Python 3 to Deno + worker-vm binding, helps you execute JavaScript safely.

How it works
------------

The module launches a Deno REPL server, which can be communicated with JSON. All JavaScript code are encoded in JSON and sent to the server. After the server executing the code in vm, the result is sent back to Python.

Install
-------

Install Deno
^^^^^^^^^^^^

Follow the instruction here:
https://docs.deno.com/runtime/manual/getting_started/installation

Also make sure ``deno`` command works as expected:
https://docs.deno.com/runtime/manual/getting_started/installation#testing-your-installation

Install deno_vm
^^^^^^^^^^^^^^^

.. code-block:: sh

   pip install deno_vm

Usage
-----

Most of the APIs are bound to `worker-vm <https://github.com/eight04/worker-vm>`__.

Simple eval:

.. code-block:: python

   from deno_vm import eval
   
   print(eval("['foo', 'bar'].join()"))
   
Use VM:

.. code-block:: python

   from deno_vm import VM
   
   with VM() as vm:
      vm.run("""
         var sum = 0, i;
         for (i = 0; i < 10; i++) sum += i;
      """)
      print(vm.run("sum"))
      
It is possible to do async task with Promise:

.. code-block:: python

   from datetime import datetime
   from deno_vm import VM

   js = """
   function test() {
      return new Promise(resolve => {
         setTimeout(() => {
            resolve("hello")
         }, 3000);
      });
   };
   """
   with VM() as vm:
      vm.run(js)
      print(datetime.now())
      print(vm.call("test"))
      print(datetime.now())
      
API reference
-------------

http://deno_vm.readthedocs.io/

Changelog
---------

- 0.6.0 (Mar 4, 2024)

  - Change: use --unstable-worker-options instead of --unstable.
  - Change: vendor deno dependencies. Now deno_vm doesn't require network and filesystem write access.
  - Fix: suppres cleanup error.
  - Fix: improve uninitialized error message.

-  0.5.1 (Oct 10, 2023)

   -  Fix: unable to pass initial code to ``VM()``.

-  0.5.0 (Oct 10, 2023)

   -  Switch to deno_vm.
   

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/eight04/deno_vm",
    "name": "deno-vm",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "deno,js,sandbox,execute,javascript",
    "author": "eight",
    "author_email": "eight04@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/7f/81/d20ca85b73ec8fbf498132bb51ca22f8e455e036ce632a3f6ef3e7f805ce/deno_vm-0.6.0.tar.gz",
    "platform": null,
    "description": "deno_vm\r\n========\r\n\r\n.. image:: https://readthedocs.org/projects/deno-vm/badge/?version=latest\r\n   :target: https://deno-vm.readthedocs.io/en/latest/?badge=latest\r\n   :alt: Documentation Status\r\n   \r\n.. image:: https://github.com/eight04/deno_vm/actions/workflows/test.yml/badge.svg\r\n   :target: https://github.com/eight04/deno_vm/actions/workflows/test.yml\r\n   :alt: test\r\n\r\nA Python 3 to Deno + worker-vm binding, helps you execute JavaScript safely.\r\n\r\nHow it works\r\n------------\r\n\r\nThe module launches a Deno REPL server, which can be communicated with JSON. All JavaScript code are encoded in JSON and sent to the server. After the server executing the code in vm, the result is sent back to Python.\r\n\r\nInstall\r\n-------\r\n\r\nInstall Deno\r\n^^^^^^^^^^^^\r\n\r\nFollow the instruction here:\r\nhttps://docs.deno.com/runtime/manual/getting_started/installation\r\n\r\nAlso make sure ``deno`` command works as expected:\r\nhttps://docs.deno.com/runtime/manual/getting_started/installation#testing-your-installation\r\n\r\nInstall deno_vm\r\n^^^^^^^^^^^^^^^\r\n\r\n.. code-block:: sh\r\n\r\n   pip install deno_vm\r\n\r\nUsage\r\n-----\r\n\r\nMost of the APIs are bound to `worker-vm <https://github.com/eight04/worker-vm>`__.\r\n\r\nSimple eval:\r\n\r\n.. code-block:: python\r\n\r\n   from deno_vm import eval\r\n   \r\n   print(eval(\"['foo', 'bar'].join()\"))\r\n   \r\nUse VM:\r\n\r\n.. code-block:: python\r\n\r\n   from deno_vm import VM\r\n   \r\n   with VM() as vm:\r\n      vm.run(\"\"\"\r\n         var sum = 0, i;\r\n         for (i = 0; i < 10; i++) sum += i;\r\n      \"\"\")\r\n      print(vm.run(\"sum\"))\r\n      \r\nIt is possible to do async task with Promise:\r\n\r\n.. code-block:: python\r\n\r\n   from datetime import datetime\r\n   from deno_vm import VM\r\n\r\n   js = \"\"\"\r\n   function test() {\r\n      return new Promise(resolve => {\r\n         setTimeout(() => {\r\n            resolve(\"hello\")\r\n         }, 3000);\r\n      });\r\n   };\r\n   \"\"\"\r\n   with VM() as vm:\r\n      vm.run(js)\r\n      print(datetime.now())\r\n      print(vm.call(\"test\"))\r\n      print(datetime.now())\r\n      \r\nAPI reference\r\n-------------\r\n\r\nhttp://deno_vm.readthedocs.io/\r\n\r\nChangelog\r\n---------\r\n\r\n- 0.6.0 (Mar 4, 2024)\r\n\r\n  - Change: use --unstable-worker-options instead of --unstable.\r\n  - Change: vendor deno dependencies. Now deno_vm doesn't require network and filesystem write access.\r\n  - Fix: suppres cleanup error.\r\n  - Fix: improve uninitialized error message.\r\n\r\n-  0.5.1 (Oct 10, 2023)\r\n\r\n   -  Fix: unable to pass initial code to ``VM()``.\r\n\r\n-  0.5.0 (Oct 10, 2023)\r\n\r\n   -  Switch to deno_vm.\r\n   \r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A binding to Deno + worker-vm, helps you execute JavaScript safely.",
    "version": "0.6.0",
    "project_urls": {
        "Homepage": "https://github.com/eight04/deno_vm"
    },
    "split_keywords": [
        "deno",
        "js",
        "sandbox",
        "execute",
        "javascript"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "86fe56b2f5b90b45ff1493166f0d8af96b86e273590c0ba2bd440edf19dbc930",
                "md5": "ba944ae5cd1b3f91ae817dfe42101663",
                "sha256": "dd24e5a6c936e1fc534dfe42f170e34950ee0e0a895b54b9ae191496e8821f48"
            },
            "downloads": -1,
            "filename": "deno_vm-0.6.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ba944ae5cd1b3f91ae817dfe42101663",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 46953,
            "upload_time": "2024-03-04T12:17:56",
            "upload_time_iso_8601": "2024-03-04T12:17:56.314684Z",
            "url": "https://files.pythonhosted.org/packages/86/fe/56b2f5b90b45ff1493166f0d8af96b86e273590c0ba2bd440edf19dbc930/deno_vm-0.6.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7f81d20ca85b73ec8fbf498132bb51ca22f8e455e036ce632a3f6ef3e7f805ce",
                "md5": "2a31279762b0e5cea565ae4a314a69c5",
                "sha256": "9bc7f59035bd197797498f50edeb7c09eedaea8769db4456fa0cb8d1bfd09ca6"
            },
            "downloads": -1,
            "filename": "deno_vm-0.6.0.tar.gz",
            "has_sig": false,
            "md5_digest": "2a31279762b0e5cea565ae4a314a69c5",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 29315,
            "upload_time": "2024-03-04T12:17:58",
            "upload_time_iso_8601": "2024-03-04T12:17:58.158998Z",
            "url": "https://files.pythonhosted.org/packages/7f/81/d20ca85b73ec8fbf498132bb51ca22f8e455e036ce632a3f6ef3e7f805ce/deno_vm-0.6.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-04 12:17:58",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "eight04",
    "github_project": "deno_vm",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "deno-vm"
}
        
Elapsed time: 0.19552s