Skip to main content

jupyasyncclient

jupyasyncclient is an async Python client for running code on Jupyter kernels. It connects to servers that implement the standard kernels API, including rustygate, jupygate, and jupyter_server.

Kernel creation, interruption, restart, and deletion use HTTP. Each client exchanges messages over one websocket. Sends await the websocket transport. The client does not depend on zmq or tornado.

Three classes provide jupyter_client-style interfaces:

  • JupyAsyncKernelClient manages one kernel’s lifecycle, channels, and messages.
  • JupyAsyncKernelManager starts and stops one kernel and creates clients for it.
  • JupyAsyncMultiKernelManager manages multiple kernels. ensure_kernel('some-key') returns the live kernel registered under that key or starts one.

The core notebook builds the client bottom-up and demonstrates every method against a live server. The managers are HTTP wrappers in plain modules. Two other notebooks cover gateway APIs:

Install

pip install jupyasyncclient

You also need a kernel server. These examples use rustygate serving ipymini kernels. The test suite also runs against a stock jupyter_server.

Use

The client’s execute, complete, inspect, history, kernel_info, and wait_for_ready methods follow their jupyter_client namesakes. Choose how to receive execution results:

  • execute sends without waiting for a reply.
  • reply awaits one execute_reply.
  • run collects every message caused by an execution.

Broadcast traffic goes to the on_jmsg callback. JmsgQueues provides queues for applications that need to pull messages instead.

Every protocol *_request type is callable by name and returns an awaitable for its reply. This includes subshell requests. New protocol messages do not require a client release.

Messages are standard Jupyter dictionaries with a channel key. The server handles zmq-specific behaviour, including sync-send edge consumption, slow-joiner subscriptions, and socket identity.

import asyncio
from rustygate.tools import start_gateway
g = start_gateway()
g
True

start_new_server_kernel starts a kernel and returns its manager and a ready client. This example uses a single jmsg queue for iopub and stdin messages:

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'

Kernel output arrives on the iopub channel. Read the stream message from the queue:

m = await qs.jmsg_for('stream', timeout=15)
m['content']['text']
'hello\n'

Calling input() in the kernel produces an input_request on the stdin channel. Answer with the client’s input method. It sets the reply’s parent to the request:

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'

Call protocol requests by name and await their replies. This example creates and deletes a JEP 91 subshell:

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'

Use the multimanager to keep a kernel for each named task. Repeated calls to ensure_kernel with the same key reuse its live kernel:

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()

Pass token=... to any of the three classes when the server requires a bearer token. HTTP requests send it in the Authorization header. Websocket connections send it as a query parameter.

Release files for jupyasyncclient 0.2.15

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jupyasyncclient 0.2.15
File Size Uploaded
jupyasyncclient-0.2.15.tar.gz 22.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for jupyasyncclient 0.2.15
File Interpreter ABI Platform
jupyasyncclient-0.2.15-py3-none-any.whl Python 3 none any Details

Total release size: 44.8 kB

Release files / jupyasyncclient-0.2.15.tar.gz

Download URL jupyasyncclient-0.2.15.tar.gz
Size 22.2 kB
Tags Source
SHA-256 checksum
How to use checksums
9f84946db53e7221cc8e8d501541bf40a57015a877a1cc94a949ec009b5c92c1
BLAKE2b-256 checksum
How to use checksums
e5bd99c2d78e74161f86231f2e7c68bc19c85f74cd4119559c14f9fb452bc532
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.15-py3-none-any.whl

Download URL jupyasyncclient-0.2.15-py3-none-any.whl
Size 22.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
52a0d953fb1ecf2fb96b950996af12e23a66a1c44142e6725d9fa024b399fc5c
BLAKE2b-256 checksum
How to use checksums
5056c871e607f60e4cd421b4377d98422ecb3e9e52fe24b77d5875fae37d9206
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Release history Release notifications | RSS feed

0.2.19

2 release files

0.2.18

2 release files

0.2.17

2 release files

0.2.16

2 release files

This release

0.2.15 This release

2 release files

0.2.11

2 release files

0.2.10

2 release files

0.2.9

2 release files

0.2.8

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page