fork of JSPyBridge overhauled to allow for asyncio compatibility and more control.
Project description
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.log
orprint()
any foreign objects -
(Bridge to call JS from Python) Specialized object oriented support for event-emitter functions.
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.
- callback an asyncio coroutine from JavaScript
- Code cleanup.
KEY CHANGES:
javascript
is nowjavascriptasync
config.py
has been encapsulated into theJSConfig
class, all objects that need to access variables withinJSConfig
have been passed an object reference to a single uniqueJSConfig
instance.__init__.py
utilizes 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!- debug output now uses the logging module.
connection.py
has been encapsulated into theConnectionClass
, accessable through theevents.EventLoop
class, asevents.EventLoop
is the only place the connection was ever utilized.- It's possible to set a custom timeout value when using eval_js.
- async variants of
require
andeval_js
are included within init.py, asrequire_a
andeval_js_a
respectively. - this package is now built using a
pyproject.toml
file instead of asetup.py
script. test_general.py
now works with pytest.console
,globalThis
, andRegExp
have to be retrieved with theget_console()
,get_globalThis()
, andget_RegExp()
functions.start
,stop
, andabort
has to be retrieved with through theThreadUtils
static class.- any call or init operation can be made into a coroutine by passing in the
coroutine=True
keyword. - 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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for javascriptasync-0.2.2.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ba8325f72287fe80a44d98299471e96cd3be03c7ded4c53d282f122f537a4e48 |
|
MD5 | ab61b54c6c7884199ca4044dcb453253 |
|
BLAKE2b-256 | c71fc37ff3e8b10a16235b33e1f70ff02d79412d31b8853de83be4629eb77678 |