Registry / devops / nbstripout

nbstripout

JSON →
library0.9.1pypypi✓ verified 21d ago

nbstripout is a Python utility that strips outputs, metadata, and other extraneous content from Jupyter and IPython notebooks. It's most commonly used as a Git hook to prevent large, noisy diffs and ensure clean notebooks in version control. The current version is 0.9.1, and it maintains an active release cadence with several updates per year.

pip install nbstripout
INSTALL
IMPORT
SIG · NBSTRIPOUT
N
nbstripout
devopspythonv0.9.1
Install
2.7s avg
Import
399ms
Disk
22MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.9.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.418s · 23.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.7s · import 0.380s · 24MB
22MB installed
● package 22MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

strip_output (programmatic API)
from nbstripout import strip_output
While nbstripout is primarily a command-line tool, its core logic can be used programmatically.

The primary use case for nbstripout is as a Git hook, which automatically strips notebook outputs and metadata before committing. The `--install` command sets this up for a repository. A programmatic example demonstrates how to use the `strip_output` function directly in Python.

# 1. Install nbstripout pip install nbstripout # 2. Install the git hook in your repository # This ensures outputs are stripped automatically before committing. # Navigate to your git repository first. # os.system('nbstripout --install') # Uncomment to run, but be aware it modifies your .git/config # 3. Example of programmatic usage (optional) from nbstripout import strip_output import json # Simulate reading a notebook file example_notebook_content = { "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": ["Hello, nbstripout!\n"] } ], "source": "print('Hello, nbstripout!')" } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" } }, "nbformat": 4, "nbformat_minor": 5 } # Strip outputs from the notebook content stripped_notebook_content = strip_output(json.dumps(example_notebook_content)) # Print the stripped content (outputs should be empty) print("\n--- Original Notebook ---") print(json.dumps(example_notebook_content, indent=2)) print("\n--- Stripped Notebook ---") print(json.dumps(json.loads(stripped_notebook_content), indent=2))
nbstripout --version
Debug
Known issues
breakingPython 3.8 and 3.9 support was dropped in version 0.9.0. If you are using an older Python version, you must upgrade to Python 3.10+ or pin nbstripout to a version prior to 0.9.0.
fix
Upgrade your Python environment to 3.10 or higher, or explicitly install `nbstripout<0.9.0`.
affects: >=0.9.0
breakingThe command-line option `--strip-empty-cells` was renamed to `--drop-empty-cells` in version 0.6.0. Scripts using the old flag will fail.
fix
Update any scripts or configurations to use `--drop-empty-cells` instead of `--strip-empty-cells`.
affects: >=0.6.0
gotchaStarting from version 0.7.0, cell IDs are renamed to be sequential by default. If you rely on stable, persistent cell IDs for specific workflows (e.g., custom tooling expecting specific IDs), this change might break them.
fix
To preserve original cell IDs, use the `--keep-id` flag when running `nbstripout`.
affects: >=0.7.0
gotchaSince version 0.8.1, when `nbstripout --install` is used, the Git filter is declared as `required`. This means if the stripping process fails (e.g., due to a malformed notebook), the commit will be blocked. Previously, a failed strip might have been ignored.
fix
Be aware that `nbstripout` failures will now prevent commits. Ensure notebooks are valid or debug issues if commits are unexpectedly blocked. You can manually edit `.git/config` to remove `required` if this behavior is undesired.
affects: >=0.8.1
gotchaWhen using `nbstripout` in CI/CD pipelines to verify notebooks, the `--verify` flag (introduced in 0.8.0) is crucial. Without it, `nbstripout` might not return a non-zero exit code upon detecting changes, leading to silent failures.
fix
Always use `nbstripout --verify` in CI/CD to ensure that pipelines fail if notebooks are not already stripped, returning an exit code of 1 if changes would have occurred.
affects: >=0.8.0
gotchaLine ending normalization (CRLF vs LF) can cause issues, especially across different operating systems. Version 0.8.2 improved preservation of Windows CRLF, and 0.9.1 introduced `--unix-newline` to force LF endings.
fix
For consistent line endings, consider using `nbstripout --unix-newline` if you primarily work in Unix-like environments or wish to standardize on LF endings. Otherwise, be aware that CRLF might be preserved on Windows.
affects: >=0.8.2
Errors
Common errors & fixes
nbstripout............................................................... Failed - hook id: nbstripout - files were modified by this hook
The pre-commit hook for `nbstripout` failed because `nbstripout` modified the notebook files (stripped outputs/metadata), and `pre-commit` is configured to fail if any changes are made by a hook without being explicitly re-staged.
fix
After the pre-commit hook reports failure and `nbstripout` has cleaned the files in your working directory, you need to stage these cleaned changes by running `git add .` and then `git commit` again. Alternatively, manually run `nbstripout <file.ipynb>` before committing.
FileNotFoundError: [WinError 2] The system cannot find the file specified.
This error, often seen on Windows, occurs when Git attempts to run `nbstripout` (or the Python interpreter specified in the Git configuration for `nbstripout`) as a filter or hook, but the executable cannot be found in the system's PATH or at the specified absolute path.
fix
Ensure that both your Python interpreter and the `nbstripout` executable are correctly in your system's PATH. If using `nbstripout --install`, you might need to manually edit your `.git/config` or global Git configuration to specify the full, absolute path to the Python interpreter (e.g., `C:/Python/Python39/python.exe -m nbstripout`) in the `filter.nbstripout.clean` setting.
error: external filter '"/path/to/python" -m nbstripout' failed
`nbstripout` failed to process a notebook file because the file is corrupted or contains invalid JSON, often due to unresolved Git merge conflicts (e.g., `<<<<<<<`, `=======`, `>>>>>>>` markers).
fix
Manually open the problematic `.ipynb` file in a text editor (not Jupyter) and resolve any merge conflict markers or other JSON syntax errors. Ensure the file is a valid JSON structure before attempting to commit or run `nbstripout` again.
command not found: nbstripout
The `nbstripout` command is not recognized because it is either not installed, or the shell environment (including Git's environment when running hooks) does not have the directory containing the `nbstripout` executable in its PATH.
fix
First, ensure `nbstripout` is installed (`pip install nbstripout` or `conda install -c conda-forge nbstripout`). If installed, activate the correct Python environment if you're using one (e.g., `conda activate myenv` or `source venv/bin/activate`). If used as a Git hook, ensure the hook script or Git configuration explicitly calls `python -m nbstripout` or provides the full path to the `nbstripout` executable.
nbstripout: command not found
The `nbstripout` executable is not in the system's PATH, or Git cannot locate it when running a hook.
fix
Ensure `nbstripout` is installed in a system-wide or readily accessible Python environment, or specify its full path in your Git configuration (e.g., `git config --global filter.nbstripout.clean "/path/to/nbstripout"`).
Upgrade
Version history
0.9.1latest on PyPI · released Feb 21, 2026
Audit
Dependencies
pythonrequiredRequires Python 3.10 or newer.
Agent activity
11 hits · last 30 days
node
10
Resources
nbstripout — pip install nbstripout · libregistry