Skip to main content

Tangled QuickJS Javascript Engine binding library

Project description

Build Status Stable Version Coverage Python License

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

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.

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

thquickjs-0.9.25.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

thquickjs-0.9.25-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file thquickjs-0.9.25.tar.gz.

File metadata

  • Download URL: thquickjs-0.9.25.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.11.0 Linux/5.4.109+

File hashes

Hashes for thquickjs-0.9.25.tar.gz
Algorithm Hash digest
SHA256 846a55ba566c6970efdd362c744dcc988e4c7087fde07df839dcb3703b592b11
MD5 19ebfb997df9cfcb5ebc2c54550aa5cc
BLAKE2b-256 e9c50287fdac672e0e08de67c030fe5a984864af8d0c0497b9a8625174051b7b

See more details on using hashes here.

File details

Details for the file thquickjs-0.9.25-py3-none-any.whl.

File metadata

  • Download URL: thquickjs-0.9.25-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.11.0 Linux/5.4.109+

File hashes

Hashes for thquickjs-0.9.25-py3-none-any.whl
Algorithm Hash digest
SHA256 85a870f4aed95049863622e9c0d43cb25a22e2e551d1bd80a17a2d345bcff5e2
MD5 7610e52e11dc84a2e52214364a22fe6b
BLAKE2b-256 1a240e2ff1199eade04666a77d453cc50496a135b2baa800bf1ef3d4f463b27b

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