pip install nbhistory
from nbhistory.core import save_notebook_history save_notebook_history('tmp/my_history.ipynb')
Notebook history saved to tmp/my_history.ipynb
nbhistory only saves the execution history, markdown cells will not be saved.