Notebook Dump ============= ``dump`` shows notebook and cell information, and cell sources of Jupyter notebooks in a compact way on stdout (more compact than ``nbshow`` of the ``nbdime`` package). Which elements of a notebook are dumped can be selected through options. The output format can also be adjusted via options. Options ------- The following options are supported by ``dump``: .. code-block:: none -g, --notebook-info, -G, --no-notebook-info show global notebook information (default: True) -c, --cell-info, -C, --no-cell-info show cell information (default: True) -s, --sources, -S, --no-sources show cell sources (default: True) -t TYPES, --cell-types TYPES comma-separated list of cell types to dump (default: 'markdown,code,raw') -p STRING, --prefix STRING pre/postfix for information lines (default: '=====') -i INT, --indent INT indentation level for source lines (default: 2) -l, --line-numbers, -L, --no-line-numbers show source line numbers (default: False) -e INT, --cell-spacing INT number of empty lines between cells (default: 0) Examples -------- A dump of notebook ``short.ipynb`` in verbose mode: .. code-block:: bash $ nbtb dump -v short.ipynb Options for nbdump: Dump notebook info: True Dump cell info: True Dump cell sources: True Dump cell types: markdown,code,raw Prefix for information lines: ===== Source line indentation level: 2 Show source line numbers: False Cell spacing lines: 0 :::::::::::::: short.ipynb :::::::::::::: ===== nbformat: 4.2 | kernel: python3 | language: python 3.6.1 ===== ===== cells: 2 ===== ===== cell 0: markdown | metadata: collapsed ===== # Short Notebook for Testing * **Bold** * _Italic_ * `Typewriter` * $e^{\pi i} + 1 = 0$ ===== cell 1: code | outputs: 2 ===== print(6 * 7) 1 + 1 Notebooks processed: 1 A dump that shows notebook and cell information only (no sources): .. code-block:: bash $ nbtb dump -S test.ipynb ===== nbformat: 4.2 | kernel: python3 | language: python 3.6.1 ===== ===== cells: 19 | metadata: celltoolbar,toc ===== ===== cell 0: markdown ===== ===== cell 1: markdown ===== ===== cell 2: markdown ===== ===== cell 3: code | metadata: collapsed | outputs: 1 ===== ===== cell 4: code | metadata: collapsed | outputs: 1 ===== ===== cell 5: code | metadata: collapsed | outputs: 1 ===== ===== cell 6: code | outputs: 1 ===== ===== cell 7: code | outputs: 2 ===== ===== cell 8: code | outputs: 2 ===== ===== cell 9: markdown | tags: YourTurn ===== ===== cell 10: code | metadata: scrolled | outputs: 1 ===== ===== cell 11: code | metadata: collapsed ===== ===== cell 12: code | metadata: scrolled | tags: YourTurn | outputs: 1 ===== ===== cell 13: code | metadata: collapsed ===== ===== cell 14: markdown ===== ===== cell 15: code | tags: YourTurn,Test | outputs: 2 ===== ===== cell 16: code | metadata: collapsed ===== ===== cell 17: markdown | attachments: 1 ===== ===== cell 18: markdown ===== A dump of MarkDown sources only, without indentation: .. code-block:: bash $ nbtb dump -G -C -t markdown -i 0 test.ipynb # Test Notebook This is a notebook for testing purposes; in particular, for testing the various scripts. It has a few formatted _MarkDown_ cells. And some simple code cells, with various execution effects; some (not only the last) has an error. Various tags have been set. ## A Section Demonstrating **bold face**. This one has a $\LaTeX$ formula: $e^{\pi i} + 1 = 0$. Print the first one hundred numbers, their squares, and their cubes. Produce a line plot of `df`. ![jupyter.png](attachment:jupyter.png) Last cell with more than five lines. A dump of code cells without global notebook information, without indentation, with cell spacing 1, and info prefix ``#####``: .. code-block:: bash $ nbtb dump -G -t code -i 0 -l 1 -p '#####' test.ipynb ##### cell 3: code | metadata: collapsed | outputs: 1 ##### print([i ** 3 for i in range(6)]) # output as stream in stdout ##### cell 4: code | metadata: collapsed | outputs: 1 ##### # NameError undefined ##### cell 5: code | metadata: collapsed | outputs: 1 ##### 6 * 7 # output as execution result ##### cell 6: code | outputs: 1 ##### 6 / 0 # ZeroDivisionError ##### cell 7: code | outputs: 2 ##### # stdout and execution result print('Hello, World!') 'Thanks' ##### cell 8: code | outputs: 2 ##### import sys print('Message on stdout') print('Message on stderr', file=sys.stderr) ##### cell 10: code | metadata: scrolled | outputs: 1 ##### for i in range(100): # output as stream in stdout print(i, i ** 2, i ** 3) ##### cell 11: code | metadata: collapsed ##### import pandas as pd ##### cell 12: code | metadata: scrolled | tags: YourTurn | outputs: 1 ##### df = pd.DataFrame([3, 1, 4, 1, 5, 9]) df ##### cell 13: code | metadata: collapsed ##### # import seaborn # commented out to avoid depencency on seaborn # %matplotlib inline # commented out to avoid dependcy on matplotlib ##### cell 15: code | tags: YourTurn,Test | outputs: 2 ##### # df.plot(kind='line') # commented out to avoid dependency on matplotlib ##### cell 16: code | metadata: collapsed ##### print(42) # output to be deleted afterwards A dump of a notebook with source line numbers: .. code-block:: bash $ nbtb dump -l short.ipynb ===== nbformat: 4.2 | kernel: python3 | language: python 3.6.1 ===== ===== cells: 2 ===== ===== cell 0: markdown | metadata: collapsed ===== 1| # Short Notebook for Testing 2| 3| * **Bold** 4| * _Italic_ 5| * `Typewriter` 6| * $e^{\pi i} + 1 = 0$ ===== cell 1: code | outputs: 2 ===== 1| print(6 * 7) 2| 1 + 1