Skip to main content

A JupyterLab Extension for showing cell (git) diffs.

Project description

jupyterlab-diff

Github Actions Status

A JupyterLab extension for showing cell diffs with multiple diffing strategies.

Requirements

  • JupyterLab >= 4.0.0

Installation

PyPI Installation

pip install jupyterlab_diff

Development Installation

# Clone the repository
git clone https://github.com/jupyter-ai-contrib/jupyterlab-diff.git
cd jupyterlab-diff

# Install the extension in development mode
pip install -e .
jupyter labextension develop . --overwrite

Usage

Commands

The extension provides commands to show diffs in multiple formats:

  • jupyterlab-diff:split-cell-diff - Show cell diff using split view (side-by-side comparison)
  • jupyterlab-diff:unified-cell-diff - Show cell diff using unified view
  • jupyterlab-diff:unified-file-diff - Show file diff using unified view for regular Python files and other text files

https://github.com/user-attachments/assets/0dacd7f0-5963-4ebe-81da-2958f0117071

Programmatic Usage

Split Cell Diff (Side-by-side View)

app.commands.execute('jupyterlab-diff:split-cell-diff', {
  cellId: 'cell-id',
  originalSource: 'print("Hello")',
  newSource: 'print("Hello, World!")',
  showActionButtons: true,
  openDiff: true
});

Unified Cell Diff

app.commands.execute('jupyterlab-diff:unified-cell-diff', {
  cellId: 'cell-id',
  originalSource: 'print("Hello")',
  newSource: 'print("Hello, World!")',
  showActionButtons: true
});

Unified File Diff

app.commands.execute('jupyterlab-diff:unified-file-diff', {
  filePath: '/path/to/file.py',
  originalSource: 'print("Hello")',
  newSource: 'print("Hello, World!")',
  showActionButtons: true
});

Command Arguments

jupyterlab-diff:split-cell-diff (Split View)

Argument Type Required Description
cellId string No ID of the cell to show diff for. If not provided, uses the active cell
originalSource string Yes Original source code to compare against
newSource string Yes New source code to compare with
showActionButtons boolean No Whether to show action buttons in the diff widget (default: true)
notebookPath string No Path to the notebook containing the cell. If not provided, uses the current notebook
openDiff boolean No Whether to open the diff widget automatically (default: true)

jupyterlab-diff:unified-cell-diff (Unified View)

Argument Type Required Description
cellId string No ID of the cell to show diff for. If not provided, uses the active cell
originalSource string Yes Original source code to compare against
newSource string Yes New source code to compare with
showActionButtons boolean No Whether to show action buttons for chunk acceptance (default: true)
notebookPath string No Path to the notebook containing the cell. If not provided, uses the current notebook

jupyterlab-diff:unified-file-diff (File Diff)

Argument Type Required Description
filePath string No Path to the file to diff. Defaults to current file in editor.
originalSource string Yes Original source code to compare against
newSource string Yes New source code to compare with
showActionButtons boolean No Whether to show action buttons for chunk acceptance (default: true)

Architecture

Diff Strategies

The extension provides two diff viewing strategies:

  • Split diff (split-cell-diff): Uses CodeMirror's two-pane view. Displays original and modified code side-by-side in separate panels with diff highlighting.

  • Unified diff (unified-cell-diff/unified-file-diff): Uses CodeMirror's unifiedMergeView. Displays changes in a single unified view with added/removed lines clearly marked. Can be used for both cell diffs and regular file diffs.

Uninstall

To remove the extension, execute:

pip uninstall jupyterlab_diff

Troubleshoot

To check the frontend extension is installed:

jupyter labextension list

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jupyterlab_diff-0.6.0.tar.gz (226.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jupyterlab_diff-0.6.0-py3-none-any.whl (93.5 kB view details)

Uploaded Python 3

File details

Details for the file jupyterlab_diff-0.6.0.tar.gz.

File metadata

  • Download URL: jupyterlab_diff-0.6.0.tar.gz
  • Upload date:
  • Size: 226.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for jupyterlab_diff-0.6.0.tar.gz
Algorithm Hash digest
SHA256 d1eb0cae1652d19303942499cf3488cffd1a8366f39c559414c3e9ee64cbde07
MD5 a8e73ac22713517477e16394cc7ec6d6
BLAKE2b-256 518c63a4eb5579b1ccd2fcacc7fefb2bfcf00245243c7b75cec9ea756d0f48bb

See more details on using hashes here.

File details

Details for the file jupyterlab_diff-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: jupyterlab_diff-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 93.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for jupyterlab_diff-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4f63390531977c168c72eada6ee89f9d40dfca5a1d5516c559cce26fb25ae94a
MD5 e1779d50626cc5bbc50bb101da1e7522
BLAKE2b-256 96b53eb9e06ca3e34cdb89b0605c8fb56455ee7195b246124672882e3ba15ea7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page