Skip to main content

A high-performance Python library that relies on nodejs to execute JavaScript

Project description

A high-performance Python library that relies on nodejs to execute JavaScript


Environments

Please note that you need to install Node.js and set up the NODE_PATH or NODE environment variable properly!
If not set, the default will use the Node.js in the system's path.


Quickstart

import pyevaljs4

# example 1
rt = pyevaljs4.compile_("function f(a,b){console.log(a,b);return a+b;}")
res = rt.call('f', 'x', 'y')
print(res)
assert res == "xy"
# Another way of passing parameters
res = rt.call('f', arg_list=['x', 'y'])
print(res)
assert res == "xy"
# Other equivalent calling methods
print(rt.f('x',  'y'))
print(rt.f(arg_list=['x', 'y']))
# close runtime
rt.close()

# example 2
with pyevaljs4.compile_("function f(a,b){console.log(a,b);return a+b;}") as rt:
    res = rt.call('f', 'x', 'y')
    print(res)
    assert res == "xy"

# example 3
# empty context
rt = pyevaljs4.compile_()
# Add the function f to this context
rt.eval("function f(a,b){console.log(a,b);return a+b;}")
res = rt.call('f', 'x', 'y')
print(res)
assert res == 'xy'
# Other calling methods
res = rt.eval("f('x', 'y')")
print(res)
assert res == "xy"
rt.close()

# example 4
# Call JS asynchronous function
rt = pyevaljs4.compile_()
rt.eval("async function f(a,b){console.log(a,b);return a+b;}")
# To call the JS asynchronous function, you need to pass async_js_func=True
res = rt.call('f', 'x', 'y', async_js_func=True)
print(res)
assert res == "xy"
res = rt.f('x', 'y', async_js_func=True)
print(res)
assert res == "xy"
# The shortcut for calling the JS asynchronous function can only be used this way.
# other cases are not supported.
res = rt.eval('await f("x", "y")')
print(res)
assert res == "xy"
rt.close()

Use a custom version of Node.js

  • By setting environment variables to use a custom version of Node, you only need to set the NODE_PATH or NODE environment variables.
import os
# Highest priority
os.environ['NODE_PATH'] = '/path/to/node.exe'

# Second priority
os.environ['NODE'] = '/path/to/node.exe'

Project details


Download files

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

Source Distribution

pyevaljs4-0.1.0.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyevaljs4-0.1.0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file pyevaljs4-0.1.0.tar.gz.

File metadata

  • Download URL: pyevaljs4-0.1.0.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/6.0.0 pkginfo/1.9.6 requests/2.32.3 requests-toolbelt/0.10.1 tqdm/4.65.0 CPython/3.9.13

File hashes

Hashes for pyevaljs4-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a4a9a19d5f31372145b8ef8aa36ae860ce463082bdf7358c1ea1cdaf22545398
MD5 b9dfad5e9b034376c5a5188dc093eb16
BLAKE2b-256 e382fc531a66b18a6d51e5cfe118d4d5cdd60dc67043e30040ec3552b13b0241

See more details on using hashes here.

File details

Details for the file pyevaljs4-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pyevaljs4-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/6.0.0 pkginfo/1.9.6 requests/2.32.3 requests-toolbelt/0.10.1 tqdm/4.65.0 CPython/3.9.13

File hashes

Hashes for pyevaljs4-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ceeb79b7baca2ebdcd57ce9af4b48e8cf9887362898d76223a3e4b7cdec5b961
MD5 5a8776bed7d09a342d818e62e20470d4
BLAKE2b-256 e81ac01824bc0c589f79c2ce690fdd075b2c577c0a8e277f66f821636945dce6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page