Skip to main content

A command line tool to wipe clean jupyter notebooks, written in Rust

Project description

nbwipers

Test License:MIT PyPI - Version Crates.io Conda codecov

nbwipers is a command line tool to wipe clean jupyter notebooks, written in Rust.

The interface and functionality are based on nbstripout and the idea to implement it in rust comes from nbstripout-fast.

Usage

nbwipers has a few subcommands that provide functionality related to cleaning Jupyter notebooks.

  • clean: clean a single notebook. This is more-or-less equivalent to nbstripout.
  • check: check notebooks in a given path for elements that would be removed by clean. This could be used in a CI context to enforce clean notebooks.
  • clean-all clean all notebooks in a given path. This one should be used carefully!
  • install register nbwipers as a git filter for ipynb files. Equivalent to nbstripout --install
  • uninstall remove nbwipers as a git filter.
  • check-install check that nbwipers or nbstripout is installed in the local repo. This is used in the pre-commit hook.
  • show-config show the effective configuration nbwipers would use, merging the config file with any CLI overrides.
  • record record kernel metadata for notebooks in a local, git-untracked store, so it can be restored later even though strip-kernel-info removes it from committed notebooks. See Preserving kernel info locally below.
  • hook subcommands used by pre-commit-style hooks — currently check-large-files, which checks notebook file sizes after cleaning.

The full options can be found in CommandLineHelp.md.

Examples

To set up nbwipers as a git filter in your repository, use

nbwipers install local

If this step is performed on a pre-existing repo, you can touch your notebooks so that git can detect the changes. In bash:

for f in $(git ls-files '*.ipynb'); do touch $f; done

To check the notebooks in your folder, you can run the following

nbwipers check .

To see the configuration nbwipers would use in the current directory, you can run

nbwipers show-config

Add --show-all to also see the default values for settings that have not been explicitly configured.

Preserving kernel info locally

nbwipers install sets up both a clean filter, which strips notebooks before they are committed, and a smudge filter, which runs when notebooks are checked out.

If you enable strip-kernel-info (see Configuration) so that kernelspec and python-version metadata never gets committed, you can still keep that information around locally with record:

nbwipers record .

This saves the kernel metadata for notebooks under the given path to .git/x-nbwipers/kernelspec_store.json — local to your clone and never committed. The next time you check out one of those notebooks, the smudge filter automatically restores its recorded kernel metadata, so each collaborator keeps their own kernel/python version info without it living in version control.

To keep the local store tidy as notebooks come and go:

  • nbwipers record --sync . discards the whole store and rebuilds it from the notebooks currently found under ., dropping entries for notebooks that no longer exist.
  • nbwipers record --remove path/to/notebook.ipynb removes a specific notebook's entry, leaving the rest of the store untouched.
  • nbwipers record --clear wipes the store entirely.

pre-commit

You can add the following to your pre-commit-config.yaml file to ensure that nbwipers or nbstripout is installed in your repo, in order to prevent Jupyter notebook outputs from being committed to version control.

  - repo: https://github.com/felixgwilliams/nbwipers-pre-commit
    rev: v0.6.2
    hooks:
      - id: nbwipers-check-install

Alternatively, you can use the URL for this repo in your config, but this will compile nbwipers from source, rather than retrieving the binary from PyPI, and is therefore not recommended.

If you are using your pre-commit configuration as part of CI, you should set the environment variable NBWIPERS_CHECK_INSTALL_EXIT_ZERO which forces this check to pass, since you do not need nbwipers configured in your CI environment.

Configuration

Configuration is currently done via the tool.nbwipers section of the pyproject.toml file. Most of the command line options can be set per-project in the pyproject.toml, nbwipers.toml or .nbwipers.toml file. If you use pyroject.toml, you need to put the configuration under [tool.nbwipers]. If you use nbwipers.toml or .nbwipers.toml, the configuration needs to be at the top level.

For example you can use strip-kernel-info to remove metadata on the python version or the details about the Jupyter Kernel.

You can also drop cell ids using id-action = "drop".

To enable these options, you can include the following in your pyproject.toml file:

[tool.nbwipers]
strip-kernel-info = true
id-action = "drop"

The equivalent for nbwipers.toml or .nbwipers.toml is just

strip-kernel-info = true
id-action = "drop"

This can be useful when collaborating, as the precise python version and the name assigned to the kernel are ephemeral and can change from person to person. Cell IDs are another element of the file which is generated by the tool you use and can change from person to person.

Motivation

A working copy of a Jupyter notebook contains:

  1. Code written by the author.
  2. Notebook outputs: tables, logs, tracebacks, images, widgets and so on...
  3. Execution counts.
  4. Metadata, such as whether cells are collapsed, scrollable etc.

Of these categories of data, only the first — code written by the author — should definitely be tracked by version control, since it is the product of the author's intention and hard work. The other categories of data are subject to change outside of the explicit intentions of the author and are generally noisy from a version control perspective.

