Registry / communication / comm
library0.2.3pypypi✓ verified 26d ago

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
INSTALL
IMPORT
SIG · COMM
C
comm
communicationpythonv0.2.3
Install
1.5s avg
Import
36ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.2.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.040s · 17.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.5s · import 0.032s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

BaseComm
from comm import BaseComm
from comm import Comm
create_comm
from comm import create_comm
CommManager
from comm import CommManager

This quickstart demonstrates the basic structure of using `comm.Comm` within a Python kernel in a Jupyter environment. It shows how to create a custom Comm class, register a message handler, and send/receive messages. Note that `comm` is a low-level library; actual communication requires a compatible frontend and a running Jupyter kernel. Running this code directly as a standalone Python script will not establish communication as there's no Jupyter `CommManager` present by default.

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}")
Debug
Known issues
breakingThe `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.
affects: >=0.2.3
gotchaThe `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`.
affects: All versions
gotchaDirect 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.
affects: All versions
breakingThe `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.
affects: All versions
breakingThe `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`.
affects: All versions
Upgrade
Version history
0.2.3latest on PyPI · released Jul 25, 2025
Audit
Dependencies
traitletsoptionalRemoved in v0.2.3. Older versions of 'comm' might have indirectly depended on 'traitlets' for some functionalities or base classes, though it's no longer a direct dependency.
ipykerneloptionalCommonly used in conjunction with 'comm' as it provides the Jupyter kernel environment where 'comm' objects operate.
Agent activity
47 hits · last 30 days
node
42
Amazon
1
OpenAI (training)
1
Resources
comm — pip install comm · libregistry