| Crates.io | nbformat |
| lib.rs | nbformat |
| version | 0.13.0 |
| created_at | 2024-10-27 20:53:50.588885+00 |
| updated_at | 2025-09-19 21:04:46.174503+00 |
| description | Parse Jupyter Notebooks |
| homepage | |
| repository | https://github.com/runtimed/runtimed |
| max_upload_size | |
| id | 1424957 |
| size | 512,462 |
This crate provides functionality to parse and work with Jupyter Notebook files in Rust.
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(¬ebook_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.