scistag.jupystag.Notebook

class Notebook(source)[source]

Bases: object

Jupyter notebook helper class.

Is able to load a notebook, provide statistics about it and clean it, for example to use it in a pre-commit hook.

Parameters

source (str) – The notebooks filename

Methods

clean

Removes temporary data from the notebook such as outputs and execution counters.

parse

Parses the notebook to receive some details about it

save

Saves the notebook to disk

Attributes

__dict__

__doc__

__module__

__weakref__

list of weak references to the object (if defined)

name

The origin filename

notebook

The notebook data

cell_count

Total cell count

mark_down_cells

Count of markdown cells

code_cells

Count of code cells

output_data_size

The total size of the output data

is_dirty

Defines if the Notebook is dirty, e.g.

clean(clear_outputs=True, clear_metadata=True, clear_counters=True)[source]

Removes temporary data from the notebook such as outputs and execution counters.

Parameters
  • clear_outputs – Clear all outputs?

  • clear_metadata – Clear metadata?

  • clear_counters – Clear counters?

parse()[source]

Parses the notebook to receive some details about it

save(filename)[source]

Saves the notebook to disk

Parameters

filename (str) – The target filename

cell_count

Total cell count

code_cells

Count of code cells

is_dirty

Defines if the Notebook is dirty, e.g. has a counter of outputs

mark_down_cells

Count of markdown cells

name

The origin filename

notebook

The notebook data

output_data_size

The total size of the output data