scrapbook package¶
Submodules¶
scrapbook.api module¶
api.py
Provides the base API calls for scrapbook
-
scrapbook.api.
frame
(name, obj)¶ Display an object with the reference name in a retrievable manner.
Parameters:
-
scrapbook.api.
glue
(name, scrap, storage=None)¶ Record a value in the output notebook when a cell is executed.
The recorded value can be retrieved during later inspection of the output notebook.
Example
record provides a handy way for data to be stored with a notebook to be used later:
sb.glue("hello", "world") sb.glue("number", 123) sb.glue("some_list", [1, 3, 5]) sb.glue("some_dict", {"a": 1, "b": 2}) sb.glue("non_json", df, 'arrow')
scrapbook can be used later to recover recorded values by reading the output notebook
nb = sb.read_notebook(‘notebook.ipynb’) nb.scrapsParameters:
scrapbook.exceptions module¶
-
exception
scrapbook.exceptions.
ScrapbookException
¶ Bases:
ValueError
Raised when an exception is encountered when operating on a notebook.
scrapbook.log module¶
scrapbook.models module¶
notebook.py
Provides the Notebook wrapper objects for scrapbook
-
class
scrapbook.models.
Notebook
(node_or_path, translators=None)¶ Bases:
object
Representation of a notebook.
Parameters: node (nbformat.NotebookNode, str) – a notebook object, or a path to a notebook object -
cell_timing
¶ list – a list of cell execution timings in cell order
-
directory
¶ str – directory name at the specified path
-
execution_counts
¶ list – a list of cell execution counts in cell order
-
filename
¶ str – filename found a the specified path
-
frames
¶ dict – a dictionary of the notebook display outputs.
-
papermill_dataframe
¶ pandas dataframe – dataframe of notebook parameters and cell scraps
-
papermill_metrics
¶ pandas dataframe – dataframe of cell execution counts and times
-
parameter_dataframe
¶ pandas dataframe – dataframe of notebook parameters
-
parameters
¶ dict – parameters stored in the notebook metadata
-
reframe
(name, raise_error=True)¶ Display output from a named source of the notebook.
Parameters:
-
scrap_dataframe
¶ pandas dataframe – dataframe of cell scraps
-
scraps
¶ dict – a dictionary of data found in the notebook
-
-
class
scrapbook.models.
Scrapbook
¶ Bases:
collections.abc.MutableMapping
Represents a collection of notebooks as a dictionary of notebooks.
-
combined_frames
¶ dict – a dictionary of the merged notebook display outputs.
-
combined_scraps
¶ dict – a dictionary of the merged notebook scraps.
-
display
(frames=None, keys=None, header=True, raise_error=False)¶ Display frames as markdown structed outputs.
Parameters: - frames (str or iterable[str] (optional)) – the frames to display as outputs
- keys (str or iterable[str] (optional)) – notebook keys to use in framing the scrapbook displays
- header (bool (default: True)) – indicator for if the frames should have headers
- raise_error (bool (default: False)) – flag for if errors should be raised on missing output_names
-
frames
¶ dict – a dictionary of the notebook display outputs by key.
-
papermill_dataframe
¶ list – a list of dataframes from a collection of notebooks
-
papermill_metrics
¶ list – a list of metrics from a collection of notebooks
-
scraps
¶ dict – a dictionary of the notebook scraps by key.
-
sorted_notebooks
¶ list – a list of the notebooks in key order.
-
-
scrapbook.models.
merge_dicts
(dicts)¶
scrapbook.translators module¶
notebook.py
Provides the translators for various data types to be persistable
-
class
scrapbook.translators.
DataTranslatorRegistry
¶ Bases:
collections.abc.MutableMapping
-
deregister
(storage_type)¶ Removes a particular translator from the registry
Parameters: storage_type (str) – Name of the mime subtype parsed by the translator.
-
load_data
(storage_type, scrap)¶ Finds the register for the given storage_type and loads the scrap into a JSON or string object.
Parameters: - storage_type (str) – Name of the mime subtype parsed by the translator.
- scrap (obj) – Object to be converted from JSON or string format to the original value.
-
register
(storage_type, translator)¶ Registers a new storage_type to a particular translator
Parameters: - storage_type (str) – Name of the mime subtype parsed by the translator.
- translator (obj) – The object which implements the required functions.
-
reset
()¶ Resets the registry to have no translators.
-
translate_data
(storage_type, scrap)¶ Finds the register for the given storage_type and translates the scrap into an object of the translator output type.
Parameters: - storage_type (str) – Name of the mime subtype parsed by the translator.
- scrap (obj) – Object to be converted to JSON or string format for storage in an output
-