Skip to main content

No project description provided

Project description

jupyter_nbmodel_client

Github Actions Status PyPI - Version

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.3.0.tar.gz (15.2 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.3.0-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: jupyter_nbmodel_client-0.3.0.tar.gz
  • Upload date:
  • Size: 15.2 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.3.0.tar.gz
Algorithm Hash digest
SHA256 01f966892f02dc7d4fb4a4aafef0f863b178c25c0c3eb21ee429ebf7e4a82162
MD5 eb7ef0dfe990289e08da88685410b0bf
BLAKE2b-256 da7beb9aec9d5a56e59acaf31a2003961d899c0ea8f2be0301816e89a0748094

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for jupyter_nbmodel_client-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b1548dd4288c849dd620a91835818d4a3a1eef4183d3cd1c4b8e20c924590d37
MD5 bf0684da1206bca29c5b298040ec055b
BLAKE2b-256 4531445de07abe72f41f44b4cbd82f799540eaa872d1d81f40532d2f0254475e

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