Skip to main content

A bridge between Python and JavaScript

Project description

pyjs_bridge

A bridge between Python and JavaScript

pip install python_js_bridge

sample

import ast

from pyjs_bridge import pyast2jsast, tojseval

pycode = """
from time import time, sleep

def fib(n: int):
    if n <= 1:
        return n
    return fib(n - 1) + fib(n - 2)

async def foo():
    i = 0
    st = time()
    while i < 25:
        print(time(), i, fib(i))
        await sleep(0.1)
        i += 1

foo()
"""

jsast = pyast2jsast(ast.parse(pycode))
with open("out.js", "w", encoding="utf-8") as f:
    f.write(tojseval(jsast))
>>> node out.js
1742608916.119 0 0
1742608916.239 1 1
1742608916.347 2 1
1742608916.457 3 2
1742608916.565 4 3
1742608916.674 5 5
1742608916.782 6 8
1742608916.892 7 13
1742608917.001 8 21
1742608917.11 9 34
1742608917.22 10 55
1742608917.33 11 89
1742608917.438 12 144
1742608917.547 13 233
1742608917.655 14 377
1742608917.764 15 610
1742608917.875 16 987
1742608917.985 17 1597
1742608918.093 18 2584
1742608918.203 19 4181
1742608918.311 20 6765
1742608918.421 21 10946
1742608918.53 22 17711
1742608918.64 23 28657
1742608918.75 24 46368

Project details


Release history Release notifications | RSS feed

This version

0

Download files

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

Source Distribution

python_js_bridge-0.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

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

python_js_bridge-0-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

Details for the file python_js_bridge-0.tar.gz.

File metadata

  • Download URL: python_js_bridge-0.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for python_js_bridge-0.tar.gz
Algorithm Hash digest
SHA256 83fe8d216582d4c018127ba3e7a8d09a0d0533e8a9053ae3d8998c1fa9194a0b
MD5 cf662a10fff16b41c76412a853b8d8ae
BLAKE2b-256 030cef53728e71ed31027864c068e75dd65b5a5599f97130a0c6a478bf22227a

See more details on using hashes here.

File details

Details for the file python_js_bridge-0-py3-none-any.whl.

File metadata

  • Download URL: python_js_bridge-0-py3-none-any.whl
  • Upload date:
  • Size: 10.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for python_js_bridge-0-py3-none-any.whl
Algorithm Hash digest
SHA256 988fe8fdc54d5ad0124a607e4b7f5aa8a597484e9b068cf8254d0e0648f939f3
MD5 4e3870c6cc0640b9267327305a3ed7cc
BLAKE2b-256 54c57961b57e99d3226bbf9d432644b3c0afeeca7b32038faa09445765327fb3

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