Jupyter Comm
raw JSON → 0.2.3 verified Tue May 12 auth: no python install: verified quickstart: stale
Comm is a low-level Python library providing the core implementation for Jupyter communications (Comms). It enables custom bidirectional messaging between a Jupyter kernel (like ipykernel or xeus-python) and its connected frontend. It is currently at version 0.2.3 and is actively maintained, with releases typically tied to Jupyter ecosystem updates.
pip install comm Common errors
error ModuleNotFoundError: No module named 'comm' ↓
cause The `comm` library is not installed in the Python environment being used by Jupyter, or the environment is not correctly activated.
fix
Install the
comm library using pip: pip install comm or conda install comm if using Anaconda/Miniconda. Ensure the installation is done in the correct virtual environment if one is being used. error DeprecationWarning: The `ipykernel.comm.Comm` class has been deprecated. Please use the `comm` module instead. ↓
cause Code is attempting to import the `Comm` class from `ipykernel.comm`, which is deprecated. The `Comm` class and related functionalities have been moved to the standalone `comm` library.
fix
Update the import statement to use the
comm library directly. For creating a comm, use from comm import create_comm instead of from ipykernel.comm import Comm. error [IPKernelApp] WARNING | No such comm: <comm_id> ↓
cause This warning indicates that the Jupyter kernel received a message for a Comm object with a specific ID that it doesn't recognize or that no longer exists. This often happens if the frontend (Jupyter Notebook/Lab) tries to interact with a Comm that the kernel has already closed or never initialized, or due to a desynchronization between frontend and backend.
fix
Ensure that Comm objects are properly created and managed on both the frontend and backend. Verify that the
comm_id is correctly passed and that the Comm lifecycle is synchronized. Often, restarting the kernel and rerunning the cells can resolve temporary desynchronization issues. For custom comms, ensure the target_name is registered correctly on the kernel side before the frontend attempts to open a comm to that target. error Jupyter kernel disconnects/hangs (indicated by '*' in cell output) ↓
cause While not a verbatim error message, a Jupyter cell displaying an asterisk (*) indefinitely and the kernel eventually disconnecting or becoming unresponsive is a common symptom of underlying communication issues handled by the `comm` library. This can be due to resource exhaustion, environment misconfiguration, or errors in the code preventing the kernel from responding.
fix
Troubleshoot by restarting the kernel, checking the Jupyter server logs for more specific errors, and verifying that the Python environment and its dependencies (including
ipykernel and comm) are correctly installed and configured. Consider increasing resource allocation if working with intensive tasks. Ensure no infinite loops or unhandled exceptions are crashing the kernel. error [IPKernelApp] WARNING | Unknown message type: 'comm_open' ↓
cause This warning suggests that the Jupyter kernel received a `comm_open` message, but it does not have a registered handler for the `target_name` specified in the message, or the message itself is malformed or unexpected by the kernel's communication protocol implementation.
fix
Ensure that a
Comm target is properly registered in the kernel using comm_manager.register_target('my_target', my_handler_function) before the frontend attempts to open a comm with that target_name. Verify that the message format conforms to the Jupyter messaging protocol for comms. Warnings
breaking The `traitlets` dependency was removed in version 0.2.3. If your code or other dependencies indirectly relied on `traitlets` through the `comm` package, this update might require explicit installation of `traitlets` or adjusting your code. ↓
fix If your application relies on `traitlets` features that were implicitly provided by `comm` in older versions, ensure `traitlets` is explicitly installed (`pip install traitlets`) in your environment.
gotcha The `comm` library is designed for communication between a Jupyter kernel and its frontend. Attempting to use `comm.Comm` outside of an active Jupyter kernel environment (e.g., in a standalone Python script) will likely result in errors (e.g., `NameError` for `get_ipython()`) because the necessary kernel infrastructure is not present. ↓
fix Ensure you are running `comm` within a Jupyter Notebook, JupyterLab, or an IPython kernel. For simpler Python-to-Python communication or general IPC, consider other libraries like `socket`, `multiprocessing`, `commlib-py`, or `pyserial`.
gotcha Direct usage of the `comm` library is a low-level operation. Most users needing kernel-frontend interactivity in Jupyter should consider using higher-level abstractions like `ipywidgets`, which simplify the process of creating interactive UI elements without needing to manage `Comm` objects directly. ↓
fix For common interactive UI patterns in Jupyter, use `ipywidgets`. Reserve direct `comm` usage for advanced custom communication protocols not covered by existing higher-level libraries.
breaking The `AttributeError: module 'comm' has no attribute 'Comm'` indicates that the `Comm` class, which is central to the `comm` library, could not be found within the imported `comm` module. This often happens if an incorrect or unrelated package named `comm` is installed instead of `jupyter-comm`, or if the `jupyter-comm` package installation is corrupted or incomplete. ↓
fix Verify the correct `jupyter-comm` package is installed (e.g., `pip install jupyter-comm`). Check your Python environment for conflicting packages named `comm` (`pip show comm`). If `jupyter-comm` is already installed, try reinstalling it (`pip install --upgrade --force-reinstall jupyter-comm`) to ensure all components are properly in place.
breaking The `comm` PyPI package does not directly expose `Comm` at the top level (i.e., `comm.Comm`). This API structure, where `Comm` is a direct attribute of the top-level module, is typically found in the `jupyter_client` library (`jupyter_client.session.Comm`). When using the standalone `comm` package, the `Comm` class is usually located in a submodule like `comm.base.Comm`. ↓
fix If you intend to use the `Comm` class from the `comm` PyPI package, import it from `comm.base.Comm` (e.g., `from comm.base import Comm`). If you are working within a Jupyter kernel environment and need access to the `Comm` class as provided by the kernel, ensure you are importing it from `jupyter_client.session.Comm`.
Install compatibility verified last tested: 2026-05-12
python os / libc status wheel install import disk
3.10 alpine (musl) wheel - 0.03s 17.8M
3.10 alpine (musl) - - 0.04s 17.8M
3.10 slim (glibc) wheel 1.4s 0.02s 18M
3.10 slim (glibc) - - 0.02s 18M
3.11 alpine (musl) wheel - 0.07s 19.6M
3.11 alpine (musl) - - 0.07s 19.6M
3.11 slim (glibc) wheel 1.6s 0.05s 20M
3.11 slim (glibc) - - 0.05s 20M
3.12 alpine (musl) wheel - 0.04s 11.5M
3.12 alpine (musl) - - 0.04s 11.5M
3.12 slim (glibc) wheel 1.4s 0.04s 12M
3.12 slim (glibc) - - 0.04s 12M
3.13 alpine (musl) wheel - 0.03s 11.3M
3.13 alpine (musl) - - 0.04s 11.2M
3.13 slim (glibc) wheel 1.4s 0.03s 12M
3.13 slim (glibc) - - 0.04s 12M
3.9 alpine (musl) wheel - 0.03s 17.3M
3.9 alpine (musl) - - 0.04s 17.3M
3.9 slim (glibc) wheel 1.7s 0.03s 18M
3.9 slim (glibc) - - 0.03s 18M
Imports
- Comm wrong
from comm import Commcorrectimport comm # ... later in a kernel ... my_comm = comm.Comm(target_name='my_target')
Quickstart stale last tested: 2026-04-24
import comm
import os
# This example assumes it's running within a Jupyter kernel environment.
# In a real Jupyter setup, the frontend would register a 'my_comm_target'.
class MyKernelComm(comm.Comm):
def __init__(self, target_name='my_comm_target', data=None, metadata=None, buffers=None):
super().__init__(target_name, data, metadata, buffers)
print(f"Kernel Comm '{target_name}' opened.")
self.on_msg(self._handle_msg)
def _handle_msg(self, msg):
# msg['content']['data'] contains the message payload from the frontend
print(f"Kernel received message: {msg['content']['data']}")
if msg['content']['data'].get('action') == 'ping':
self.send({'action': 'pong', 'value': msg['content']['data'].get('value')})
print("Kernel sent 'pong'.")
def shutdown(self):
self.close()
print(f"Kernel Comm '{self.target_name}' closed.")
# Instantiate the Comm (in a real scenario, this would interact with the frontend)
# Note: Running this outside a Jupyter kernel will likely not connect to anything
# and 'comm.Comm' might rely on 'get_ipython()' which would not exist.
# To simulate, we'll just demonstrate the object creation and basic method calls.
# In a live kernel, this object would be managed by the kernel's CommManager.
try:
# This part would only successfully run inside a live Jupyter kernel
# where get_ipython() is available and the kernel manager is active.
# For a standalone script, this will raise an error.
if os.environ.get('SIMULATE_JUPYTER_KERNEL', 'false').lower() == 'true':
my_comm_instance = MyKernelComm(target_name='test_target')
my_comm_instance.send({'action': 'init', 'message': 'Hello from kernel!'})
# Simulate receiving a message
# In reality, the _handle_msg is called by the kernel's message loop
# This manual call is for demonstration purposes in a non-kernel environment
my_comm_instance._handle_msg({'content': {'data': {'action': 'ping', 'value': 42}}})
my_comm_instance.shutdown()
else:
print("To run a more interactive quickstart, execute this code within a Jupyter Notebook or IPython kernel.")
print("The 'comm' library provides the low-level API; higher-level libraries like ipywidgets are usually preferred.")
except Exception as e:
print(f"Could not fully demonstrate 'comm.Comm' outside a live Jupyter kernel. Error: {e}")