nbtoolbelt
raw JSON → 2024.7.2 verified Fri May 01 auth: no python
nbtoolbelt (version 2024.7.2) provides tools to work with Jupyter notebooks programmatically. It supports tasks like merging, splitting, executing, and converting notebooks. Released as a companion to jupyter-releaser, with regular updates.
pip install nbtoolbelt Common errors
error AttributeError: module 'nbtoolbelt' has no attribute 'Notebook' ↓
cause nbtoolbelt was installed incorrectly or a different package with same name is installed.
fix
Run
pip install nbtoolbelt --upgrade and verify import: from nbtoolbelt import Notebook. error ModuleNotFoundError: No module named 'nbtoolbelt' ↓
cause Package not installed or virtual environment not activated.
fix
Install with
pip install nbtoolbelt and ensure your environment is correct. Warnings
breaking The library uses calendar versioning (YYYY.MM.MICRO). Major changes can occur between minor versions; pin your dependency (nbtoolbelt>=2024.7,<2025) to avoid unexpected breaks. ↓
fix Pin to a specific major version range in requirements.txt.
gotcha Notebook.from_path() does not verify the notebook file is valid JSON. Invalid notebooks cause cryptic errors during cell access. ↓
fix Wrap in try/except or validate JSON beforehand.
deprecated The old API using nbformat as a dependency directly may be removed. Use Notebook objects instead. ↓
fix Migrate to nbtoolbelt's Notebook API.
Imports
- Notebook wrong
from nbtoolbelt.notebook import Notebookcorrectfrom nbtoolbelt import Notebook - merge_notebooks
from nbtoolbelt import merge_notebooks
Quickstart
from nbtoolbelt import Notebook
nb = Notebook.from_path('example.ipynb')
print(nb.cells[0].source)