deno_vm
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
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.
Metadata
Release files for deno-vm 0.6.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| deno_vm-0.6.0.tar.gz | 29.3 kB | Without provenance | Details for deno_vm-0.6.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| deno_vm-0.6.0-py3-none-any.whl | Python 3 | none | any | Details for deno_vm-0.6.0-py3-none-any.whl |
Total release size: 76.3 kB
Release files / deno_vm-0.6.0.tar.gz
| Download URL | deno_vm-0.6.0.tar.gz |
|---|---|
| Size | 29.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9bc7f59035bd197797498f50edeb7c09eedaea8769db4456fa0cb8d1bfd09ca6
|
|
BLAKE2b-256 checksum How to use checksums |
7f81d20ca85b73ec8fbf498132bb51ca22f8e455e036ce632a3f6ef3e7f805ce
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.12.2
|
Release files / deno_vm-0.6.0-py3-none-any.whl
| Download URL | deno_vm-0.6.0-py3-none-any.whl |
|---|---|
| Size | 47.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dd24e5a6c936e1fc534dfe42f170e34950ee0e0a895b54b9ae191496e8821f48
|
|
BLAKE2b-256 checksum How to use checksums |
86fe56b2f5b90b45ff1493166f0d8af96b86e273590c0ba2bd440edf19dbc930
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.12.2
|
Security for deno-vm 0.6.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.