Skip to content

qwenger/quickjs

This branch is 3 commits ahead of, 28 commits behind PetterS/quickjs:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

40ef96f · Apr 8, 2022

History

97 Commits
Oct 12, 2020
Apr 8, 2022
Mar 30, 2021
Jul 17, 2019
Jul 19, 2019
Jul 12, 2019
Jul 15, 2019
Sep 30, 2020
Nov 4, 2020
Apr 8, 2022
Nov 23, 2021
Apr 8, 2022
Nov 23, 2021
Mar 9, 2020
Apr 2, 2022
Apr 8, 2022
Jul 20, 2019

Repository files navigation

CircleCI PyPI version fury.io

Just install with

pip install quickjs

Windows binaries are provided for:

  • 1.18.0: None.
  • 1.5.1–1.17.0: Python 3.9, 64-bit.
  • 1.5.0 and earlier: Python 3.7, 64-bit.

Usage

from quickjs import Function

f = Function("f", """
    function adder(a, b) {
        return a + b;
    }
    
    function f(a, b) {
        return adder(a, b);
    }
    """)

assert f(1, 2) == 3

Simple types like int, floats and strings are converted directly. Other types (dicts, lists) are converted via JSON by the Function class. The library is thread-safe if Function is used. If the Context class is used directly, it can only ever be accessed by the same thread. This is true even if the accesses are not concurrent.

Both Function and Context expose set_memory_limit and set_time_limit functions that allow limits for code running in production.

API

The Function class has, apart from being a callable, additional methods:

  • set_memory_limit
  • set_time_limit
  • set_max_stack_size
  • memory – returns a dict with information about memory usage.
  • add_callable – adds a Python function and makes it callable from JS.
  • execute_pending_job – executes a pending job (such as a async function or Promise).
  • set_promise_rejection_tracker - sets a callback receiving (promise, reason, is_handled) when a promise is rejected. Pass None to disable.

Documentation

For full functionality, please see test_quickjs.py

Developing

Use a poetry shell and make test should work from inside its virtual environment.

Packages

No packages published

Languages

  • Python 49.3%
  • C 48.9%
  • Makefile 1.6%
  • Batchfile 0.2%