Skip to content

Commit

Permalink
[KED-802] Allow users to run Kedro commands from Jupyter Notebooks (#166
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Lorena Bălan authored Aug 1, 2019
1 parent 2763f34 commit 0e453d0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions docs/source/04_user_guide/10_ipython.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,15 @@ With `context`, you can access the following variables and methods
- `tags`: An optional list of node tags which should be used to
filter the nodes of the ``Pipeline``. If specified, only the nodes
containing *any* of these tags will be added to the ``Pipeline``
- `runner`: An optional parameter specifying the runner _instance_ that you want to run
- `runner`: An optional parameter specifying the runner _instance_ that you want to run
the pipeline with
- `node_names`: An optional list of node names which should be used to
filter the nodes of the ``Pipeline``. If specified, only the nodes
with these names will be run.
- `from_nodes`: An optional list of node names which should be used as a
starting point of the new ``Pipeline``.
- `to_nodes`: An optional list of node names which should be used as an
end point of the new ``Pipeline``.

## Loading `DataCatalog` in IPython

Expand Down Expand Up @@ -87,12 +94,11 @@ jupyter notebook
And then add the following code in a notebook cell:

```python
from pathlib import Path
from kedro.context import load_context
import os

proj_path = os.getcwd()
context_class = load_context(proj_path)
context = context_class(proj_path)
proj_path = Path.cwd()
context = load_context(proj_path)
df = context.io.load("example_iris_data")
df.head()
```
Expand All @@ -105,6 +111,21 @@ You should be able to see the first 5 rows of the loaded dataset as follows:
If you see an error message in a notebook cell, you can see what went wrong by using `print(startup_error)`, where `startup_error` is available as a variable in Python.
<br/>When you add new datasets to your `catalog.yml` file you need to reload Kedro's session by running `%reload_kedro` in your cell.

You can also run your Kedro pipeline by using `context.run()`, which provides the same functionality as the CLI command `kedro run`. You can try this out by typing the following in a notebook cell:

```python
from pathlib import Path
from kedro.context import load_context

proj_path = Path.cwd()
context = load_context(proj_path)
context.run()
```

You should be able to see the logging output as follows:

![](images/jupyter-notebook-ch10-3.png)

## Extras

There are optional extra scripts that can help improve your Kedro experience for certain use cases. Those are not essential for using Kedro CLI or library components.
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0e453d0

Please sign in to comment.