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.1.1.tar.gz (13.5 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.1.1-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

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

Hashes for jupyter_nbmodel_client-0.1.1.tar.gz
Algorithm Hash digest
SHA256 de014a41fd7bda02ac05657b0c93c9c96b2d21a0c5289aa3c7ac54ad06acc574
MD5 d6fe52ea86c03c73294ee8f4d0f8d0aa
BLAKE2b-256 f1cd395ed89373f0367c7dfc8f45810f14867696cb7cedfb05dce6e88e49057f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for jupyter_nbmodel_client-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1f9ca41afab459aef9456bc76507e925949ccf6f05a5f0ce11b78a0c3e370b5a
MD5 820d5cb245235e46d9a3dd8b83233789
BLAKE2b-256 25988caddd468013e832abb44575fe64bb18a217a8d247bdd491ffcad3a02d75

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