Info Command Examples¶
Practical examples for using nbctl info to analyze notebooks.
Basic Usage¶
Get Full Analysis¶
Display complete notebook information:
Output:
Notebook Information: analysis.ipynb
Basic Statistics:
- Total cells: 25
- Code cells: 18
- Markdown cells: 6
- Raw cells: 1
- File size: 145.2 KB
Code Metrics:
- Total lines of code: 234
- Average lines per cell: 13.0
- Empty code cells: 2
- Code complexity: Medium
Dependencies:
- numpy
- pandas
- matplotlib.pyplot
- sklearn.model_selection
Show Only Code Metrics¶
Show Only Imports¶
Analysis Examples¶
Analyze Before Splitting¶
Check if notebook should be split into modules:
If complexity is "Very High", consider using ml-split.
Check Dependencies¶
List all notebook dependencies:
Batch Analysis¶
Analyze all notebooks in a directory:
Compare Notebooks¶
Compare statistics of multiple notebooks:
echo "Notebook,Cells,Code Lines,Complexity"
for nb in *.ipynb; do
info=$(nbctl info "$nb" --code-metrics)
# Parse and format as CSV
echo "$nb,$info"
done > notebook-stats.csv
Find Large Notebooks¶
Find notebooks with many cells:
for nb in *.ipynb; do
cells=$(nbctl info "$nb" | grep "Total cells" | awk '{print $3}')
if [ "$cells" -gt 50 ]; then
echo "$nb has $cells cells (consider splitting)"
fi
done
Track Notebook Growth¶
Monitor notebook size over time:
#!/bin/bash
# track-size.sh
nb="$1"
date=$(date +%Y-%m-%d)
cells=$(nbctl info "$nb" | grep "Total cells" | awk '{print $3}')
lines=$(nbctl info "$nb" | grep "lines of code" | awk '{print $5}')
echo "$date,$cells,$lines" >> notebook-growth.csv
CI/CD Examples¶
Enforce Notebook Size Limits¶
#!/bin/bash
# Fail CI if notebook is too large
max_cells=100
for nb in *.ipynb; do
cells=$(nbctl info "$nb" | grep "Total cells" | awk '{print $3}')
if [ "$cells" -gt "$max_cells" ]; then
echo "ERROR: $nb has $cells cells (max: $max_cells)"
exit 1
fi
done
echo "All notebooks within size limits"
Generate Notebook Report¶
#!/bin/bash
# Generate HTML report of all notebooks
echo "<html><body><h1>Notebook Report</h1>" > report.html
for nb in *.ipynb; do
echo "<h2>$nb</h2><pre>" >> report.html
nbctl info "$nb" >> report.html
echo "</pre>" >> report.html
done
echo "</body></html>" >> report.html
Tips & Best Practices¶
1. Regular Analysis¶
Check notebooks regularly for growth:
2. Before Refactoring¶
Always analyze before splitting:
3. Document Dependencies¶
Export dependencies for documentation:
Related Examples¶
- ML-Split Examples - Split large notebooks
- Lint Examples - Check code quality
- Clean Examples - Clean before analysis