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
Rust
Add to your Cargo.toml:
[]
= "0.1"
CLI
Usage
Python
# Load a notebook
=
# Convert to percent format
# Or get as string
=
# Clean notebook for version control
=
# Convenience functions
CLI (nbx)
# Convert ipynb to percent format
# Convert percent to ipynb
# Clean a notebook (remove outputs)
# Clean in place
# Use stdin/stdout
|
Rust
use ;
// Parse from file
let content = read_to_string?;
let notebook = Ipynb.parse?;
// Convert to percent format
let percent = Percent.serialize?;
// Clean notebook
let options = CleanOptions ;
let clean = notebook.clean;
// Save to file
let output = Ipynb.serialize?;
write?;
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
=
# Strip everything (including outputs)
=
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
# Build Rust library and CLI
# Build Python package
Running tests
# Rust tests
# Python tests
License
MIT
Acknowledgements
Example notebooks in nb_format_examples/ are from the Jupytext demo.