Adding Tools to nbtoolbelt

nbtoolbelt is set up in a modular way, so that it easy to add new tools.

The base class Tool is defined in toolbaseapp.py.

Every tool extends Tool, and thereby inherits the common code for argument parsing, looping over all argmuments, reading and writing of notebooks. The tool only needs to override

  • the constructor __init__() [it must call super() at the beginning],

and following hook methods:

  • config_tool_args_parsing() to configure the parser for tool-specific arguments [optional; no need to call super()]

  • check_and_adjust_arguments() to check and adjust tool-specific arguments, e.g. to enforce consistence [optional; no need to call super()]

  • print_tool_args() to print tool-specific arguments, called in verbose mode [optional; no need to call super()]

  • process_nb() to process one notebook, returning produced notebooks [must NOT call super()]

  • process_collected_data() to process data collected for all notebook [must call super() at the beginning]

For a simple example, see the head tool.