12 releases (breaking)

0.10.0 Jan 9, 2025
0.9.0 Dec 2, 2024
0.8.0 Nov 28, 2024

#699 in Parser implementations

Download history 293/week @ 2024-10-23 2384/week @ 2024-10-30 2016/week @ 2024-11-06 3154/week @ 2024-11-13 3140/week @ 2024-11-20 2912/week @ 2024-11-27 2681/week @ 2024-12-04 2365/week @ 2024-12-11 1836/week @ 2024-12-18 1291/week @ 2024-12-25 2490/week @ 2025-01-01 3448/week @ 2025-01-08 2255/week @ 2025-01-15 2007/week @ 2025-01-22

10,371 downloads per month

BSD-3-Clause

290KB
3K SLoC

nbformat - Jupyter Notebook Format in Rust

This crate provides functionality to parse and work with Jupyter Notebook files in Rust.

Usage

Add this to your Cargo.toml:

[dependencies]
nbformat = "0.1.0"

Here's a basic example of how to use parse_notebook:

use nbformat::{parse_notebook, Notebook};
use std::fs;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Read the notebook file
    let notebook_json = fs::read_to_string("Untitled1337.ipynb")?;

    // Parse the notebook
    let notebook = parse_notebook(&notebook_json)?;

    // Work with the parsed notebook
    match notebook {
        Notebook::V4(nb) => {
            println!("Notebook version: {}.{}", nb.nbformat, nb.nbformat_minor);
            println!("Number of cells: {}", nb.cells.len());
            // Access other notebook properties...
        }
        Notebook::Legacy(nb) => {
            println!("Legacy notebook version: {}.{}", nb.nbformat, nb.nbformat_minor);
            println!("Number of cells: {}", nb.cells.len());
            // Access other notebook properties...
        }
    }

    Ok(())
}

At present, this crate supports v4.5 notebooks via Notebook::V4 and v4.1-v4.4 via Notebook::Legacy. v4.5 have some more hard constraints on CellIDs being required, only allowing certain characters, and not having duplicates. Converting from a v4.1-v4.4 notebook to a v4.5 notebook requires modifying the notebook to include Cell IDs.

ROADMAP

  • Serialize and Deserialize v4.1-v4.5 notebooks into rust structures
  • Test operations on a suite of notebooks from Python nbformat
  • Add support for upconverting v3 notebooks to v4
  • Add support for upconverting v4.1-v4.4 notebooks to v4.5
  • Break out types to be shared between runtimelib's Media setup and the notebook crate

Dependencies

~2.7–4MB
~76K SLoC