Skip to main content

Clean Jupyter notebooks for versioning

Project description

nb-clean

nb-clean cleans Jupyter notebooks of cell execution counts, metadata, outputs, and (optionally) empty cells, preparing them for committing to version control. It provides a Git filter to automatically clean notebooks before they are staged, and can also be used as a standalone tool outside Git or with other version control systems. It can determine if a notebook is clean or not, which can be used as a check in your continuous integration pipelines.

Installation

To install the latest release from PyPI, use pip:

python3 -m pip install nb-clean

Alternately, in Python projects using Poetry or Pipenv for dependency management, add nb-clean as a development dependency with poetry add --dev nb-clean or pipenv install --dev nb-clean. nb-clean requires Python 3.6 or later.

Usage

Cleaning

To install a filter in an existing Git repository to automatically clean notebooks before they are staged, run the following from the working tree:

nb-clean configure-git

This will configure a filter to remove cell execution counts, metadata, and outputs. To also remove empty cells, use:

nb-clean configure-git --remove-empty

To preserve cell metadata, such as that required by tools such as papermill, use:

nb-clean configure-git --preserve-metadata

nb-clean will configure a filter in the Git repository in which it is run, and will not mutate your global or system Git configuration. To remove the filter, run:

nb-clean unconfigure-git

Aside from usage from a filter in a Git repository, you can also clean up a Jupyter notebook manually with:

nb-clean clean -i original.ipynb -o cleaned.ipynb

or by passing the notebook contents on stdin:

nb-clean clean < original.ipynb > cleaned.ipynb

To also remove empty cells, add the --remove--empty flag. To preserve cell metadata, add the --preserve-metadata flag.

Checking

You can check if a notebook is clean with:

nb-clean check -i notebook.ipynb

or by passing the notebook contents on stdin:

nb-clean check < notebook.ipynb

To also check for empty cells, add the --remove--empty flag. To ignore cell metadata, add the --preserve-metadata flag.

nb-clean will exit with status code 0 if the notebook is clean, and status code 1 if it is not. nb-clean will also print details of cell execution counts, metadata, outputs, and empty cells it finds.

Copyright

Copyright © 2017-2020 Scott Stevenson.

nb-clean is distributed under the terms of the ISC licence.

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

nb-clean-1.6.0.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

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

nb_clean-1.6.0-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file nb-clean-1.6.0.tar.gz.

File metadata

  • Download URL: nb-clean-1.6.0.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.10 CPython/3.6.10 Linux/4.9.0-11-amd64

File hashes

Hashes for nb-clean-1.6.0.tar.gz
Algorithm Hash digest
SHA256 b53fbdd53f69cff97de405319b803512a4ca1881862031c43a2607b48edb50a1
MD5 a6b56596dc6892f44bed4fd9477e84e6
BLAKE2b-256 4e8afa83d350129fd5643724ce910bd79f87c090b4764778fe56533d55b9b2f9

See more details on using hashes here.

File details

Details for the file nb_clean-1.6.0-py3-none-any.whl.

File metadata

  • Download URL: nb_clean-1.6.0-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.10 CPython/3.6.10 Linux/4.9.0-11-amd64

File hashes

Hashes for nb_clean-1.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 06b7c80cede05e069d38a0d88d31e2187272857db9f7fd5b3b04320724d98256
MD5 7fde576ef94fad565976b929917543dd
BLAKE2b-256 848a66d44826feb4e9cc3c64e7087db371525eea98f83cc78c484b92fafe43a1

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