🔥✨🚀Python binding to Microsoft Chakra JavaScript Engine.
PyChakra is a Python binding to Microsoft Chakra(v1.11.16) Javascript engine.
Chakra is a modern JavaScript engine for Microsoft Edge, it support 96% ES6 feature, Complete info see https://kangax.github.io/compat-table/es6/
pip install PyChakra
from PyChakra import Runtime
# create runtime instance
runtime = Runtime()
# eval JavaScript code
runtime.eval("(() => 2)();") # (True, 2)
runtime.eval("(() => a)();") # (False, "ReferenceError: 'a' is not defined")
# set or get variable
runtime.set_variable("foo", "'bar'") # True
runtime.get_variable("foo") # 'bar'
eval(js_string)
Eval JavaScript code string.
Parameters:
js_string: str
: JavaScript code stringReturns: (is_successful: bool, result: any)
is_successfully
: indicates whether JavaScript is running successfully.result
:
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
variable_name
in the global scope.