Skip to main content

jupyterlab_notebook_awareness

Github Actions Status

A JupyterLab extension that tracks a user's current notebook and cell.

Usage

A JupyterLab frontend extension that tracks user awareness by adding activeCellId and notebookPath to each client's collaborative awareness state. This enables applications to know which notebook and cell each user is currently viewing.

Awareness State Schema

The extension adds the following fields to each client's awareness state:

  • activeCellId (string | null): The unique ID of the currently active cell the user is viewing
  • notebookPath (string | null): The file path of the notebook the user has open

Example Awareness Structure

Here is an example of the complete awareness structure in JSON with multiple users:

{
  "4233401820": {
    "user": {
      "username": "960fe034b7b847dfbee15eede12caac7",
      "name": "Anonymous Kale",
      "display_name": "Anonymous Kale",
      "initials": "AK",
      "avatar_url": null,
      "color": "var(--jp-collaborator-color5)"
    },
    "activeCellId": "42768507-1132-43fb-86ba-980a4e73e490",
    "notebookPath": "data_analysis.ipynb",
    "cursors": [
      {
        "anchor": {
          "type": {
            "client": 2431406065,
            "clock": 6
          },
          "tname": null,
          "item": null,
          "assoc": 0
        },
        "head": {
          "type": {
            "client": 2431406065,
            "clock": 6
          },
          "tname": null,
          "item": null,
          "assoc": 0
        },
        "primary": true,
        "empty": true
      }
    ]
  },
  "1582940372": {
    "user": {
      "username": "alice_researcher",
      "name": "Alice Smith",
      "display_name": "Alice Smith",
      "initials": "AS",
      "avatar_url": "https://example.com/avatar.jpg",
      "color": "var(--jp-collaborator-color2)"
    },
    "activeCellId": "b8f3e729-4891-4c2a-9876-543210fedcba",
    "notebookPath": "machine_learning.ipynb",
    "cursors": []
  }
}

State Updates

The awareness state is automatically updated when:

  • A user opens a notebook (sets notebookPath)
  • A user clicks on a different cell (updates activeCellId)
  • A user switches between notebooks (updates both fields)
  • A user refreshes the page (restores state when notebook loads)

Accessing Awareness Data

You can access the awareness data programmatically in JupyterLab:

// Get the current notebook's awareness
const notebook = notebookTracker.currentWidget;
const awareness = notebook?.model?.sharedModel?.awareness;

// Get all awareness states
const allStates = awareness?.getStates();

// Get local user's state
const localState = awareness?.getLocalState();

Requirements

  • JupyterLab >= 4.0.0

Install

To install the extension, execute:

pip install jupyterlab_notebook_awareness

Uninstall

To remove the extension, execute:

pip uninstall jupyterlab_notebook_awareness

Contributing

Development install

Note: You will need NodeJS to build the extension package.

The jlpm command is JupyterLab's pinned version of yarn that is installed with JupyterLab. You may use yarn or npm in lieu of jlpm below.

# Clone the repo to your local environment
# Change directory to the jupyterlab_notebook_awareness directory
# Install package in development mode
pip install -e "."
# Link your development version of the extension with JupyterLab
jupyter labextension develop . --overwrite
# Rebuild extension Typescript source after making changes
jlpm build

You can watch the source directory and run JupyterLab at the same time in different terminals to watch for changes in the extension's source and automatically rebuild the extension.

# Watch the source directory in one terminal, automatically rebuilding when needed
jlpm watch
# Run JupyterLab in another terminal
jupyter lab

With the watch command running, every saved change will immediately be built locally and available in your running JupyterLab. Refresh JupyterLab to load the change in your browser (you may need to wait several seconds for the extension to be rebuilt).

By default, the jlpm build command generates the source maps for this extension to make it easier to debug using the browser dev tools. To also generate source maps for the JupyterLab core extensions, you can run the following command:

jupyter lab build --minimize=False

Development uninstall

pip uninstall jupyterlab_notebook_awareness

In development mode, you will also need to remove the symlink created by jupyter labextension develop command. To find its location, you can run jupyter labextension list to figure out where the labextensions folder is located. Then you can remove the symlink named jupyterlab-notebook-awareness within that folder.

Testing the extension

Frontend tests

This extension is using Jest for JavaScript code testing.

To execute them, execute:

jlpm
jlpm test

Integration tests

This extension uses Playwright for the integration tests (aka user level tests). More precisely, the JupyterLab helper Galata is used to handle testing the extension in JupyterLab.

More information are provided within the ui-tests README.

Packaging the extension

See RELEASE

Metadata

Release files for jupyterlab_notebook_awareness 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jupyterlab_notebook_awareness 0.2.0
File Size Uploaded
jupyterlab_notebook_awareness-0.2.0.tar.gz 130.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for jupyterlab_notebook_awareness 0.2.0
File Interpreter ABI Platform
jupyterlab_notebook_awareness-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 148.4 kB

Release files / jupyterlab_notebook_awareness-0.2.0.tar.gz

Download URL jupyterlab_notebook_awareness-0.2.0.tar.gz
Size 130.7 kB
Tags Source
SHA-256 checksum
How to use checksums
98ef9e61088bec54cd826a793091b74ea557e69b8b7f9cdc8d8387e0ba60c1be
BLAKE2b-256 checksum
How to use checksums
a15d8f3d0d9f40441b147f89247136b32c3dc7765996a5bd40d81a379f9d1c84
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.28.1

Release files / jupyterlab_notebook_awareness-0.2.0-py3-none-any.whl

Download URL jupyterlab_notebook_awareness-0.2.0-py3-none-any.whl
Size 17.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c761718b21648bc31ea5b7c38585d0a3ad0f4a5bde9d7feadaaaba301bc276a3
BLAKE2b-256 checksum
How to use checksums
3db9f54616ace9225c7688e2076f9f7c64bddd8e221405e581dd44c798573327
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.28.1

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page