Skip to main content

Fast, lightweight notebook conversion library

Project description

notebookx

A fast, lightweight notebook conversion library written in Rust with Python bindings.

notebookx is a Rust-based alternative to Python's nbconvert, providing fast notebook conversion between formats like .ipynb and percent format (.pct.py).

Features

  • Fast: Written in Rust for maximum performance
  • Multiple interfaces: Use as a Rust library, CLI tool (nbx), or Python package
  • Format conversion: Convert between ipynb and percent format
  • Notebook cleaning: Strip outputs, execution counts, and metadata for version control
  • Cross-platform: Works on Linux, macOS, and Windows

Installation

Python

pip install notebookx-py

Rust

Add to your Cargo.toml:

[dependencies]
notebookx = "0.1"

CLI

cargo install notebookx --features cli

Usage

Python

from notebookx import Notebook, Format, CleanOptions

# Load a notebook
nb = Notebook.from_file("example.ipynb")

# Convert to percent format
nb.to_file("example.pct.py")

# Or get as string
percent_content = nb.to_string(Format.Percent)

# Clean notebook for version control
clean_nb = nb.clean(CleanOptions(
    remove_outputs=True,
    remove_execution_counts=True,
))
clean_nb.to_file("clean.ipynb")

# Convenience functions
from notebookx import convert, clean_notebook

convert("input.ipynb", "output.pct.py")
clean_notebook("notebook.ipynb", remove_outputs=True)

CLI (nbx)

# Convert ipynb to percent format
nbx convert notebook.ipynb --to notebook.pct.py

# Convert percent to ipynb
nbx convert notebook.pct.py --to notebook.ipynb

# Clean a notebook (remove outputs)
nbx clean notebook.ipynb --output clean.ipynb --remove-outputs

# Clean in place
nbx clean notebook.ipynb --in-place --remove-outputs --remove-execution-counts

# Use stdin/stdout
cat notebook.ipynb | nbx convert - --from-fmt ipynb --to - --to-fmt percent

Rust

use notebookx::{Notebook, NotebookFormat, CleanOptions};

// Parse from file
let content = std::fs::read_to_string("example.ipynb")?;
let notebook = NotebookFormat::Ipynb.parse(&content)?;

// Convert to percent format
let percent = NotebookFormat::Percent.serialize(&notebook)?;

// Clean notebook
let options = CleanOptions {
    remove_outputs: true,
    remove_execution_counts: true,
    ..Default::default()
};
let clean = notebook.clean(&options);

// Save to file
let output = NotebookFormat::Ipynb.serialize(&clean)?;
std::fs::write("clean.ipynb", output)?;

Supported Formats

Format Extension Description
ipynb .ipynb Standard Jupyter notebook format (JSON)
percent .pct.py Percent format used by Jupytext, VSCode, etc.

Clean Options

When cleaning notebooks, you can control what gets removed:

Option Description
remove_outputs Remove all cell outputs
remove_execution_counts Reset execution counts to null
remove_cell_metadata Remove cell-level metadata
remove_notebook_metadata Remove notebook-level metadata
remove_kernel_info Remove kernel specification
preserve_cell_ids Keep cell IDs (default: regenerate)
remove_output_metadata Remove metadata from outputs
remove_output_execution_counts Remove execution counts from outputs

Presets

Python:

# For version control (removes cell metadata, execution counts, and output metadata)
# Preserves outputs so rendered content remains visible
options = CleanOptions.for_vcs()

# Strip everything (including outputs)
options = CleanOptions.strip_all()

CLI Reference

nbx convert

Convert notebooks between formats.

nbx convert <INPUT> --to <OUTPUT> [OPTIONS]

Options:
  --from-fmt <FORMAT>  Input format (ipynb, percent). Inferred from extension if not specified.
  --to-fmt <FORMAT>    Output format (ipynb, percent). Inferred from extension if not specified.
  -h, --help           Print help

nbx clean

Clean notebooks by removing outputs and metadata.

nbx clean <INPUT> [OPTIONS]

Options:
  -o, --output <FILE>           Output file (default: stdout)
  -i, --in-place                Modify file in place
  -O, --remove-outputs          Remove all outputs
  -e, --remove-execution-counts Remove execution counts
  --remove-cell-metadata        Remove cell metadata
  --remove-notebook-metadata    Remove notebook metadata
  --remove-kernel-info          Remove kernel specification
  -h, --help                    Print help

Development

Building from source

# Clone the repository
git clone https://github.com/lukastk/notebookx.git
cd notebookx

# Build Rust library and CLI
cargo build --release

# Build Python package
pip install maturin
maturin develop

Running tests

# Rust tests
cargo test --workspace

# Python tests
pytest tests/python

License

MIT

Acknowledgements

Example notebooks in nb_format_examples/ are from the Jupytext demo.

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

notebookx_py-0.1.7.tar.gz (39.8 kB view details)

Uploaded Source

Built Distributions

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

