Skip to main content

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.


Installation

pip install pyevaljs4

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'

Metadata

Release files for pyevaljs4 0.2.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyevaljs4 0.2.4
File Size Uploaded Provenance Actions
pyevaljs4-0.2.4.tar.gz 4.8 kB Without provenance Details for pyevaljs4-0.2.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pyevaljs4 0.2.4
File Interpreter ABI Platform Actions
pyevaljs4-0.2.4-py3-none-any.whl Python 3 none any Details for pyevaljs4-0.2.4-py3-none-any.whl

Total release size: 10.5 kB

Release files / pyevaljs4-0.2.4.tar.gz

Download URL pyevaljs4-0.2.4.tar.gz
Size 4.8 kB
Tags Source
SHA-256 checksum
How to use checksums
1182e32b2618938776f6bf3b37b0a266db4863b10f56483bf54ca80a55345b4e
BLAKE2b-256 checksum
How to use checksums
9cab30cf21194793c071eda28d4b99455aae27bf8c53f8d4ec8e6ba312a148f7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.7

Release files / pyevaljs4-0.2.4-py3-none-any.whl

Download URL pyevaljs4-0.2.4-py3-none-any.whl
Size 5.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
aeac95a7e60a7657fde328f8a3ee59d2d69b663252ce42b9494e40796f7b82c6
BLAKE2b-256 checksum
How to use checksums
e4ff3364136f38f05b7be3b93d59d054df5d927a1a4e4c5c269e33ca74e79fa3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.7

Security for pyevaljs4 0.2.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page