{"id":4644,"library":"nbstripout","title":"nbstripout","description":"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.","status":"active","version":"0.9.1","language":"en","source_language":"en","source_url":"https://github.com/kynan/nbstripout","tags":["jupyter","notebooks","git-hook","ci","code-quality","pre-commit"],"install":[{"cmd":"pip install nbstripout","lang":"bash","label":"Install nbstripout"}],"dependencies":[{"reason":"Requires Python 3.10 or newer.","package":"python","optional":false}],"imports":[{"note":"While nbstripout is primarily a command-line tool, its core logic can be used programmatically.","symbol":"strip_output (programmatic API)","correct":"from nbstripout import strip_output"}],"quickstart":{"code":"# 1. Install nbstripout\npip install nbstripout\n\n# 2. Install the git hook in your repository\n# This ensures outputs are stripped automatically before committing.\n# Navigate to your git repository first.\n# os.system('nbstripout --install') # Uncomment to run, but be aware it modifies your .git/config\n\n# 3. Example of programmatic usage (optional)\nfrom nbstripout import strip_output\nimport json\n\n# Simulate reading a notebook file\nexample_notebook_content = {\n    \"cells\": [\n        {\n            \"cell_type\": \"code\",\n            \"execution_count\": 1,\n            \"metadata\": {},\n            \"outputs\": [\n                {\n                    \"name\": \"stdout\",\n                    \"output_type\": \"stream\",\n                    \"text\": [\"Hello, nbstripout!\\n\"]\n                }\n            ],\n            \"source\": \"print('Hello, nbstripout!')\"\n        }\n    ],\n    \"metadata\": {\n        \"kernelspec\": {\n            \"display_name\": \"Python 3\",\n            \"language\": \"python\",\n            \"name\": \"python3\"\n        }\n    },\n    \"nbformat\": 4,\n    \"nbformat_minor\": 5\n}\n\n# Strip outputs from the notebook content\nstripped_notebook_content = strip_output(json.dumps(example_notebook_content))\n\n# Print the stripped content (outputs should be empty)\nprint(\"\\n--- Original Notebook ---\")\nprint(json.dumps(example_notebook_content, indent=2))\nprint(\"\\n--- Stripped Notebook ---\")\nprint(json.dumps(json.loads(stripped_notebook_content), indent=2))\n","lang":"python","description":"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."},"warnings":[{"fix":"Upgrade your Python environment to 3.10 or higher, or explicitly install `nbstripout<0.9.0`.","message":"Python 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.","severity":"breaking","affected_versions":">=0.9.0"},{"fix":"Update any scripts or configurations to use `--drop-empty-cells` instead of `--strip-empty-cells`.","message":"The command-line option `--strip-empty-cells` was renamed to `--drop-empty-cells` in version 0.6.0. Scripts using the old flag will fail.","severity":"breaking","affected_versions":">=0.6.0"},{"fix":"To preserve original cell IDs, use the `--keep-id` flag when running `nbstripout`.","message":"Starting 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.","severity":"gotcha","affected_versions":">=0.7.0"},{"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.","message":"Since 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.","severity":"gotcha","affected_versions":">=0.8.1"},{"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.","message":"When 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.","severity":"gotcha","affected_versions":">=0.8.0"},{"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.","message":"Line 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.","severity":"gotcha","affected_versions":">=0.8.2"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}