notebookx_py-0.1.7-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (788.2 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

notebookx_py-0.1.7-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (791.0 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

notebookx_py-0.1.7-cp38-abi3-win_amd64.whl (624.8 kB view details)

Uploaded CPython 3.8+Windows x86-64

notebookx_py-0.1.7-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (812.4 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ x86-64

notebookx_py-0.1.7-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (789.9 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARM64

notebookx_py-0.1.7-cp38-abi3-macosx_11_0_arm64.whl (731.7 kB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

notebookx_py-0.1.7-cp38-abi3-macosx_10_12_x86_64.whl (760.8 kB view details)

Uploaded CPython 3.8+macOS 10.12+ x86-64

File details

Details for the file notebookx_py-0.1.7.tar.gz.

File metadata

  • Download URL: notebookx_py-0.1.7.tar.gz
  • Upload date:
  • Size: 39.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for notebookx_py-0.1.7.tar.gz
Algorithm Hash digest
SHA256 b2a5edb5a6d1bf88eaef53eee2c2f76fefc1686254e1a9d5e87d2a8b059350fa
MD5 6bf9ea1401c37ac162b85f8973295f8c
BLAKE2b-256 3e90c4ed27d24442769a287158dcbf1acd155e9a07f1052d5789cc02aa1b3b1b

See more details on using hashes here.

Provenance

The following attestation bundles were made for notebookx_py-0.1.7.tar.gz:

Publisher: release.yml on lukastk/notebookx

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

File details

Details for the file notebookx_py-0.1.7-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for notebookx_py-0.1.7-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a24c370a2ffb266036071e3605ee37c83fbf6769d03a23e25910739eb8ff8a1f
MD5 c8aa35b637ac8093e8a12ae15b4f329f
BLAKE2b-256 223dd66fd75e2c7e8c0d2804a0a1f4d421a711e76c1ddc41e5252e08ccb92e8d

See more details on using hashes here.

Provenance

The following attestation bundles were made for notebookx_py-0.1.7-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on lukastk/notebookx

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

File details

Details for the file notebookx_py-0.1.7-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for notebookx_py-0.1.7-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 e2542d7e7588579258681865a42766bf7d38040e37150819430929db2884e4b1
MD5 650f605993e3b56cb17f4ea94bb089e8
BLAKE2b-256 b5a211eb498d584309951de9c58c43cb87fd7fdeb28e42292a5bc00424aa8253

See more details on using hashes here.

Provenance

The following attestation bundles were made for notebookx_py-0.1.7-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on lukastk/notebookx

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

File details

Details for the file notebookx_py-0.1.7-cp38-abi3-win_amd64.whl.

File metadata

  • Download URL: notebookx_py-0.1.7-cp38-abi3-win_amd64.whl
  • Upload date:
  • Size: 624.8 kB
  • Tags: CPython 3.8+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for notebookx_py-0.1.7-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 fe01624fa3896554f7bb95fe3e9817806f7fabf6e90b4693c77ecf323c34f232
MD5 10912acf21d2e0bf214327f83a8b19f3
BLAKE2b-256 04ef1385db1ca416cafe4425470655c04ba9316a584c93afa3fe88d9e19dab3f

See more details on using hashes here.

Provenance

The following attestation bundles were made for notebookx_py-0.1.7-cp38-abi3-win_amd64.whl:

Publisher: release.yml on lukastk/notebookx

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

File details

Details for the file notebookx_py-0.1.7-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for notebookx_py-0.1.7-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 14b02e8ae8304f3b7f6e0327a59de91b62c3fc0d57b51ee7c6ba24273ef98b75
MD5 f53628aa0b5c28b1226a8970fcc03b2b
BLAKE2b-256 3fcc5de9ec770e47978411a575f0d55b8b38c45cf01dd59c3d4971283944a42c

See more details on using hashes here.

Provenance

The following attestation bundles were made for notebookx_py-0.1.7-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on lukastk/notebookx

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

File details

Details for the file notebookx_py-0.1.7-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for notebookx_py-0.1.7-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 69cc86601cd1a1b7cb1ac86b577f28a9c09f629da191844903baec3aec347f8b
MD5 0cb0d8b9a908bde437d521520692b16d
BLAKE2b-256 621cd3f8339243bcf649fb375eb92ac27a13ab0bf3e86aee510b7a27a910ead6

See more details on using hashes here.

Provenance

The following attestation bundles were made for notebookx_py-0.1.7-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on lukastk/notebookx

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

File details

Details for the file notebookx_py-0.1.7-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for notebookx_py-0.1.7-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c75687a9dc279a0a0437ae52d74d6f0b195e1589f6d40fe898b23e0aea46b373
MD5 2145fe484e77cf545b11bc49c352b58a
BLAKE2b-256 77d084dd9e328f1f7b69bc88c36fa7f6ee137d7e7ed9776266642f2d2fb7cbf2

See more details on using hashes here.

Provenance

The following attestation bundles were made for notebookx_py-0.1.7-cp38-abi3-macosx_11_0_arm64.whl:

Publisher: release.yml on lukastk/notebookx

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

File details

Details for the file notebookx_py-0.1.7-cp38-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for notebookx_py-0.1.7-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 9ca82154c3770cfe622a2c6404769c70db0e973874cb62f28a36552f06ebd308
MD5 c1c688811df0546f1ef30926962b9ba8
BLAKE2b-256 fca78c9980f3c00ca57671375b4cff10a540bcd2acd8309b2cd072e7d24ea80b

See more details on using hashes here.

Provenance

The following attestation bundles were made for notebookx_py-0.1.7-cp38-abi3-macosx_10_12_x86_64.whl:

Publisher: release.yml on lukastk/notebookx

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