Skip to main content

Python binding to Microsoft Chakra JavaScript engine

Project description

Build Status

PyChakra is a Python binding to Microsoft Chakra(v1.11.8) Javascript engine. PyChakra will be downloading pre-compiled Chakra binaries when install, so the process is fast and easy.

Chakra is a modern JavaScript engine for Microsoft Edge, it support 96% ES6 feature, Complete info see https://kangax.github.io/compat-table/es6/

Installation

pip install PyChakra

Usage

from PyChakra import Runtime

# create runtime instance
runtime = Runtime()

# eval JavaScript code
runtime.eval("(() => 2)();") # (True, '2')
runtime.eval("(() => a)();") # (False, "'a' is not defined")

# set or get variable
runtime.set_variable("foo", "'bar'") # True
runtime.get_variable("foo") # bar

API

eval(js_string)

Eval JavaScript code string.

Parameters:

  • js_string: str: JavaScript code string

Returns: (is_successful: bool, result: string|number)

  • is_successfully: indicates whether JavaScript is running successfully.
  • result:
    • if s is True, result is the JavaScript running return value.
    • if is_successfully is False and result is string, result is the JavaScript running exception.
    • if is_successfully is False and result is number, result is the chakra internal error code. see(github)

set_variable(variable_name: str, variable_value: any)

Set variable in global scope.

Parameters:

  • variable_name: str: JavaScript variable name.
  • variable_value: str: JavaScript variable value in Python str.

Returns: same as eval

get_variable(variable_name: str)

Get variable in global scope.

Parameters:

  • variable_name: str: JavaScript variable name.

Returns: variable_value: str - if returns value is None, it indicates there is no variable_name in the global scope.

Supports

  • Python2 >= 2.7
  • Python3 >= 3.4

Platform

  • macOS x64
  • Linux x64
  • Windows x86/x64 (tested on Windows 10 x64, Python 3.7)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
PyChakra-2.1.3-py3-none-any.whl (38.7 MB) Copy SHA256 hash SHA256 Wheel py3
PyChakra-2.1.3.tar.gz (38.5 MB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page