JSPyBridge_async - javascript asyncio fork
Interoperate Node.js from Python, with built in asyncio compatibility.
This is a fork of JSPyBridge by extremeheat, created to properly integrate asyncio events and coroutines into the python side of the bridge.
As the purpose of this fork was only to alter the javascript package, it's specifically for running Node.js from Python. No changes are made to pythonia or are planned to be made to pythonia.
current stable installation
pip install -U javascriptasync
current latest installation
pip install -U git+https://github.com/CrosswaveOmega/JSPyBridge_Async.git
Requires Node.js 14 and Python 3.8 or newer.
Key Features
-
use node.js objects in the same way as python modules.
-
Ability to call async and sync functions and get object properties with a native feel
-
Built-in garbage collection
-
Bidirectional callbacks with arbitrary arguments
-
Iteration and exception handling support
-
Object inspection allows you to easily
console.logorprint()any foreign objects -
(Bridge to call JS from Python) Specialized object oriented support for event-emitter functions.
-
retrieve blob objects from the Javascript side of the bridge.
-
enhanced support for concurrent operations.
New Javascript from Python usage:
import asyncio
from javascriptasync import init_js, require_a, get_globalThis
init_js()
async def main():
chalk, fs = await require_a("chalk")
globalThis=get_globalThis()
datestr=await (await globalThis.Date(coroutine=True)).toLocaleString(coroutine=True)
print("Hello", chalk.red("world!"), "it's", datestr)
fs.writeFileSync("HelloWorld.txt", "hi!")
asyncio.run(main)
TO DO:
- better documentation and examples
- bug fixing/optimization
- Code cleanup.
KEY CHANGES:
javascriptis nowjavascriptasyncconfig.pyhas been encapsulated into theJSConfigclass, all objects that need to access variables withinJSConfighave been passed an object reference to a single uniqueJSConfiginstance.__init__.pyutilizes a singleton to ensure that only one instance of an JSConfig class is created at any one time. You need to callinit()to start up the bridge!- The
JSContextobject can be utilized to make use of the library's operations in a more object oriented manner. - debug output now uses the logging module.
connection.pyhas been encapsulated into theConnectionClass, accessable through theevents.EventLoopclass, asevents.EventLoopis the only place the connection was ever utilized.- It's possible to set a custom timeout value when using eval_js.
- async variants of
requireandeval_jsare included within init.py, asrequire_aandeval_js_arespectively. - this package is now built using a
pyproject.tomlfile instead of asetup.pyscript. test_general.pynow works with pytest.console,globalThis, andRegExphave to be retrieved with theget_console(),get_globalThis(), andget_RegExp()functions.start,stop, andaborthas to be retrieved with through theThreadUtilsstatic class.- any call or init operation can be made into a coroutine by passing in the
coroutine=Truekeyword. - Separate set of wrappers for asyncio tasks through
AsyncTaskUtils - Event Emitters can utilize Coroutine handlers.
Examples
see https://github.com/CrosswaveOmega/JSPyBridge_Async/tree/master/examples
Release files for javascriptasync 0.2.2.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| javascriptasync-0.2.2.8.tar.gz | 71.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| javascriptasync-0.2.2.8-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 150.7 kB
Release files / javascriptasync-0.2.2.8.tar.gz
| Download URL | javascriptasync-0.2.2.8.tar.gz |
|---|---|
| Size | 71.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5e7d604e28ba868cdab51b1fe2c7f372947154b940ebd8ebd6481c4d0c27afcc
|
|
BLAKE2b-256 checksum How to use checksums |
5fab9df14ba9bf95a43b05aaaa5786ef40560bca2c7b04190fcc289a6a953257
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|
Release files / javascriptasync-0.2.2.8-py3-none-any.whl
| Download URL | javascriptasync-0.2.2.8-py3-none-any.whl |
|---|---|
| Size | 79.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f660188e2ad3fc2c9f19cabdbcedaf317d2f1573c928fb64045dd86a7d48b72e
|
|
BLAKE2b-256 checksum How to use checksums |
91adc4e408c6bf7932d27fb99a7098581a8e9a389bd632f921b3ea8bbc8e7108
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|