Notebook Utilities

Functions to help with processing of notebooks. Most come from nbdev

class NotebookCell

<source>

(index: int, cell: dict)

A cell for a Jupyter Notebook

set_source

<source>

(source: list)

Parameters:

  • source (list) – The source of the cell as a list of strings

Sets the source attribute of the cell as a string and removes parsed directives

nbquarto.notebook.dict2notebook

<source>

(d: dict = None, **kwargs)

Parameters:

  • d (dict, optional, defaults to None) – A dictionary to convert

Converts dictionary d to an AttributeDictionary

nbquarto.notebook.read_notebook

<source>

(path: str)

Parameters:

  • path (str) – The path to the Jupyter Notebook

Reads a Jupyter Notebook from a filepath

nbquarto.notebook.write_notebook

<source>

(notebook: AttributeDictionary, path: str)

Parameters:

  • notebook (AttributeDictionary) – An object representing all the cells in a Jupyter Notebook
  • path (str) – The path to the Jupyter Notebook

Writes the contents of notebook to path

nbquarto.notebook.new_notebook

<source>

(cells: list = [], metadata: dict = {}, nbformat: int = 4, nbformat_minor: int = 5)

Parameters:

  • cells (list of NotebookCell, optional, defaults to []) – A list of cells to make up the notebook
  • metadata (dict, optional, defaults to {}) – Metadata for the notebook
  • nbformat (int, optional, defaults to 4) – The nbformat of the notebook
  • nbformat_minor (int, optional, defaults to 5) – The minor nbformat version of the notebook

Creates a new empty notebook

nbquarto.notebook.make_cell

<source>

(text: str, cell_type: str = 'code', **kwargs)

Parameters:

  • text (str) – The source code for the cell
  • cell_type (str, optional, defaults to “code”) – The type of cell to make, must be one of “code”, “markdown”, or “raw” kwargs – Additional arguments to pass to the cell, such as metadata

Makes a blank notebook cell