thquickjs


Namethquickjs JSON
Version 0.9.26 PyPI version JSON
download
home_pagehttps://gitlab.com/tangledlabs/thquickjs
SummaryTangled QuickJS Javascript Engine binding library
upload_time2022-11-30 17:07:30
maintainer
docs_urlNone
authorTangled
requires_python>=3.10,<4.0
licenseBSD 3-clause
keywords tangled thquickjs quickjs tangledhub tangledlab tangledcloud tangledgroup
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![Build][build-image]]()
[![Status][status-image]][pypi-project-url]
[![Stable Version][stable-ver-image]][pypi-project-url]
[![Coverage][coverage-image]]()
[![Python][python-ver-image]][pypi-project-url]
[![License][bsd3-image]][bsd3-url]


# 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

```bash
pip install thquickjs
```


## Simple Usage

```python
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

```python
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
```bash
docker-compose build thquickjs-test ; docker-compose run --rm thquickjs-test
```


## Coverage

```bash
docker-compose build thquickjs-coverage ; docker-compose run --rm -v $PWD:/test thquickjs-coverage
```


## Building
```bash
docker-compose build thquickjs-build ; docker-compose run --rm thquickjs-build
```


## Licensing

`thquickjs` is licensed under the BSD 3 license.

Check the [LICENSE](https://opensource.org/licenses/BSD-3-Clause) for details.


<!-- Badges -->
[bsd3-image]: https://img.shields.io/badge/License-BSD_3--Clause-blue.svg
[bsd3-url]: https://opensource.org/licenses/BSD-3-Clause
[build-image]: https://img.shields.io/gitlab/pipeline-status/tangledlabs/thquickjs?branch=main
[coverage-image]: https://img.shields.io/gitlab/pipeline-coverage/tangledlabs/thquickjs?branch=main

[pypi-project-url]: https://pypi.org/project/thquickjs/
[stable-ver-image]: https://img.shields.io/pypi/v/thquickjs?label=stable
[python-ver-image]: https://img.shields.io/pypi/pyversions/thquickjs.svg?logo=python&logoColor=FBE072
[status-image]: https://img.shields.io/pypi/status/thquickjs.svg

            

Raw data

            {
    "_id": null,
    "home_page": "https://gitlab.com/tangledlabs/thquickjs",
    "name": "thquickjs",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.10,<4.0",
    "maintainer_email": "",
    "keywords": "tangled,thquickjs,quickjs,tangledhub,tangledlab,tangledcloud,tangledgroup",
    "author": "Tangled",
    "author_email": "info@tangledgroup.com",
    "download_url": "https://files.pythonhosted.org/packages/c0/f2/5119b6b403bfaf0b0c3fe70d79f1798e1a390387e059eeaeeeb6b44b5dbd/thquickjs-0.9.26.tar.gz",
    "platform": null,
    "description": "[![Build][build-image]]()\n[![Status][status-image]][pypi-project-url]\n[![Stable Version][stable-ver-image]][pypi-project-url]\n[![Coverage][coverage-image]]()\n[![Python][python-ver-image]][pypi-project-url]\n[![License][bsd3-image]][bsd3-url]\n\n\n# thquickjs\n\n*Python* binding for *QuickJS* JavaScript Engine.\nQuickJS is a small and embeddable *JavaScript* engine. \nSafely evaluate untrusted JavaScript code. \nCreate and manipulate values inside the QuickJS runtime. \nExpose host functions to the QuickJS runtime.\n\n\n## Installation\n\n```bash\npip install thquickjs\n```\n\n\n## Simple Usage\n\n```python\nfrom thresult import unwrap\nfrom thquickjs.thquickjs import QuickJS\n\n\nqjs = QuickJS()\n\nwith unwrap():\n    # call JS function\n    code = '''\n        var f = (x) => {\n            return [ x, x, x ];\n        };\n    '''\n\n    qjs.eval(code)\n    f: callable = qjs.get_function('f')\n    result = f(10)\n    assert result == [10, 10, 10]\n```\n\n## Advanced Usage\n\n```python\nfrom thresult import unwrap\nfrom thquickjs.thquickjs import QuickJS\n\n\nqjs = QuickJS()\n\nwith unwrap():\n    # call JS function\n    code = '''\n        var f = (x) => {\n            return [ x ];\n        };\n    '''\n\n    qjs.eval(code)\n    f: callable = qjs.get_function('f')\n    result = f(10)\n    assert result == [10]\n\n    # register Python function inside JS runtime\n    py_name = 'pylam'\n    py_func = lambda x: json.dumps([x * 10])\n    qjs.add_callable(py_name, py_func)\n\n    # call Python function from JS runtime\n    code = '''\n        var g = (x) => {\n            return [ JSON.parse(pylam(x)) ];\n        };\n    '''\n\n    qjs.eval(code)\n    g: callable = qjs.get_function('g')\n    result = g(10)\n    assert result == [[100]]\n    \n    # call Python function registered in JS runtime\n    pylam = qjs.get(py_name)\n    result = pylam(5)\n    assert result == json.dumps([50])\n```\n\n\n## Testing\n```bash\ndocker-compose build thquickjs-test ; docker-compose run --rm thquickjs-test\n```\n\n\n## Coverage\n\n```bash\ndocker-compose build thquickjs-coverage ; docker-compose run --rm -v $PWD:/test thquickjs-coverage\n```\n\n\n## Building\n```bash\ndocker-compose build thquickjs-build ; docker-compose run --rm thquickjs-build\n```\n\n\n## Licensing\n\n`thquickjs` is licensed under the BSD 3 license.\n\nCheck the [LICENSE](https://opensource.org/licenses/BSD-3-Clause) for details.\n\n\n<!-- Badges -->\n[bsd3-image]: https://img.shields.io/badge/License-BSD_3--Clause-blue.svg\n[bsd3-url]: https://opensource.org/licenses/BSD-3-Clause\n[build-image]: https://img.shields.io/gitlab/pipeline-status/tangledlabs/thquickjs?branch=main\n[coverage-image]: https://img.shields.io/gitlab/pipeline-coverage/tangledlabs/thquickjs?branch=main\n\n[pypi-project-url]: https://pypi.org/project/thquickjs/\n[stable-ver-image]: https://img.shields.io/pypi/v/thquickjs?label=stable\n[python-ver-image]: https://img.shields.io/pypi/pyversions/thquickjs.svg?logo=python&logoColor=FBE072\n[status-image]: https://img.shields.io/pypi/status/thquickjs.svg\n",
    "bugtrack_url": null,
    "license": "BSD 3-clause",
    "summary": "Tangled QuickJS Javascript Engine binding library",
    "version": "0.9.26",
    "split_keywords": [
        "tangled",
        "thquickjs",
        "quickjs",
        "tangledhub",
        "tangledlab",
        "tangledcloud",
        "tangledgroup"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "f647df755555604915ffe435896154f5",
                "sha256": "e3a183f538bcc71ee9400da29723ff480b4e7ddd558d64f3c01b9be59ef94052"
            },
            "downloads": -1,
            "filename": "thquickjs-0.9.26-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f647df755555604915ffe435896154f5",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10,<4.0",
            "size": 4142,
            "upload_time": "2022-11-30T17:07:28",
            "upload_time_iso_8601": "2022-11-30T17:07:28.895650Z",
            "url": "https://files.pythonhosted.org/packages/3c/ae/d85ad396a4b176a5e84f82577ec8ee8a6eeca508ea0aa7eb721d54a4489b/thquickjs-0.9.26-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "46a84ca3892789c5b5c81cfac2c3ae99",
                "sha256": "cdf955469144153baff2c704eea64c6e49222bd4100c784cc3e21e6f0a991224"
            },
            "downloads": -1,
            "filename": "thquickjs-0.9.26.tar.gz",
            "has_sig": false,
            "md5_digest": "46a84ca3892789c5b5c81cfac2c3ae99",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10,<4.0",
            "size": 4227,
            "upload_time": "2022-11-30T17:07:30",
            "upload_time_iso_8601": "2022-11-30T17:07:30.357134Z",
            "url": "https://files.pythonhosted.org/packages/c0/f2/5119b6b403bfaf0b0c3fe70d79f1798e1a390387e059eeaeeeb6b44b5dbd/thquickjs-0.9.26.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-11-30 17:07:30",
    "github": false,
    "gitlab": true,
    "bitbucket": false,
    "gitlab_user": "tangledlabs",
    "gitlab_project": "thquickjs",
    "lcname": "thquickjs"
}
        
Elapsed time: 0.01278s