dietnb
dietnb addresses the issue of large .ipynb file sizes caused by matplotlib figures being embedded as Base64 data. By saving plots as external PNG files and embedding only image links, dietnb keeps your notebooks lightweight and improves manageability.
Key Features
- Minimized Notebook Size: Significantly reduces
.ipynbfile bulk by storingmatplotlibfigures as external PNG files. - One-Click Image Copy: Every plot includes an automatically added 📋 copy button for instant clipboard access.
- Automatic Image Folder Management: Creates and manages image storage directories (e.g.,
[NotebookFileName]_dietnb_imgs) relative to the notebook's location. When you move the notebook and the folder together, the<img>tags continue to work because only relative paths are stored. If detection fails, the defaultdietnb_imgsfolder in the working directory is used. - Automatic Image Updates: Registers per-directory/per-cell execution counts to replace old PNGs when a cell reruns, preventing stale images from piling up.
- Image Cleanup Function: The
dietnb.clean_unused()function consults the execution registry to remove unreferenced image files from the active session. - Simple Auto-Activation: The
dietnb installcommand configuresdietnbto activate automatically when IPython and Jupyter environments start.
Installation and Activation
1. Install the dietnb package
Execute the following command in your terminal:
pip install dietnb
2. Choose an Activation Method
A. Automatic Activation (Recommended) Run the following command in your terminal once:
dietnb install
This creates a startup script (00-dietnb.py) in your IPython profile directory.
After restarting your Jupyter kernel, dietnb will be activated automatically. Images will be saved to a folder based on the notebook's path or to the default dietnb_imgs directory.
To disable automatic activation later, run:
dietnb uninstall
This removes the startup script.
B. Manual Activation (Per Notebook)
If you prefer to use dietnb only for specific notebooks or do not want automatic activation, add the following code at the top of your notebook to activate it manually:
import dietnb
dietnb.activate()
Example Usage
With dietnb active, use your matplotlib code as usual.
import matplotlib.pyplot as plt
import numpy as np
# Create a plot
x = np.linspace(0, 10, 100)
plt.plot(x, np.sin(x), label='sin(x)')
plt.plot(x, np.cos(x), label='cos(x)')
plt.title("Trigonometric Functions")
plt.xlabel("X-axis")
plt.ylabel("Y-axis")
plt.legend()
plt.show() # On show(), the image is saved to a file, and a link is displayed in the notebook.
Generated images can be found in the [NotebookFileName]_dietnb_imgs folder alongside your notebook (with relative links), or in the dietnb_imgs folder.
Cleaning Unused Image Files
To remove image files that are no longer in use, execute the following function in a notebook cell:
import dietnb
dietnb.clean_unused()
License
MIT License. See LICENSE for details.
Release files for dietnb 0.2.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| dietnb-0.2.4.tar.gz | 16.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| dietnb-0.2.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size:29.6 kB
Release files / dietnb-0.2.4.tar.gz
| Download URL | dietnb-0.2.4.tar.gz |
|---|---|
| Size | 16.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1a080f96cf601a3cfb31830e3470a4b3ddfc20f183070094789278e744bcdcec
|
|
BLAKE2b-256 checksum How to use checksums |
7797a9d4529e634742b602e1e850578b18f5fec51e66b79e91ac55fc8117e78a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.7
|
Release files / dietnb-0.2.4-py3-none-any.whl
| Download URL | dietnb-0.2.4-py3-none-any.whl |
|---|---|
| Size | 13.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f095c326d7b2c991126b6992e9344fa939b052aca8c05f83a8962717441c20b8
|
|
BLAKE2b-256 checksum How to use checksums |
d9dfcacb840cdf2b97df584561804fb33f44d144088bcb28d6c10c938dd03c65
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.7
|