Skip to main content

Easily run javascript expressions using python.

Project description

pyrunjs

使用python简单地调用js,获取js表达式返回值

note: 系统需要安装node.js,node命令可用,尝试用node -v查询node版本:

$ node -v 
v18.20.5

安装

pdm

pdm add pyrunjs

pip

pip install pyrunjs

使用示例

import pyrunjs

js_script = """function HelloWorld() { return 'Hello World!'; } """
result = pyrunjs.run_js(js_script, "HelloWorld()")
print(result)  # output: Hello World!
import pyrunjs

result = pyrunjs.run_js('', "1 + 2")
print(result)  # output: 3
import pyrunjs

js_script = """
    function add(a, b) {
        return new Promise((resolve, reject) => {
            let sum = a + b;
            resolve(sum);
        }).then(sum => {
            return sum * sum;
        });
    }
"""
result = pyrunjs.run_js(js_script, "add(1, 2)")
print(result) # output: 9

版本更新概要信息

  • 0.1.2 run_js函数可用
  • 0.1.3
    • 新增call_js函数,可自动编写调用function的表达式。
    • 解决不同系统默认编码不同导致的乱码问题。(例:windows系统默认编码为GBK时,现在可能正常返回结果了)
  • 0.1.4 添加对异步函数Promise的支持。run_js表达式返回异步函数时,可以获取resolve中的结果了。
  • 0.1.5 添加nox测试多版本的python, python支持的版本可降低到 python3.8
  • 0.1.6 修复一些错误
  • 0.1.7 修复一些错误

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

pyrunjs-0.1.7.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

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

pyrunjs-0.1.7-py3-none-any.whl (3.4 kB view details)

Uploaded Python 3

File details

Details for the file pyrunjs-0.1.7.tar.gz.

File metadata

  • Download URL: pyrunjs-0.1.7.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: pdm/2.22.0 CPython/3.12.8 Linux/6.5.0-1025-azure

File hashes

Hashes for pyrunjs-0.1.7.tar.gz
Algorithm Hash digest
SHA256 b3cc1670ada790ca46d26aec07ef807f24c0c433fb8f68ffd49cd4739608c077
MD5 54ad4c351f1e3757f3017fb4fb108359
BLAKE2b-256 d1e15bfd1983e55c7dad6bd915eb1024314ef84318e3acb95b805b920fe2440d

See more details on using hashes here.

File details

Details for the file pyrunjs-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: pyrunjs-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 3.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: pdm/2.22.0 CPython/3.12.8 Linux/6.5.0-1025-azure

File hashes

Hashes for pyrunjs-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 0c50a9352081e482f85a1024dbf883d5db3d6282ed3f6c9f75acfe48b3052f09
MD5 3ba84f2a65fe2ad7c9c8dafb48829db9
BLAKE2b-256 a573be677abe6bd7f5e91bbbdf1ba8c284193b2d1623e1049cf649b6cdf9bc77

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