Skip to main content

Strips outputs from Jupyter notebooks

Project description

nbstripout-fast

PyPI version PyPI DM Github Actions Status

A much faster version of nbstripout by writing it in rust (of course). This helps strip Jupyter Notebook output and metadata from notebooks. It is very useful as a git filter and is highly configurable.

Installation

pip install nbstripout-fast

Then replace nbstripout-fast with anywhere you use nbstripout.

Key differences

  1. While we mirrored most of nbstripout's API, we do not support every nbstripout option.
  2. There is no CLI option to install this in git for you
  3. We support repository level settings in a .git-nbconfig.yaml file. Check out our examples. On a high level, you can add a git filter in a sitewide/user level and then allow each project to enforce consistent settings.

Why Rust?

nbstripout is a excellent project, but the python startup and import time makes its usage at scale a bit painful. While this means giving up on using nbconvert under the hood and ensuring the notebook is the correct format, it does make things up to 200x faster. This matters when you have a large number of files and git filter is called sometimes more than once per file. Let's look at the data:

Cells nbstripout nbstripout_fast
1 0m0.266s 0m0.003s
10 0m0.258s 0m0.003s
100 0m0.280s 0m0.004s
1000 0m0.372s 0m0.013s
10000 0m1.649s 0m0.133s

The table above shows a large overhead per notebook (mostly python startup time). When you have 100 or more notebooks, nbstripout takes more than 40s while nbstripout-fast takes only 1s!

Developing

You can use cargo which will build + run the CLI:

cargo run -- -t examples/example.ipynb

You can also build with cargo and run the script with the full path:

cargo build # dev build - ./target/debug/nbstripout-fast
cargo build --release # release build - ./target/release/nbstripout-fast

Running unit tests: maturin builds this repo to include pyo3 bindings by default. This allows for us to have an extension python extension mode as well. As of today, we can't have a binary and an extension, so we use the extension only for testing (issue).

pip install -e .
maturin develop
# Should output, this way you can use RUST_LOG=debug
in-venv pytest -rP

Debugging

Use RUST_LOG=debug to debug script for example:

RUST_LOG=debug cargo run -- '--extra-keys "metadata.bar cell.baz" -t foo.ipynb'

Releasing

Manylinux, macos, and windows wheels and sdist are built by github workflows. Builds are triggered upon the creation of a pull request, creating a new release, or with a manual workflow dispatch. The wheels and sdist are only uploaded to PyPI when a new release is published. In order to create a new release:

  1. Create a commit updating the version in Cargo.toml and CHANGELOG.md, then create a git tag:
git tag vX.Y.Z
git push --tags
  1. Draft a new release in github; select the tag that you just created.
  2. Once the new release is created, the wheels and sdist will be built by a github workflow and then uploaded to PyPI automatically using the PYPI_API_TOKEN in the github secrets for the repository.

History

This plugin was contributed back to the community by the D. E. Shaw group.

D. E. Shaw Logo

License

This project is released under a BSD-3-Clause license.

We love contributions! Before you can contribute, please sign and submit this Contributor License Agreement (CLA). This CLA is in place to protect all users of this project.

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

nbstripout_fast-1.0.2.tar.gz (22.0 kB view hashes)

Uploaded Source

Built Distributions

nbstripout_fast-1.0.2-cp311-none-win_amd64.whl (952.3 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

nbstripout_fast-1.0.2-cp311-none-win32.whl (884.0 kB view hashes)

Uploaded CPython 3.11 Windows x86

nbstripout_fast-1.0.2-cp311-cp311-musllinux_1_1_x86_64.whl (2.2 MB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

nbstripout_fast-1.0.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.1 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

nbstripout_fast-1.0.2-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (2.2 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

nbstripout_fast-1.0.2-cp310-none-win_amd64.whl (952.3 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

nbstripout_fast-1.0.2-cp310-none-win32.whl (884.0 kB view hashes)

Uploaded CPython 3.10 Windows x86

nbstripout_fast-1.0.2-cp310-cp310-musllinux_1_1_x86_64.whl (2.2 MB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

nbstripout_fast-1.0.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.1 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

nbstripout_fast-1.0.2-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (2.2 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

nbstripout_fast-1.0.2-cp39-none-win_amd64.whl (952.3 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

nbstripout_fast-1.0.2-cp39-none-win32.whl (884.0 kB view hashes)

Uploaded CPython 3.9 Windows x86

nbstripout_fast-1.0.2-cp39-cp39-musllinux_1_1_x86_64.whl (2.2 MB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

nbstripout_fast-1.0.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.1 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

nbstripout_fast-1.0.2-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (2.2 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page