Skip to main content

No project description provided

Project description

jupyter_nbmodel_client

Github Actions Status

Client to interact with Jupyter notebook model.

Install

To install the extension, execute:

pip install jupyter_nbmodel_client

Usage

  1. Ensure you have an environment with jupyter-server-ydoc installed.

To reproduce the above video you will need to install jupyterlab, jupyter-collaboration and scikit-learn and matplotlib for the notebook demo.

  1. Start the server jupyter server (or JupyterLab like in the video)

  2. Write down the URL (usually http://localhost:8888) and the server token

  3. Open a Python terminal

  4. 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')")
  1. 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() and stop() 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jupyter_nbmodel_client-0.2.0.tar.gz (15.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jupyter_nbmodel_client-0.2.0-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

Details for the file jupyter_nbmodel_client-0.2.0.tar.gz.

File metadata

  • Download URL: jupyter_nbmodel_client-0.2.0.tar.gz
  • Upload date:
  • Size: 15.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.7

File hashes

Hashes for jupyter_nbmodel_client-0.2.0.tar.gz
Algorithm Hash digest
SHA256 1cc666634b92b7375fd5e3f62a96fc9eb0d8ab05fcbb2b6c1be4081878af2c7a
MD5 904135d5e375151290a8a4b5c8ef5094
BLAKE2b-256 708455ce89f5d6aa1faf1776e0228e640bfc01a60883d3752b1bcfcf90e883e3

See more details on using hashes here.

File details

Details for the file jupyter_nbmodel_client-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for jupyter_nbmodel_client-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ba9712026c41bd4f5e93efcc4393f471195a594e9182cf451483ea1a11f16df1
MD5 e14315f6babd656c88ee19d4c75bfab3
BLAKE2b-256 6ab0368a3538afa8a2694890d460708a7ba2860e11b91e28a1ef39830b177d41

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page