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 nbstripoutVerified import paths — ran on the pinned version, not inferred.
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.
Upgrade your Python environment to 3.10 or higher, or explicitly install `nbstripout<0.9.0`.
Update any scripts or configurations to use `--drop-empty-cells` instead of `--strip-empty-cells`.
To preserve original cell IDs, use the `--keep-id` flag when running `nbstripout`.
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.
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.
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.
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.
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.
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.
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.
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"`).