Archived
This project has been archived by its maintainers, and is no longer receiving any updates.
thquickjs
Python binding for QuickJS JavaScript Engine. QuickJS is a small and embeddable JavaScript engine. Safely evaluate untrusted JavaScript code. Create and manipulate values inside the QuickJS runtime. Expose host functions to the QuickJS runtime.
Installation
pip install thquickjs
Simple Usage
from thresult import unwrap
from thquickjs.thquickjs import QuickJS
qjs = QuickJS()
with unwrap():
# call JS function
code = '''
var f = (x) => {
return [ x, x, x ];
};
'''
qjs.eval(code)
f: callable = qjs.get_function('f')
result = f(10)
assert result == [10, 10, 10]
Advanced Usage
from thresult import unwrap
from thquickjs.thquickjs import QuickJS
qjs = QuickJS()
with unwrap():
# call JS function
code = '''
var f = (x) => {
return [ x ];
};
'''
qjs.eval(code)
f: callable = qjs.get_function('f')
result = f(10)
assert result == [10]
# register Python function inside JS runtime
py_name = 'pylam'
py_func = lambda x: json.dumps([x * 10])
qjs.add_callable(py_name, py_func)
# call Python function from JS runtime
code = '''
var g = (x) => {
return [ JSON.parse(pylam(x)) ];
};
'''
qjs.eval(code)
g: callable = qjs.get_function('g')
result = g(10)
assert result == [[100]]
# call Python function registered in JS runtime
pylam = qjs.get(py_name)
result = pylam(5)
assert result == json.dumps([50])
Testing
docker-compose build thquickjs-test ; docker-compose run --rm thquickjs-test
Coverage
docker-compose build thquickjs-coverage ; docker-compose run --rm -v $PWD:/test thquickjs-coverage
Building
docker-compose build thquickjs-build ; docker-compose run --rm thquickjs-build
Licensing
thquickjs is licensed under the BSD 3 license.
Check the LICENSE for details.
Metadata
Release files for thquickjs 0.9.26
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| thquickjs-0.9.26.tar.gz | 4.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| thquickjs-0.9.26-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.4 kB
Release files / thquickjs-0.9.26.tar.gz
| Download URL | thquickjs-0.9.26.tar.gz |
|---|---|
| Size | 4.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cdf955469144153baff2c704eea64c6e49222bd4100c784cc3e21e6f0a991224
|
|
BLAKE2b-256 checksum How to use checksums |
c0f25119b6b403bfaf0b0c3fe70d79f1798e1a390387e059eeaeeeb6b44b5dbd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.2.2 CPython/3.11.0 Linux/5.4.109+
|
Release files / thquickjs-0.9.26-py3-none-any.whl
| Download URL | thquickjs-0.9.26-py3-none-any.whl |
|---|---|
| Size | 4.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e3a183f538bcc71ee9400da29723ff480b4e7ddd558d64f3c01b9be59ef94052
|
|
BLAKE2b-256 checksum How to use checksums |
3caed85ad396a4b176a5e84f82577ec8ee8a6eeca508ea0aa7eb721d54a4489b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.2.2 CPython/3.11.0 Linux/5.4.109+
|