Moreover, including notebook outputs in version control

  • makes diffs harder to interpret, as they will contain lots of unintended changes.
  • increases the risk of a tricky merge conflict if different users run the same cell and get a slightly different result.
  • increases the amount of data committed, which can degrade repository performance.
  • risks leaking sensitive data.

An effective way to ensure you do not commit problematic parts of your notebooks is to use nbwipers or nbstripout as a git filter.

A git filter sits between your actual files and what git sees when you stage and commit your changes. This way, git only sees the transformed version of the file without the problematic elements. At the same time, you do not have to lose them from your local copy.

An exception is when you checkout a branch or do a git pull, which results in changes to the notebook. In this case, your local copy will be replaced by the clean version and you will lose your cell outputs.

Acknowledgements

nbwipers relies on inspiration and code from several projects. For the projects, whose code was used please see LICENSE for the third-party notices.

nbstripout

strip output from Jupyter and IPython notebooks

nbstripout is an invaluable tool for working with Jupyter Notebooks in the context of version control. This project forms the basis of the interface and logic of this project and is also the source of the testing examples.

nbstripout-fast

A much faster version of nbstripout by writing it in rust (of course).

nbstripout-fast, like this project, implements the functionality of nbstripout in Rust, while also allowing repo-level configuration in a YAML file.

With nbwipers I hoped to recreate the idea of nbstripout-fast, but with the ability to install as a git filter, and configuration via pyproject.toml.

ruff

An extremely fast Python linter and code formatter, written in Rust.

Ruff is quickly becoming the linter for python code, thanks to its performance, extensive set of rules and its ease of use. It was a definite source of knowledge for the organisation of the configuration and the file discovery. The schema for Jupyter Notebooks, and some of the file discovery code was adapted from Ruff.

pre-commit

A framework for managing and maintaining multi-language pre-commit hooks.

This repo contains a version of the check-large-files hook, that will not flag notebook files whose clean size is less that the threshold, even if the size on-disk including outputs is greater than the threshold. The logic and interface of the hook was adapted from the pre-commit-hooks repository.

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

nbwipers-0.7.0.tar.gz (77.4 kB view details)

Uploaded Source

Built Distributions

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

nbwipers-0.7.0-py3-none-win_amd64.whl (1.9 MB view details)

Uploaded Python 3Windows x86-64

nbwipers-0.7.0-py3-none-win32.whl (1.7 MB view details)

Uploaded Python 3Windows x86

nbwipers-0.7.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.3 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64

