Package: nbstripout-fast
nbstripout-fastA much faster version ofnbstripoutby 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.Installationpip install nbstripout-fastThen replace nbstripout-fast with anywhere you use nbstripout.Key differencesWhile we mirrored most of nbstripout's API, we do not support every
nbstripout option.There is no CLI option to install this in git for youWe support repository level settings in a.git-nbconfig.yamlfile. Check out
ourexamples. 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:Cellsnbstripoutnbstripout_fast10m0.266s0m0.003s100m0.258s0m0.003s1000m0.280s0m0.004s10000m0.372s0m0.013s100000m1.649s0m0.133sThe 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!DevelopingYou can use cargo which will build + run the CLI:cargo run -- -t examples/example.ipynbYou 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-fastRunning 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 -rPDebuggingUse RUST_LOG=debug to debug script for example:RUST_LOG=debug cargo run -- '--extra-keys "metadata.bar cell.baz" -t foo.ipynb'ReleasingManylinux, 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:Create a commit updating the version inCargo.tomlandCHANGELOG.md, then create a git tag:gittagvX.Y.Z
gitpush--tagsDraft a new release in github; select the tag that you just created.Once the new release is created, the wheels and sdist will be built by a
github workflow and then uploaded to PyPI automatically using thePYPI_API_TOKENin the github secrets for the repository.HistoryThis plugin was contributed back to the community by theD. E. Shaw group.LicenseThis project is released under aBSD-3-Clause license.We love contributions! Before you can contribute, please sign and submit thisContributor License Agreement (CLA).
This CLA is in place to protect all users of this project.