Skip to main content
Help us improve Python packaging – donate today!

Strips outputs from Jupyter and IPython notebooks

Project Description

https://travis-ci.org/kynan/nbstripout.svg?branch=master

nbstripout: strip output from Jupyter and IPython notebooks

Opens a notebook, strips its output, and writes the outputless version to the original file.

Useful mainly as a git filter or pre-commit hook for users who don’t want to track output in VCS.

This does mostly the same thing as the Clear All Output command in the notebook UI.

Based on https://gist.github.com/minrk/6176788.

Screencast

This screencast demonstrates the use and working principles behind the nbstripout utility and how to use it as a Git filter:

http://i.imgur.com/7oQHuJ5.png

Installation

You can download and install the latest version of nbstripout from PyPI, the Python package index, as follows:

pip install --upgrade nbstripout

When using the Anaconda Python distribution, install nbstripout via the conda package manager from conda-forge:

conda install -c conda-forge nbstripout

Usage

Strip output from IPython / Jupyter notebook (modifies the files in-place):

nbstripout FILE.ipynb [FILE2.ipynb ...]

Force processing of non .ipynb files:

nbstripout -f FILE.ipynb.bak

Write to stdout e.g. to use as part of a shell pipeline:

cat FILE.ipynb | nbstripout > OUT.ipynb

or

nbstripout -t FILE.ipynb | other-command

Set up the git filter and attributes as described in the manual installation instructions below:

nbstripout --install

Set up the git filter using .gitattributes

nbstripout --install --attributes .gitattributes

Remove the git filter and attributes:

nbstripout --uninstall

Remove the git filter and attributes from .gitattributes:

nbstripout --uninstall --attributes .gitattributes

Check if nbstripout is installed in the current repository (exits with code 0 if installed, 1 otherwise):

nbstripout --is-installed

Print status of nbstripout installation in the current repository and configuration summary of filter and attributes if installed (exits with code 0 if installed, 1 otherwise):

nbstripout --status

Print the version:

nbstripout --version

Show this help page:

nbstripout --help

Keeping some output

Do not strip the execution count/prompt number

nbstripout --keep-count

Do not strip the output

nbstripout --keep-output

To mark special cells so that the output is not striped, set the "keep_output": true metadata on the cell. To do this, select the “Edit Metadata” Cell Toolbar, and then use the “Edit Metadata” button on the desired cell to enter something like:

{
  "keep_output": true,
}

Another use-case is to preserve initialization cells that might load customized CSS etc. critical for the display of the notebook. To support this, we also keep output for cells with:

{
  "init_cell": true,
}

This is the same metadata used by the init_cell nbextension.

Manual filter installation

Set up a git filter using nbstripout as follows:

git config filter.nbstripout.clean '/path/to/nbstripout'
git config filter.nbstripout.smudge cat
git config filter.nbstripout.required true

Create a file .gitattributes or .git/info/attributes with:

*.ipynb filter=nbstripout

Apply the filter for git diff of *.ipynb files:

git config diff.ipynb.textconv '/path/to/nbstripout -t'

In file .gitattributes or .git/info/attributes add:

*.ipynb diff=ipynb

Mercurial usage

Mercurial does not have the equivalent of smudge filters. One can use an encode/decode hook but this has some issues. An alternative solution is to provide a set of commands that first run nbstripout, then perform these operations. This is the approach of the mmf-setup package.

Release history Release notifications

This version
History Node

0.3.1

History Node

0.3.0

History Node

0.2.9

History Node

0.2.8

History Node

0.2.7

History Node

0.2.6

History Node

0.2.5

History Node

0.2.4

History Node

0.2.3

History Node

0.2.2

History Node

0.2.1

History Node

0.2.0

Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
nbstripout-0.3.1-py2.py3-none-any.whl (10.7 kB) Copy SHA256 hash SHA256 Wheel 3.5 Jul 30, 2017
nbstripout-0.3.1.tar.gz (6.6 kB) Copy SHA256 hash SHA256 Source None Jul 30, 2017

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page