Skip to main content

A sidecar

Project description

Kernel Sidecar

Pypi Tests Python versions

Kernel-Sidecar

This package offers the building blocks for creating a "Kernel Sidecar" Jupyter framework. In normal Jupyter Notebook architecture, one or many frontends manage the document model (code cells, outputs, metadata, etc) and send requests to a single Kernel. Each frontend observes responses on different ZMQ channels (iopub, shell, etc) but may end up with some inconsistency based on the Kernel only sending certain responses to the client that made the request.

In a kernel-sidecar architecture, all frontend clients talk to the kernel-sidecar client, and only the kernel-sidecar client communicates with the Kernel over ZMQ. That pattern offers several potential features:

  • Keep a document model within kernel-sidecar or the backend architecture
  • Add "extension"-esque capabilities on the backend such as auto-linting code on execute
  • Eliminate inconsistencies in what messages individual frontends receive because of Kernel replies
  • Model all requests, replies, and the Notebook document with Pydantic

Installation

pip install kernel-sidecar

Key Concepts

SidecarKernelClient

A manager that uses jupyter_client under the hood to create ZMQ connections and watch for messages coming in over different ZMQ channels (iopub, shell, etc. An important assumption here is that kernel-sidecar is the only client talking to the Kernel, which means every message observed coming from the Kernel should be a reply (based on parent_header_msg.msg_id) to a request sent from this client.

When the SidecarKernelClient send a request to the Kernel, it is wrapped in an KernelAction class. Every message received from the Kernel is delegated to the requesting Action and triggers callbacks attached to the Action class.

Actions

Actions in kernel-sidecar encompass a request-reply cycle, including an await action syntax, where the Action is complete when the Kernel has reported its status returning to idle and optionally emitted a reply appropriate for the request. For instance, an execute_request is "done" when the status has been reported as idle and the Kernel has emitted an execute_reply, both with the parent_header_msg.msg_id the same as the execute_request header.msg_id.

In a nutshell, an actions.KernelAction takes in a requests.Request and zero-to-many handlers.Handler subclasses (or just async functions) and creates an awaitable instance. kernel.send(action) submits the Request over ZMQ, and registers the Action so that all observed messages get routed to that Action to be handled by the Handlers/callbacks.

Most of the time, you should be able to just use convience functions in the SidecarKernelClient class to create the actions. See tests/test_actions.py for many examples of using Actions and Handlers.

Models

kernel-sidecar has Pydantic models for:

  • The Jupyter Notebook document (models/notebook.py), which should be consistent with nbformat parsing / structure
  • Request messages sent to the Kernel over ZMQ (models/requests.py)
  • Messages received over ZMQ from the Kernel (models/messages.py)

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

kernel_sidecar-0.2.1.tar.gz (16.1 kB view details)

Uploaded Source

Built Distribution

kernel_sidecar-0.2.1-py3-none-any.whl (17.6 kB view details)

Uploaded Python 3

File details

Details for the file kernel_sidecar-0.2.1.tar.gz.

File metadata

  • Download URL: kernel_sidecar-0.2.1.tar.gz
  • Upload date:
  • Size: 16.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.10.6 Linux/5.15.0-1033-azure

File hashes

Hashes for kernel_sidecar-0.2.1.tar.gz
Algorithm Hash digest
SHA256 6c6b4617834a055ee65b24e38b91d7c35b37c99af7f9b87be607adbf0d0c4855
MD5 4cd045c1d5531877831c3c2e7918819c
BLAKE2b-256 bff66a64bb00df594e6caef66d9c7a651448f0d2b91bb3f6dd320ccbc6098e4b

See more details on using hashes here.

File details

Details for the file kernel_sidecar-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: kernel_sidecar-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 17.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.10.6 Linux/5.15.0-1033-azure

File hashes

Hashes for kernel_sidecar-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8a976794cc3ae97a6fe1893f10f3522ddc6c1a7b6fc98e2b5b6fa3b89bdf4f3f
MD5 38ed3b9e1281631e628330a20dce52f2
BLAKE2b-256 cf8b9ab9dd19c2b30b46700d915fb28e3226698630bf78eb830ae4754e4d823a

See more details on using hashes here.

Supported by

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