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 = '''
        function f(x) {
            return 40 + x;
        }

        f
    '''

    f: callable = qjs.eval(code)
    result = f(10)
    assert result == 50

    # register Python function inside JS runtime
    py_name = 'pylam'
    py_func = lambda x: x * 10
    qjs.add_callable(py_name, py_func)

    # call Python function from JS runtime
    code = '''
        function g(x) {
            return pylam(x);
        }

        g
    '''

    g: callable = qjs.eval(code)
    result = g(10)
    assert result == 100
    
    # call Python function registered in JS runtime
    pylam = qjs.get(py_name)
    result = pylam(5)
    assert result == 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.24.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: thquickjs-0.9.24.tar.gz
  • Upload date:
  • Size: 4.1 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.24.tar.gz
Algorithm Hash digest
SHA256 be478d0129e7c10bbd84c78ce08cca219ac774de5227f3c2cc59017d2d4d33cf
MD5 be60df02a5b34d8567310eb9c5593818
BLAKE2b-256 e88780380f8500e207c0591d7f4191f5ec6b65b5c10955dc5bc08add362c077e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: thquickjs-0.9.24-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.24-py3-none-any.whl
Algorithm Hash digest
SHA256 586118c8a2539e39b028020419fba5a9781e5516bf9b8f9a6abbbd80a9b0f4d4
MD5 6f32a553dfaf863d7e4fdf2c95220a74
BLAKE2b-256 ab5eed75f787499c547a2bef27105074ae2f7113a13d4821012d599acdf9ea7b

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