jupyasyncclient
jupyasyncclient runs code on Jupyter kernels hosted by any server speaking the standard kernels API: rustygate, jupygate, or jupyter_server. Kernel lifecycle (create, interrupt, restart, delete) is plain HTTP; messaging is one websocket per client carrying standard Jupyter message dicts with a channel key. There is no zmq and no tornado in the client process, and every send is genuinely awaited - the zmq-side subtleties (sync-send edge consumption, slow-joiner subscriptions, socket identity contracts) all live server-side.
Three classes cover the usual shapes, mirroring jupyter_client where familiarity helps:
JupyAsyncKernelClient- one kernel: lifecycle, channels, and messaging.execute,complete,inspect,history,kernel_info, andwait_for_readywork like their jupyter_client namesakes.executesends fire-and-forget,replyawaits oneexecute_reply, andruncollects every message one execute causes; broadcast traffic goes to anon_jmsgcallback, withJmsgQueuesas the pull adapter. Every*_requestmessage type in the protocol is callable by name, returning an awaitable of its reply, subshell requests included, so new protocol messages need no client release.JupyAsyncKernelManager- start/stop one kernel and mint clients for it.JupyAsyncMultiKernelManager- a fleet, with keyed reuse:ensure_kernel('some-key')returns the live kernel registered under that key or starts a fresh one.
The core notebook builds the client bottom-up with every method demonstrated against a live server; the managers are thin HTTP wrappers and live in plain modules.
Two sibling pages cover the rest of a gateway’s surface: term attaches JupyAsyncTerminalClient to gateway-hosted terminals, and files builds JupyAsyncFilesClient and JupyAsyncCellsClient over the files and cells APIs, including apply_ops for keeping a local view current from a kernel’s change broadcasts.
Install
pip install jupyasyncclient
Plus a server to talk to. The examples here use rustygate serving ipymini kernels; a stock jupyter_server works identically (the test suite runs against one).
Use
import asyncio
from rustygate.tools import start_gateway
g = start_gateway()
g
True
start_new_server_kernel gives a running kernel and a ready client in one call:
km, kc = await start_new_server_kernel(g.url)
qs = JmsgQueues(kc, queues=('jmsg',), merge=dict(iopub='jmsg', stdin='jmsg'))
rep = await kc.reply("print('hello'); 6*7", timeout=30)
rep['content']['status']
'ok'
Outputs arrive on the iopub queue, like jupyter_client:
m = await qs.jmsg_for('stream', timeout=15)
m['content']['text']
'hello\n'
input() in the kernel becomes an input_request on the stdin queue; answer it with input, which parents the reply properly:
fut = asyncio.ensure_future(kc.reply("name = input('who? ')", timeout=30))
prompt = await qs.jmsg_for('input_request', timeout=15)
kc.input('Jeremy')
(await fut)['content']['status']
'ok'
Any protocol request type works by name, awaited for its reply - here JEP 91 subshells, no client support required beyond the message type:
sub = (await kc.create_subshell(timeout=15))['content']['subshell_id']
rep = await kc.reply('40+2', timeout=30, subshell_id=sub)
await kc.delete_subshell(sub, timeout=15)
rep['content']['status']
'ok'
The multimanager runs fleets, with keyed reuse for “the kernel for X” patterns:
mkm = JupyAsyncMultiKernelManager(g.url)
k1 = await mkm.ensure_kernel('analysis')
k2 = await mkm.ensure_kernel('analysis')
k1 == k2
True
await kc.aclose()
await km.shutdown_kernel()
await mkm.shutdown_all()
Auth is a bearer token when the server requires one: pass token=... to any of the three classes and it is sent as an Authorization header on HTTP and a query param on the websocket.
Release files for jupyasyncclient 0.2.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| jupyasyncclient-0.2.9.tar.gz | 21.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| jupyasyncclient-0.2.9-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 44.1 kB
Release files / jupyasyncclient-0.2.9.tar.gz
| Download URL | jupyasyncclient-0.2.9.tar.gz |
|---|---|
| Size | 21.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0eab73bad6594c98ca530e16e8e435a0befd2ecaddd07d280f5826d801c92b96
|
|
BLAKE2b-256 checksum How to use checksums |
6c9a7fe1e7d24aa29ef554700e6db585047a9fc895bee4b0ddd9b12601aaeb66
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.15
|
Release files / jupyasyncclient-0.2.9-py3-none-any.whl
| Download URL | jupyasyncclient-0.2.9-py3-none-any.whl |
|---|---|
| Size | 22.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e505ce8a34af15806ed7508a600289e40a1f9e541ef0409df250b24c6925412b
|
|
BLAKE2b-256 checksum How to use checksums |
0b68b6d13938ee6cb45608d788d36c514db9ec28cead0dcace70cf09fad33103
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.15
|