Skip to main content

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

Project description

Documentation Status 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

pip install deno_vm

Usage

Most of the APIs are bound to worker-vm.

Simple eval:

from deno_vm import eval

print(eval("['foo', 'bar'].join()"))

Use VM:

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:

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.5.0 (Oct 10, 2023)

    • Switch to deno_vm.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

deno_vm-0.5.0.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

deno_vm-0.5.0-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file deno_vm-0.5.0.tar.gz.

File metadata

  • Download URL: deno_vm-0.5.0.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.11

File hashes

Hashes for deno_vm-0.5.0.tar.gz
Algorithm Hash digest
SHA256 1a63eb1cc4d4dc4730c0e920037ba90c32a25a61b1518dedd569bbcc084932cf
MD5 bec789b0a4e01c2f088e0fc2d45526b7
BLAKE2b-256 31bb1a302d719cf5a8a22864e8ac0ecf6efc75b59a0f920fdcc016312de82706

See more details on using hashes here.

File details

Details for the file deno_vm-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: deno_vm-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.11

File hashes

Hashes for deno_vm-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f327654e297dede75023a21bfe0c02205b8dcc27a56ded9de9edcf23ef47491d
MD5 f73f9233a00c925ccbe7a4c9881eada1
BLAKE2b-256 b7194af13bd5503c74211c2667c0964cb7524272da9d992b6be23d76c4f16c67

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page