nbwipers-0.7.0-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl (2.3 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ s390x

nbwipers-0.7.0-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (2.5 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ppc64le

nbwipers-0.7.0-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl (2.4 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ i686

nbwipers-0.7.0-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (2.1 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARMv7l

nbwipers-0.7.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.2 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARM64

nbwipers-0.7.0-py3-none-macosx_11_0_arm64.whl (2.0 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

nbwipers-0.7.0-py3-none-macosx_10_12_x86_64.whl (2.1 MB view details)

Uploaded Python 3macOS 10.12+ x86-64

File details

Details for the file nbwipers-0.7.0.tar.gz.

File metadata

  • Download URL: nbwipers-0.7.0.tar.gz
  • Upload date:
  • Size: 77.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for nbwipers-0.7.0.tar.gz
Algorithm Hash digest
SHA256 1f01af37887f513361a0a7f70ae74393a5010c8ba25a9ab65c3ba2b67aeb1a16
MD5 62db24459e3ed1099a7f38d3cae218ef
BLAKE2b-256 56e7240a28e3a6d7da1a07eba60335bf998d9923bb220e1e94391c74ef58beb0

See more details on using hashes here.

Provenance

The following attestation bundles were made for nbwipers-0.7.0.tar.gz:

Publisher: release.yml on felixgwilliams/nbwipers

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nbwipers-0.7.0-py3-none-win_amd64.whl.

File metadata

  • Download URL: nbwipers-0.7.0-py3-none-win_amd64.whl
  • Upload date:
  • Size: 1.9 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for nbwipers-0.7.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 ad6c59613e9701707b79e875b29966f70fbaa8fbaa42d6b53a8af64e51a3530c
MD5 57771220654bab33233c99e6591ddae3
BLAKE2b-256 9fc096e0bff2a83f4bad25c49b0c72b861500a05297713ce397b4d251695197d

See more details on using hashes here.

Provenance

The following attestation bundles were made for nbwipers-0.7.0-py3-none-win_amd64.whl:

Publisher: release.yml on felixgwilliams/nbwipers

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nbwipers-0.7.0-py3-none-win32.whl.

File metadata

  • Download URL: nbwipers-0.7.0-py3-none-win32.whl
  • Upload date:
  • Size: 1.7 MB
  • Tags: Python 3, Windows x86
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for nbwipers-0.7.0-py3-none-win32.whl
Algorithm Hash digest
SHA256 a5e38956186f1033b4db6d7780b07133538f9d06c74ee7a76cec77e0c2912115
MD5 a98cfce423e346c443c67ce6f7a08275
BLAKE2b-256 1871fb9e910249f03f16426051b29589c764640ab3fc2ce54b14ceada682f600

See more details on using hashes here.

Provenance

The following attestation bundles were made for nbwipers-0.7.0-py3-none-win32.whl:

Publisher: release.yml on felixgwilliams/nbwipers

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nbwipers-0.7.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for nbwipers-0.7.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 23d6818f61ca06d9983e2680f879304d8554050453969cfffc40bd891aeaf53b
MD5 90d32de0798a42b1e586ab736b68f16c
BLAKE2b-256 8dd1279c5341e5aadc72bfd4bb570c69ccef6acfe6875048715437dbca0099e2

See more details on using hashes here.

Provenance

The following attestation bundles were made for nbwipers-0.7.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on felixgwilliams/nbwipers

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nbwipers-0.7.0-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl.

File metadata

File hashes

Hashes for nbwipers-0.7.0-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 d4ba1dc8a70bbce37e12241e590a6a6a6a8c9c453ed2f9c180ed82992f639055
MD5 caafcd380f766d92e0eb3b6fa100f9af
BLAKE2b-256 e8680bd83524ac38a2c9ac2e977db7e7c1dce832b321289bb907720da000d672

See more details on using hashes here.

Provenance

The following attestation bundles were made for nbwipers-0.7.0-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl:

Publisher: release.yml on felixgwilliams/nbwipers

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nbwipers-0.7.0-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl.

File metadata

File hashes

Hashes for nbwipers-0.7.0-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 cca7bc147d8f292f5e9b57dadeffbe54809fd5db6df3f0f8a54694e11b51aecb
MD5 7566c10940179eceabb504e13ec00e85
BLAKE2b-256 17da4c3c4c3dcdbad6dca8981d8b5479d1b71c49a2d14fba7c5b7aef028f90ee

See more details on using hashes here.

Provenance

The following attestation bundles were made for nbwipers-0.7.0-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl:

Publisher: release.yml on felixgwilliams/nbwipers

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nbwipers-0.7.0-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for nbwipers-0.7.0-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 1bd7d000f05676e008f17c52f4cfafd02dab680008481165a34fedd44b911812
MD5 b5a1b691b4c274fc31181b63c37e4258
BLAKE2b-256 189d4f77809c9bf0080df4d02f7da783d992eed6e178b753ba758902db2dd7bb

See more details on using hashes here.

Provenance

The following attestation bundles were made for nbwipers-0.7.0-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl:

Publisher: release.yml on felixgwilliams/nbwipers

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nbwipers-0.7.0-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.

File metadata

File hashes

Hashes for nbwipers-0.7.0-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 7b8da862164411440f22720dc077018781e56e1588dcbec2ec3e7251d6c7c91b
MD5 539efa3afffa633c823947e5839649b8
BLAKE2b-256 e4c29defe7b7f6cde88626c89af1e4ce36a3219bbe6202e52f638a0f71ebe436

See more details on using hashes here.

Provenance

The following attestation bundles were made for nbwipers-0.7.0-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl:

Publisher: release.yml on felixgwilliams/nbwipers

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nbwipers-0.7.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for nbwipers-0.7.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 9c003d86832f646fb3295a26d25c4a76436b0a13f061ca8cc91e49c43ddb6376
MD5 c9c7073cc305d5d94aaa12599f09ac5d
BLAKE2b-256 6e0723bd8776fae1fb768539d0d8b7d888a0aabef63b5edcc7a1cdc329546dd6

See more details on using hashes here.

Provenance

The following attestation bundles were made for nbwipers-0.7.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on felixgwilliams/nbwipers

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nbwipers-0.7.0-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for nbwipers-0.7.0-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d52f98df08cf8c5b5067818a028b3804af2c68df4ad028d4fb36ca60f2c6ee26
MD5 872103ad6cfc4560cc0890206c284e8a
BLAKE2b-256 50ae209c2bc2c7d6d2d59843b50a1f45ef1bf7980bb00ed5ded2446fa97c5392

See more details on using hashes here.

Provenance

The following attestation bundles were made for nbwipers-0.7.0-py3-none-macosx_11_0_arm64.whl:

Publisher: release.yml on felixgwilliams/nbwipers

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nbwipers-0.7.0-py3-none-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for nbwipers-0.7.0-py3-none-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 727702e84ab3fc27f539a6701d7a20a80a6c33b73354297f4bf726dda4b07cd5
MD5 05c3c59fbb763b4479d758612b8fad92
BLAKE2b-256 d5b38b6dbebdb118916942393d9287d5722d728061e7c7b8cd1d292200c82d2d

See more details on using hashes here.

Provenance

The following attestation bundles were made for nbwipers-0.7.0-py3-none-macosx_10_12_x86_64.whl:

Publisher: release.yml on felixgwilliams/nbwipers

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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