{"id":623,"library":"comm","title":"Jupyter Comm","description":"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.","status":"active","version":"0.2.3","language":"python","source_language":"en","source_url":"https://github.com/ipython/comm","tags":["jupyter","kernel","frontend","communication","ipython","widgets"],"install":[{"cmd":"pip install comm","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Removed 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.","package":"traitlets","optional":true},{"reason":"Commonly used in conjunction with 'comm' as it provides the Jupyter kernel environment where 'comm' objects operate.","package":"ipykernel","optional":true}],"imports":[{"note":"While `from comm import Comm` works, the common pattern, especially when subclassing or working directly with the library's internal structure, is to `import comm` and then refer to `comm.Comm`.","wrong":"from comm import Comm","symbol":"Comm","correct":"import comm\n# ... later in a kernel ...\nmy_comm = comm.Comm(target_name='my_target')"}],"quickstart":{"code":"import comm\nimport os\n\n# This example assumes it's running within a Jupyter kernel environment.\n# In a real Jupyter setup, the frontend would register a 'my_comm_target'.\n\nclass MyKernelComm(comm.Comm):\n    def __init__(self, target_name='my_comm_target', data=None, metadata=None, buffers=None):\n        super().__init__(target_name, data, metadata, buffers)\n        print(f\"Kernel Comm '{target_name}' opened.\")\n        self.on_msg(self._handle_msg)\n\n    def _handle_msg(self, msg):\n        # msg['content']['data'] contains the message payload from the frontend\n        print(f\"Kernel received message: {msg['content']['data']}\")\n        if msg['content']['data'].get('action') == 'ping':\n            self.send({'action': 'pong', 'value': msg['content']['data'].get('value')})\n            print(\"Kernel sent 'pong'.\")\n\n    def shutdown(self):\n        self.close()\n        print(f\"Kernel Comm '{self.target_name}' closed.\")\n\n# Instantiate the Comm (in a real scenario, this would interact with the frontend)\n# Note: Running this outside a Jupyter kernel will likely not connect to anything\n# and 'comm.Comm' might rely on 'get_ipython()' which would not exist.\n\n# To simulate, we'll just demonstrate the object creation and basic method calls.\n# In a live kernel, this object would be managed by the kernel's CommManager.\n\ntry:\n    # This part would only successfully run inside a live Jupyter kernel\n    # where get_ipython() is available and the kernel manager is active.\n    # For a standalone script, this will raise an error.\n    if os.environ.get('SIMULATE_JUPYTER_KERNEL', 'false').lower() == 'true':\n        my_comm_instance = MyKernelComm(target_name='test_target')\n        my_comm_instance.send({'action': 'init', 'message': 'Hello from kernel!'})\n        # Simulate receiving a message\n        # In reality, the _handle_msg is called by the kernel's message loop\n        # This manual call is for demonstration purposes in a non-kernel environment\n        my_comm_instance._handle_msg({'content': {'data': {'action': 'ping', 'value': 42}}})\n        my_comm_instance.shutdown()\n    else:\n        print(\"To run a more interactive quickstart, execute this code within a Jupyter Notebook or IPython kernel.\")\n        print(\"The 'comm' library provides the low-level API; higher-level libraries like ipywidgets are usually preferred.\")\nexcept Exception as e:\n    print(f\"Could not fully demonstrate 'comm.Comm' outside a live Jupyter kernel. Error: {e}\")","lang":"python","description":"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."},"warnings":[{"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.","message":"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.","severity":"breaking","affected_versions":">=0.2.3"},{"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`.","message":"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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"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.","severity":"breaking","affected_versions":"All versions"},{"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`.","message":"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`.","severity":"breaking","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-05-12T16:51:42.499Z","next_check":"2026-06-26T00:00:00.000Z","problems":[{"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.","cause":"The `comm` library is not installed in the Python environment being used by Jupyter, or the environment is not correctly activated.","error":"ModuleNotFoundError: No module named 'comm'"},{"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`.","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.","error":"DeprecationWarning: The `ipykernel.comm.Comm` class has been deprecated. Please use the `comm` module instead."},{"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.","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.","error":"[IPKernelApp] WARNING | No such comm: <comm_id>"},{"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.","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.","error":"Jupyter kernel disconnects/hangs (indicated by '*' in cell output)"},{"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.","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.","error":"[IPKernelApp] WARNING | Unknown message type: 'comm_open'"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"install_tag":"verified","quickstart_score":0,"quickstart_tag":"stale","pypi_latest":"0.2.3","install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0.03,"mem_mb":1.7,"disk_size":"17.8M"},{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.04,"mem_mb":1.7,"disk_size":"17.8M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":1.4,"import_time_s":0.02,"mem_mb":1.7,"disk_size":"18M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.02,"mem_mb":1.7,"disk_size":"18M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0.07,"mem_mb":1.7,"disk_size":"19.6M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.07,"mem_mb":1.7,"disk_size":"19.6M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":1.6,"import_time_s":0.05,"mem_mb":1.7,"disk_size":"20M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.05,"mem_mb":1.7,"disk_size":"20M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0.04,"mem_mb":1.5,"disk_size":"11.5M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.04,"mem_mb":1.5,"disk_size":"11.5M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":1.4,"import_time_s":0.04,"mem_mb":1.5,"disk_size":"12M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.04,"mem_mb":1.5,"disk_size":"12M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0.03,"mem_mb":1.7,"disk_size":"11.3M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.04,"mem_mb":1.7,"disk_size":"11.2M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":1.4,"import_time_s":0.03,"mem_mb":1.5,"disk_size":"12M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.04,"mem_mb":1.5,"disk_size":"12M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0.03,"mem_mb":1.6,"disk_size":"17.3M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.04,"mem_mb":1.6,"disk_size":"17.3M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":1.7,"import_time_s":0.03,"mem_mb":1.6,"disk_size":"18M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.03,"mem_mb":1.6,"disk_size":"18M"}]},"quickstart_checks":{"last_tested":"2026-04-24","tag":"stale","tag_description":"widespread failures or data too old to trust","results":[{"runtime":"python:3.10-alpine","exit_code":1},{"runtime":"python:3.10-slim","exit_code":1},{"runtime":"python:3.11-alpine","exit_code":1},{"runtime":"python:3.11-slim","exit_code":1},{"runtime":"python:3.12-alpine","exit_code":1},{"runtime":"python:3.12-slim","exit_code":1},{"runtime":"python:3.13-alpine","exit_code":1},{"runtime":"python:3.13-slim","exit_code":1},{"runtime":"python:3.9-alpine","exit_code":1},{"runtime":"python:3.9-slim","exit_code":1}]}}