{"id":4228,"library":"pyviz-comms","title":"PyViz Comms","description":"pyviz-comms is a Python library that provides a simple bidirectional communication architecture between Python and JavaScript, primarily for use within Jupyter environments (Classic Notebook and JupyterLab). It acts as a low-level building block for the HoloViz ecosystem, enabling interactive content rendering. The library is currently at version 3.0.6 and aligns its major releases with JupyterLab versions to ensure compatibility.","status":"active","version":"3.0.6","language":"en","source_language":"en","source_url":"https://github.com/holoviz/pyviz_comms.git","tags":["jupyter","holoviz","communication","frontend","backend","jupyterlab","ipywidgets"],"install":[{"cmd":"pip install pyviz-comms","lang":"bash","label":"Latest version"}],"dependencies":[{"reason":"Required for the JupyterLab extension component and to run in a Jupyter environment. For JupyterLab 3.0+, the extension is automatically bundled.","package":"jupyterlab","optional":false},{"reason":"Provides the underlying Jupyter Comm infrastructure used by pyviz-comms.","package":"ipykernel","optional":false},{"reason":"A common dependency in the HoloViz ecosystem; while not strictly required for basic comms, it's often used by tools that leverage pyviz-comms.","package":"param","optional":true}],"imports":[{"note":"This is the main class for establishing bidirectional communication.","symbol":"Comm","correct":"from pyviz_comms import Comm"},{"note":"pyviz_comms internally uses `ipykernel.comm.Comm` and exposes it as `pyviz_comms.Comm`. Direct import of `IPyComm` from `pyviz_comms` is not the intended public API, though `Comm` itself wraps it.","wrong":"from pyviz_comms import IPyComm","symbol":"IPyComm","correct":"from ipykernel.comm import Comm as IPyComm"}],"quickstart":{"code":"from pyviz_comms import Comm\nfrom IPython.display import display, Javascript\n\ndef python_message_handler(msg):\n    print(f\"Python received: {msg['content']['data']}\")\n\n# Create a new comm target\ncomm_id = 'my_pyviz_comm_example'\ncomm = Comm(target_name=comm_id, data={})\ncomm.on_msg(python_message_handler)\n\n# Send a message from Python to the frontend\ncomm.send(data={'status': 'hello from python!'})\n\n# To make this truly bidirectional, a JavaScript counterpart is needed in the Jupyter frontend.\n# Run the following JavaScript in a separate Jupyter cell:\n#\n# %%javascript\n# if (window.PyViz == undefined) { window.PyViz = {}; }\n# if (window.PyViz.comms == undefined) { window.PyViz.comms = {}; }\n#\n# Jupyter.notebook.kernel.comm_manager.register_target('my_pyviz_comm_example', function(comm) {\n#     window.PyViz.comms[comm.comm_id] = comm;\n#     comm.on_msg(function(msg) {\n#         console.log(\"JS received:\", msg.content.data);\n#         comm.send({'response': 'hello from JS!'});\n#     });\n#     comm.send({'ready': true});\n#     console.log(\"JS comm 'my_pyviz_comm_example' registered and ready.\");\n# });\n\n# After running the JS, you could send another message from Python:\n# comm.send(data={'action': 'update_chart'})","lang":"python","description":"This quickstart demonstrates how to establish a basic bidirectional communication channel using `pyviz_comms.Comm` within a Jupyter environment. It sets up a Python-side message handler and sends an initial message. For full interactivity, a corresponding JavaScript snippet must be executed in a Jupyter frontend cell to register the client-side comm and handle messages from Python, as well as send messages back. This example illustrates the low-level nature of `pyviz-comms`; higher-level libraries like Panel abstract much of this complexity."},"warnings":[{"fix":"Upgrade JupyterLab to version 3.0 or higher. If unable to upgrade, use an older `pyviz-comms` version compatible with your JupyterLab or manually install the `jupyterlab_pyviz` extension.","message":"For JupyterLab versions older than 3.0, the `@pyviz/jupyterlab_pyviz` extension needed to be installed manually using `jupyter labextension install @pyviz/jupyterlab_pyviz`. `pyviz-comms` version 3.x is specifically designed for JupyterLab 3.x and 4.x, where the extension is automatically bundled with the Python package.","severity":"breaking","affected_versions":"<3.0 (JupyterLab)"},{"fix":"Refer to the official HoloViz documentation (holoviz.org) for information and usage patterns, and understand that `pyviz-comms` is a component within the HoloViz suite.","message":"The project was formerly known as 'PyViz', which can cause confusion with the broader 'PyViz.org' community project that catalogs all Python visualization tools. `pyviz-comms` is now firmly part of the 'HoloViz' ecosystem.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Consider using higher-level HoloViz libraries like Panel (panel.holoviz.org) or HoloViews (holoviews.org) for most visualization and dashboarding needs, as they abstract away the complexities of direct comms management.","message":"pyviz-comms provides a low-level communication primitive. Most users of the HoloViz ecosystem will interact with this functionality indirectly through higher-level libraries like Panel, HoloViews, or Bokeh, rather than directly using `pyviz_comms.Comm`. Direct usage often requires detailed knowledge of both Python and JavaScript comms.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}