jupyter kernel websocket client
Project description
jupyter_kernel_client
Code execution client based on jupyter server websocket
How to use
1. Start Jupyter Server(or Lab)
Enter the following command to start
jupyter server
By default, you'll get output like below, and you can get your server host is localhost
, port is 8888
, token
is fa42b5d1f787df44f5ca70a88c4fa6f2d42fdb4a1838c59b
...
[C 2022-12-12 17:37:40.953 ServerApp]
http://localhost:8888/?token=fa42b5d1f787df44f5ca70a88c4fa6f2d42fdb4a1838c59b
or http://127.0.0.1:8888/?token=fa42b5d1f787df44f5ca70a88c4fa6f2d42fdb4a1838c59b
2. Start a kernel
Using Jupyter Server REST API to start a kernel
see: POST /api/kernels
TODO: Start kernel by client
3. Connect to kernel and execute code
You can get the kernel_id
in the request to start the kernel
from jupyter_kernel_client.client import KernelWebsocketClient
client = KernelWebsocketClient(
kernel_id=kernel_id, # you can get it in 2. Start a kernel
port='8888', # you can get port in 1. Start Jupyter Server(or Lab)
host='localhost', # you can get host in 1. Start Jupyter Server(or Lab)
token=token, # you can get token in 1. Start Jupyter Server(or Lab)
)
code = """
print('hello world')
"""
import asyncio
result = asyncio.run(client.execute(code))
print(result)
You will get
{'outputs': [{'output_type': 'stream', 'name': 'stdout', 'text': 'hello world\n'}], 'execution_count': 1}
Project details
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
File details
Details for the file jupyter_kernel_client-0.1.4.tar.gz
.
File metadata
- Download URL: jupyter_kernel_client-0.1.4.tar.gz
- Upload date:
- Size: 6.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bbe496cd8aac3487784d2e07dd53f05a239ea60f643d149d23ea126a405b7450 |
|
MD5 | 55d7b311da0725076b820dda604b3a75 |
|
BLAKE2b-256 | 15dea72cd7eccf3b2f1fa4cc5c52a262b45d7d7cdf53ecd1cb551457b0880b71 |
File details
Details for the file jupyter_kernel_client-0.1.4-py3-none-any.whl
.
File metadata
- Download URL: jupyter_kernel_client-0.1.4-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c1d9bd393df02919ba78a707f7fa279de6ff9ca7ea1960a691f1b5d9b95ea02 |
|
MD5 | 2410ca93163796c9076fd73dd1556019 |
|
BLAKE2b-256 | e57a88da2646efb8821292e8a85ef1b79a3ed957149bc4e2a4e25e758b735fdf |