No project description provided
Project description
jupyter_nbmodel_client
Client to interact with Jupyter notebook model.
Install
To install the extension, execute:
pip install jupyter_nbmodel_client
Usage
- Ensure you have an environment with
jupyter-server-ydocinstalled.
To reproduce the above video you will need to install
jupyterlab,jupyter-collaborationandscikit-learnandmatplotlibfor the notebook demo.
-
Start the server
jupyter server(or JupyterLab like in the video) -
Write down the URL (usually
http://localhost:8888) and the server token -
Open a Python terminal
-
Execute the following snippet to add a cell
from jupyter_nbmodel_client import NbModelClient
with NbModelClient(server_url="http://localhost:8888", token="...", path="test.ipynb") as notebook:
notebook.add_code_cell("print('hello world')")
- Another example adding a cell and executing within a kernel process
from jupyter_kernel_client import KernelClient
from jupyter_nbmodel_client import NbModelClient
with KernelClient(server_url="http://localhost:8888", token="...") as kernel:
with NbModelClient(server_url="http://localhost:8888", token="...", path="test.ipynb") as notebook:
cell_index = notebook.add_code_cell("print('hello world')")
results = notebook.execute_cell(cell_index, kernel)
assert results["status"] == "ok"
assert len(results["outputs"]) > 0
[!NOTE] Instead of using the clients as context manager, you can call the
start()andstop()methods.
from jupyter_nbmodel_client import NbModelClient
kernel = KernelClient(server_url="http://localhost:8888", token="...")
kernel.start()
try:
notebook = NbModelClient(server_url="http://localhost:8888", token="...", path="test.ipynb"):
notebook.start()
try:
cell_index = notebook.add_code_cell("print('hello world')")
results = notebook.execute_cell(cell_index, kernel)
finally:
notebook.stop()
finally:
kernel.stop()
Uninstall
To remove the extension, execute:
pip uninstall jupyter_nbmodel_client
Troubleshoot
If you are seeing the frontend extension, but it is not working, check that the server extension is enabled:
jupyter server extension list
Contributing
Development install
# Clone the repo to your local environment
# Change directory to the jupyter_nbmodel_client directory
# Install package in development mode - will automatically enable
# The server extension.
pip install -e ".[test,lint,typing]"
Running Tests
Install dependencies:
pip install -e ".[test]"
To run the python tests, use:
pytest
Development uninstall
pip uninstall jupyter_nbmodel_client
Packaging the extension
See RELEASE
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file jupyter_nbmodel_client-0.1.1.tar.gz.
File metadata
- Download URL: jupyter_nbmodel_client-0.1.1.tar.gz
- Upload date:
- Size: 13.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
de014a41fd7bda02ac05657b0c93c9c96b2d21a0c5289aa3c7ac54ad06acc574
|
|
| MD5 |
d6fe52ea86c03c73294ee8f4d0f8d0aa
|
|
| BLAKE2b-256 |
f1cd395ed89373f0367c7dfc8f45810f14867696cb7cedfb05dce6e88e49057f
|
File details
Details for the file jupyter_nbmodel_client-0.1.1-py3-none-any.whl.
File metadata
- Download URL: jupyter_nbmodel_client-0.1.1-py3-none-any.whl
- Upload date:
- Size: 11.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1f9ca41afab459aef9456bc76507e925949ccf6f05a5f0ce11b78a0c3e370b5a
|
|
| MD5 |
820d5cb245235e46d9a3dd8b83233789
|
|
| BLAKE2b-256 |
25988caddd468013e832abb44575fe64bb18a217a8d247bdd491ffcad3a02d75
|