• Stars
    star
    175
  • Rank 218,059 (Top 5 %)
  • Language
    Python
  • License
    MIT License
  • Created over 5 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Thin Python wrapper of https://bellard.org/quickjs/

CircleCI PyPI version fury.io

Just install with

pip install quickjs

Binaries are provided for:

  • 1.19.2 and later: Python 3.7-3.10, 64-bit for Windows, macOS and GNU/Linux.
  • 1.18.0-1.19.1: None.
  • 1.5.1–1.17.0: Python 3.9, 64-bit for Windows.
  • 1.5.0 and earlier: Python 3.7, 64-bit for Windows.

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).

Documentation

For full functionality, please see test_quickjs.py

Developing

This project uses a git submodule for the upstream code, so clone it with the --recurse-submodules option or run git submodule update --init --recursive afterwards.

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

More Repositories

1

monte-carlo-tree-search

Monte Carlo Tree Search with UCT with a couple of example games.
C++
151
star
2

clang-wasm

How to build webassembly files with nothing other than standard Clang/llvm.
C++
143
star
3

SuiteSparse

A shallow fork of SuiteSparse adding build files for Visual Studio and support for ACML
C
100
star
4

monolith

A C++ monorepo for discrete and continuous optimization. Batteries included!
Jupyter Notebook
98
star
5

patch-inpainting

Image inpainting using coherency senstitive hashing
MATLAB
52
star
6

spii

A library for unconstrained minimization of smooth functions using Newton's method or L-BFGS.
C++
35
star
7

submodular

Library for minimizing Pseudo-Boolean functions
C++
27
star
8

qepcad

Quantifier Elimination by Partial Cylindrical Algebraic Decomposition
C
24
star
9

realtimechess

In Real-time Chess (or Kung-Fu Chess, Ninja Chess), all pieces can be moved simultaneously!
Python
20
star
10

sexton

Hex editor written in Python
Python
16
star
11

opencv_srgb_gamma

sRGB gamma tranformations in C++ and Python
Jupyter Notebook
16
star
12

easy-IP

C++ modelling library for integer programming
C++
15
star
13

CXSparse

A shallow fork of CXSparse adding build files for Visual Studio
C
14
star
14

surfmex

Extremely simple wrapper around OpenCV for SURF
C++
13
star
15

curve_extraction

C++ shortest path with curvature and torsion taken into account
C++
12
star
16

rapidsvg

Renders SVG files containing lines very quickly.
C++
7
star
17

glpk

A shallow fork of GLPK made re-entrant with CMake build files. Tests pass with Visual Studio, Clang, and GCC.
C
7
star
18

hep-2

HEp-2 Cells Classification
C
6
star
19

reverb

Calculates the room RT60 reverberation time by sending out tones
Python
4
star
20

numpy_display

Formats numpy matrices in an IPython Notebook
Python
2
star
21

wikipedia

Scripts for automated processing of Wikipedia database dumps
Python
2
star
22

surfaces

Curvature regularization for surfaces
C++
1
star
23

emscripten_cmake

A simple example showing how to use Emscripten with CMake
C++
1
star
24

quickcd

Two-hour project: Quick directory switching with statistics and fuzzy matching.
Python
1
star