module documentation

A collection of helper functions to integrate with Jupyter/IPython and CLI commands for working with Kedro catalog.

Function convert_notebook Convert selected or all notebooks found in a Kedro project to Kedro code, by exporting code from the appropriately-tagged cells: Cells tagged as node will be copied over to a Python file matching the name of the notebook, under ...
Function jupyter Open Jupyter Notebook / Lab with project specific variables loaded, or convert notebooks into Kedro code.
Function jupyter_cli Undocumented
Function jupyter_lab Open Jupyter Lab with project specific variables loaded.
Function jupyter_notebook Open Jupyter Notebook with project specific variables loaded.
Constant CONVERT_ALL_HELP Undocumented
Constant OVERWRITE_HELP Undocumented
Function _append_source_code Undocumented
Function _create_kernel Creates an IPython kernel for the kedro project. If one with the same kernel_name exists already it will be replaced.
Function _export_nodes Copy code from Jupyter cells into nodes in src/<package_name>/nodes/, under filename with same name as notebook.
@command_with_verbosity(jupyter, 'convert')
@click.option('--all', '-a', 'all_flag', is_flag=True, help=CONVERT_ALL_HELP)
@click.option('-y', 'overwrite_flag', is_flag=True, help=OVERWRITE_HELP)
@click.argument('filepath', type=click.Path(exists=True, dir_okay=False, resolve_path=True), required=False, nargs=-1)
@env_option
@click.pass_obj
def convert_notebook(metadata: ProjectMetadata, all_flag, overwrite_flag, filepath, env, **kwargs): (source)

Convert selected or all notebooks found in a Kedro project to Kedro code, by exporting code from the appropriately-tagged cells: Cells tagged as node will be copied over to a Python file matching the name of the notebook, under <source_dir>/<package_name>/nodes. Note: Make sure your notebooks have unique names! FILEPATH: Path(s) to exact notebook file(s) to be converted. Both relative and absolute paths are accepted. Should not be provided if --all flag is already present. (DEPRECATED)

@jupyter_cli.group()
def jupyter(): (source)

Open Jupyter Notebook / Lab with project specific variables loaded, or convert notebooks into Kedro code.

@click.group(name='Kedro')
def jupyter_cli(): (source)

Undocumented

@forward_command(jupyter, 'lab', forward_help=True)
@env_option
@click.pass_obj
def jupyter_lab(metadata: ProjectMetadata, env, args, **kwargs): (source)

Open Jupyter Lab with project specific variables loaded.

@forward_command(jupyter, 'notebook', forward_help=True)
@env_option
@click.pass_obj
def jupyter_notebook(metadata: ProjectMetadata, env, args, **kwargs): (source)

Open Jupyter Notebook with project specific variables loaded.

CONVERT_ALL_HELP: str = (source)

Undocumented

Value
'''Extract the nodes from all notebooks in the Kedro project directory,
including sub-folders.'''
OVERWRITE_HELP: str = (source)

Undocumented

Value
'''If Python file already exists for the equivalent notebook,
overwrite its contents.'''
def _append_source_code(cell: Dict[str, Any], path: Path): (source)

Undocumented

def _create_kernel(kernel_name: str, display_name: str): (source)

Creates an IPython kernel for the kedro project. If one with the same kernel_name exists already it will be replaced.

Installs the default IPython kernel (which points towards sys.executable) and customises it to make the launch command load the kedro extension. This is equivalent to the method recommended for creating a custom IPython kernel on the CLI: https://ipython.readthedocs.io/en/stable/install/kernel_install.html.

On linux this creates a directory ~/.local/share/jupyter/kernels/{kernel_name} containing kernel.json, logo-32x32.png, logo-64x64.png and logo-svg.svg. An example kernel.json looks as follows:

{
"argv": [
"/Users/antony_milne/miniconda3/envs/spaceflights/bin/python", "-m", "ipykernel_launcher", "-f", "{connection_file}", "--ext", "kedro.ipython"

], "display_name": "Kedro (spaceflights)", "language": "python", "metadata": {

"debugger": false

}

}

Parameters
kernel_name:strName of the kernel to create.
display_name:strKernel name as it is displayed in the UI.
Raises
KedroCliErrorWhen kernel cannot be setup.
def _export_nodes(filepath: Path, output_path: Path): (source)

Copy code from Jupyter cells into nodes in src/<package_name>/nodes/, under filename with same name as notebook.

Parameters
filepath:PathPath to Jupyter notebook file
output_path:PathPath where notebook cells' source code will be exported
Raises
KedroCliErrorWhen provided a filepath that cannot be read as a Jupyer notebook and loaded into json format.