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

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.6.tar.gz (4.1 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.6-py3-none-any.whl (3.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pyrunjs-0.1.6.tar.gz
Algorithm Hash digest
SHA256 2552375cd01e0c9a12253842c2656dca9da6a351148b24fec4e50d48dbaabdf0
MD5 47b592e4392064a99bbc021845e35907
BLAKE2b-256 2709bea5cdb91fab0573d21ec320b0e9bd8024a0f518069ecee17157f7602d90

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyrunjs-0.1.6-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.7 Linux/6.5.0-1025-azure

File hashes

Hashes for pyrunjs-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 466547b4305226c0ca5c180956c82e9e169a627f3edce997898db11310bb9fc0
MD5 1e9adbaa2616d32ee2bf543a631e699d
BLAKE2b-256 39d711eaae0dbf3e6994633a9f3682ecd1e515256ab9f158d8282d68d2859b04

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