nbparts: Unpack a Jupyter notebook into its sources, metadata and outputs

[ apache, data, library, program ] [ Propose Tags ] [ Report a vulnerability ]

nbparts is a tool for splitting Jupyter notebooks into its "parts":

  • sources (code and markdown content),

  • outputs, and

  • metadata.

These parts can be re-assembled back into an equivalent Jupyter notebook. The goal is to make it easier to store and diff Jupyter notebooks in text-based version control systems like Git.


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0
Change log CHANGELOG.md
Dependencies aeson (>=2.2.3.0 && <2.3), aeson-pretty (>=0.8.10 && <0.9), base (>=4.19 && <5), base64-bytestring (>=1.2.1.0 && <1.3), bytestring (>=0.12.1.0 && <0.13), commonmark (>=0.2.6.1 && <0.3), containers (>=0.7 && <0.8), crypton (>=1.0.4 && <1.1), directory (>=1.3.8.5 && <1.4), filepath (>=1.4.301.0 && <1.5), ipynb (>=0.2 && <0.3), libyaml (>=0.1.4 && <0.2), megaparsec (>=9.7.0 && <9.8), memory (>=0.18.0 && <0.19), mime-types (>=0.1.2.0 && <0.2), mtl (>=2.3.1 && <2.4), nbparts, optparse-applicative (>=0.19.0.0 && <0.20), parsec (>=3.1.18.0 && <3.2), text (>=2.1.1 && <2.2), transformers (>=0.6.0.0 && <0.7), yaml (>=0.11.11.2 && <0.12) [details]
Tested with ghc ==9.8, ghc ==9.10, ghc ==9.12
License Apache-2.0[multiple license files]
Copyright (c) 2025 Dixon Sean Low Yan Feng
Author Dixon Sean Low Yan Feng
Maintainer root@dixslyf.dev
Category Data
Home page https://github.com/dixslyf/nbparts
Bug tracker https://github.com/dixslyf/nbparts/issues
Source repo head: git clone https://github.com/dixslyf/nbparts
Uploaded by dixslyf at 2025-09-17T15:34:08Z
Distributions
Executables nbparts
Downloads 2 total (2 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2025-09-17 [all 1 reports]

Readme for nbparts-0.1.0.0

[back to package description]

nbparts

Build Build (Nix)

nbparts is a tool for splitting Jupyter notebooks into its "parts":

  • sources (code and Markdown content),

  • outputs, and

  • metadata.

These parts can be re-assembled back into an equivalent Jupyter notebook. The goal is to make it easier to store and diff Jupyter notebooks in text-based version control systems like Git.

Features

  • Unpack: Split a Jupyter notebook into its sources, outputs and metadata.

  • Pack: Reconstruct the original Jupyter notebook from unpacked parts.

  • Formats:

    • Sources can be exported as YAML, JSON or Markdown.

    • Outputs and metadata can be exported as YAML or JSON.

  • Binary outputs and attachments (e.g. PNG images, Markdown attachments) are extracted as files alongside the parts.

  • Roundtrip safety: unpack followed by pack yields a notebook semantically equivalent to the original. Markdown and code formatting is preserved.

    The only known caveat at this point in time is that, when re-encoding binary attachments and outputs into base64, nbparts always performs line wrapping after 76 characters; however, not all Jupyter notebook platforms perform line wrapping on the base64 strings, so although the content reconstructed by nbparts is the same, the formatting may slightly differ.

Motivation

Jupyter notebooks are widely used for data exploration and analysis, but because they are large JSON documents, storing them in version control systems like Git is painful:

  • Attachments, execution outputs and metadata add significant noise to diffs and overshadow meaningful changes.

  • Even after removing metadata and binary outputs from a notebook, the diffs for small edits to code or Markdown content are a little difficult to read due to syntactic JSON elements.

  • Collaborating on notebooks is hard when every commit contains unrelated noise.

Tools like Jupytext (awesome tool!) help by representing notebook sources as plaintext. nbparts complements this idea by splitting a notebook not only into its sources, but also into its outputs and metadata, as separate parts. This gives us more flexibility:

  • If you only care about the source code and Markdown, you can ignore the outputs and metadata.

  • If outputs or metadata matter for reproducibility, you can commit them alongside the sources. Since attachments and binary outputs are extracted, you may even use tools like Git LFS for versioning them.

Installation

Cabal

nbparts can be installed with Cabal.

You may first want to update Cabal's package database:

cabal update

Then, run:

cabal install nbparts

With the default Cabal configuration, this will install nbparts into ~/.cabal/bin on Linux / macOS and %APPDATA%\cabal\bin on Windows.

Pre-Built Binaries

Static binaries for x86_64 Linux are available from the releases.

Unfortunately, no binary releases are available for macOS and Windows at this point in time (contributions welcome!). Please refer to Compiling from Source.

Basic Usage

Unpack a notebook with all parts exported to YAML:

# This will create a `notebook.ipynb.nbparts` directory.
nbparts unpack notebook.ipynb

Pack the parts back into a notebook:

nbparts pack notebook.ipynb.nbparts -o notebook-repacked.ipynb

Unpack a notebook, with sources exported to Markdown:

nbparts unpack notebook.ipynb --sources-format markdown

For more options, see:

nbparts --help

Compiling From Source

Cabal

nbparts uses Cabal for building and packaging.

To build and install nbparts, ensure you have Cabal and GHC installed.

Update Cabal's package database:

cabal update

Now, clone the repository and cd into it. Then, run:

cabal install

With the default Cabal configuration, this will build and install nbparts into ~/.cabal/bin on Linux / macOS and %APPDATA%\cabal\bin on Windows.

Nix

nbparts provides a Nix flake for building x86_64 Linux binaries.

To build:

nix build github:dixslyf/nbparts#nbparts

To run:

nix run github:dixslyf/nbparts#nbparts

Static binaries can be built using Nix and are exposed as the nbparts-static flake output:

nix build github:dixslyf/nbparts#nbparts-static
nix run github:dixslyf/nbparts#nbparts-static

Running Tests

nbparts uses Hspec and Hedgehog for testing.

To run nbparts's tests, clone the repository and cd into it. Then, run:

cabal test

Nix

Tests can also be run with Nix:

nix run github:dixslyf/nbparts#nbparts:test:test-nbparts