Jupyter Kernel Client allows you to connect via WebSocket and HTTP to Jupyter Kernels. It also provide a easy to use interactive Konsole (console for Kernels).
To install the library, run the following command.
pip install jupyter_kernel_client
Check you have a Jupyter Server with ipykernel running somewhere. You can install those packages using:
pip install jupyter-server ipykernel
- Start a Jupyter Server.
jupyter server --port 8888 --IdentityProvider.token MY_TOKEN
- Launch
python
in a terminal and execute the following snippet (update the server_url and token).
import os
from platform import node
from jupyter_kernel_client import KernelClient
with KernelClient(server_url="http://localhost:8888", token="MY_TOKEN") as kernel:
reply = kernel.execute(
"""import os
from platform import node
print(f"Hey {os.environ.get('USER', 'John Smith')} from {node()}.")
"""
)
assert reply["execution_count"] == 1
assert reply["outputs"] == [
{
"output_type": "stream",
"name": "stdout",
"text": f"Hey {os.environ.get('USER', 'John Smith')} from {node()}.\n",
}
]
assert reply["status"] == "ok"
This package can be used to open a Jupyter Console to a Jupyter Kernel 🐣.
- Install the optional dependencies.
pip install jupyter-kernel-client[konsole]
- Start a Jupyter Server.
jupyter server --port 8888 --IdentityProvider.token MY_TOKEN
- Start the konsole and execute code.
jupyter konsole --url http://localhost:8888 --token MY_TOKEN
[KonsoleApp] KernelHttpManager created a new kernel: ...
Jupyter Kernel console 0.2.0
Python 3.12.7 | packaged by conda-forge | (main, Oct 4 2024, 16:05:46) [GCC 13.3.0]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.30.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: print("hello")
hello
In [2]:
To remove the library, execute:
pip uninstall jupyter_kernel_client
# Clone the repo to your local environment
# Change directory to the jupyter_kernel_client directory
# Install package in development mode - will automatically enable
# The server extension.
pip install -e ".[konsole,test,lint,typing]"
Install dependencies:
pip install -e ".[test]"
To run the python tests, use:
pytest
pip uninstall jupyter_kernel_client
See RELEASE