nbinspect-lab: JupyterLab State Inspector for Bridget
nbinspect-lab is the companion JupyterLab and Jupyter Notebook extension for the Bridget project. It runs in the browser, monitoring the notebook’s structure, cell content, and outputs in real-time. This live state information is then sent to the Bridget Python kernel, enabling its powerful introspection and dynamic capabilities.
Features
The extension actively monitors the notebook and provides a front-end API for its findings. Key features include tracking changes to the notebook’s cell structure and content, monitoring cell execution status, and providing visual feedback through a custom MIME renderer. All state changes are broadcast via a global window.$Nb API that front-end components can subscribe to.
Requirements
- JupyterLab >= 4.0.0 or Notebook >= 7.0
- The
bridgetPython package (for standard usage).
Installation
This extension is designed to be installed as part of the main bridget repository. Please follow the installation instructions in the main project’s README file.
Alternatively, you can install this extension standalone from its directory:
# From packages/nbinspect-lab:
pip install -e .Note on Standalone Usage: While nbinspect-lab is part of Bridget, it has no direct dependency on the Python package and can be used in isolation. If you choose this path, you are responsible for creating your own front-end widget to subscribe to the state change events provided by the extension’s window.$Nb API.
Uninstalling
To remove the extension:
pip uninstall nbinspect_labYou can verify removal with:
pip list | grep nbinspect
jupyter labextension listDevelopment
nbinspect-lab is a package within the bridget pnpm monorepo. To contribute, you will need NodeJS and the pnpm package manager.
Development Setup
Install Dependencies: From the repository root:
pnpm installInstall Extension in Editable Mode: From this directory:
pip install -e .Enable Live Reloading (Optional): For automatic rebuilds during development:
jupyter labextension develop . --overwrite
Development Workflow
# In one terminal (from packages/nbinspect-lab):
pnpm watch
# In another terminal:
jupyter labAfter making changes, refresh your browser to see updates.
Packaging the Extension
Instructions for creating a release are in RELEASE.md.
Architecture: Session Management
The extension uses a session-aware architecture to handle JupyterLab’s shared window context:
Key Components
- SessionManager: Global state manager mapping file paths to session state
- NotebookMonitor: Document-focused monitor that queries SessionManager
- Session Lifecycle: State persists across panel close/reopen, cleans up on kernel restart
Session Flow
- Notebook opens → Monitor created → Queries SessionManager for existing state
- Notebook closes → Monitor disposed → State remains in SessionManager
- Notebook reopens → New monitor → Retrieves existing state from SessionManager
- Kernel restarts → SessionManager cleans up session state