reasons-to-kedro
━━━━━━━━━━━━━━━━

Date: November 1, 2020

There are many reasons that you should be using kedro. If you are on a team of Data Scientists/Data Engineers processing DataFrames from many data sources should be considering a pipeline framework. Kedro is a great option that provides many benefits for teams to collaborate, develop, and deploy data pipelines

[4m[38;2;248;248;242mWhat is Kedro[0m <[38;2;248;248;242m/what-is-kedro/[0m>

[1m[38;2;189;147;249mStarter Template[0m
[38;2;68;71;90m────────────────[0m

Kedro makes it super easy to get started with their cli that utilizes cookiecutter under the hood.

[38;2;248;248;242m[code][0m
  conda create -n my-new-project -y python=3.8
  kedro new
  kedro install
  kedro run

[4m[38;2;248;248;242mCreate New Kedro Project[0m <[38;2;248;248;242m/create-new-kedro-project/[0m>

[38;2;248;248;242m│ [0mread more about how to start your first kedro project here

[1m[38;2;189;147;249mCollaboration[0m
[38;2;68;71;90m─────────────[0m

Kedro provides many tools that help teams collaborate on a single codebase. While writing monolithic scripts it can be easy to pin yourself in a corner where it is difficult to have multiple people making changes to the notebook/script at the same time. Kedro helps guide your team to break your project down into small pieces that different members of the team can work on in parallel.

[1m[38;2;189;147;249m### sharable catalog[0m

Kedro makes it easy to collaborate with members who aren’t even working on the pipeline. I often see team members who want to investigate datasets from different points in the pipeline. Kedro makes it really easy for them to load it into python.

[1mfor python users[0m

Share catalog entries with folks doing EDA.

[38;2;248;248;242m[code][0m
  [38;2;248;248;242mcatalog[0m[38;2;255;121;198m.[0m[38;2;248;248;242mload[0m[38;2;248;248;242m([0m[38;2;241;250;140m'[0m[38;2;241;250;140mmain_table[0m[38;2;241;250;140m'[0m[38;2;248;248;242m)[0m

[1mfor non-python users[0m

For those who may not be using python, we can easily kick out a CSV version of that [38;2;189;147;249mmain_table[0m that they can get from s3 or your cloud storage solution of choice.

[38;2;248;248;242m[code][0m
  master_table:
    type: pandas.CSVDataSet
    filepath: s3://bucket/data/03_primary/master_table.csv
    layer: primary

[1mfor the SQL folks[0m

We aren’t even constrained to those who only use python or excel, we can kick out any kind of dataset that python can output. Kedro even comes with many DataSet types out of the box so that we don’t have to write any read/write code.

[38;2;248;248;242m[code][0m
  master_table:
    type: SQLTableDataSet
    table_name: master_table
    credentials: postgres

[1m[38;2;189;147;249m### small nodes over monolithic scripts[0m

As I said before single notebooks/scripts are really hard to collaborate on. I have seen Data Engineers sitting idle waiting to get their changes manually added into the master notebook. When you find yourself in this situation, find a better solution. It’s time to break things down into individual modules and utilize a version control system that can automatically merge changes in.

Kedro encourages the use of [4m[38;2;248;248;242mgit[0m <[38;2;248;248;242m/glossary/git/[0m> version control and storing all node functions inside of modules while still making it really easy to load data into a notebook/shell and start trying out new things.

[1m[38;2;189;147;249mNo More read and write code[0m
[38;2;68;71;90m───────────────────────────[0m

As I said earlier kedro comes with datasets for the most popular output formats. It is also backed by a really amazing library called [38;2;189;147;249mfsspec[0m, this library makes the filesystem that you are storing agnostic to how you write to it. This means that the kedro library utilizes [38;2;189;147;249mfsspec[0m under the hood and writes to the file as if it was to disk, but based on the prefix to the file it may actually be writing to the local filesystem, gcp, azure blob, or s3.

[1mcustom DataSets[0m

If kedro does not have a [38;2;189;147;249mDataSet[0m for the format that you need to read or write you can easily create your own custom [38;2;189;147;249mDataSet[0m all you need to do is inherit from [38;2;189;147;249mkedro.io.AbstractDataSet[0m and create methods for [38;2;189;147;249m__init__[0m, [38;2;189;147;249m_load[0m, [38;2;189;147;249m_save[0m, [38;2;189;147;249m_exists[0m, and [38;2;189;147;249m_describe[0m.

Check out this example from their docs. I removed the docstrings for brevity, you can see the entire [38;2;189;147;249mDataSet[0m in their [4m[38;2;248;248;242mdocs[0m <[38;2;248;248;242mhttps://kedro.readthedocs.io/en/0.15.2/03_tutorial/03_set_up_data.html?highlight=custom%20dataset#creating-custom-datasets[0m>.

[38;2;248;248;242m│ [0mThe complete example all in one was only available in an older version, more up to date [4m[38;2;248;248;242mdocs[0m <[38;2;248;248;242mhttps://kedro.readthedocs.io/en/0.16.6/07_extend_kedro/01_custom_datasets.html?highlight=custom%20dataset[0m> have a good writeup that walks through everything separately.

[38;2;248;248;242m[code][0m
  [38;2;248;248;242mfrom[0m[38;2;248;248;242m [0m[38;2;248;248;242mos[0m[38;2;255;121;198m.[0m[38;2;248;248;242mpath[0m[38;2;248;248;242m [0m[38;2;248;248;242mimport[0m[38;2;248;248;242m [0m[38;2;248;248;242misfile[0m[38;2;248;248;242m[0m
  [38;2;248;248;242mfrom[0m[38;2;248;248;242m [0m[38;2;248;248;242mtyping[0m[38;2;248;248;242m [0m[38;2;248;248;242mimport[0m[38;2;248;248;242m [0m[38;2;248;248;242mAny[0m[38;2;248;248;242m,[0m[38;2;248;248;242m [0m[38;2;248;248;242mUnion[0m[38;2;248;248;242m,[0m[38;2;248;248;242m [0m[38;2;248;248;242mDict[0m[38;2;248;248;242m[0m
  [38;2;248;248;242m[0m
  [38;2;248;248;242mimport[0m[38;2;248;248;242m [0m[38;2;248;248;242mpandas[0m[38;2;248;248;242m [0m[38;2;248;248;242mas[0m[38;2;248;248;242m [0m[38;2;248;248;242mpd[0m[38;2;248;248;242m[0m
  [38;2;248;248;242m[0m
  [38;2;248;248;242mfrom[0m[38;2;248;248;242m [0m[38;2;248;248;242mkedro[0m[38;2;255;121;198m.[0m[38;2;248;248;242mio[0m[38;2;248;248;242m [0m[38;2;248;248;242mimport[0m[38;2;248;248;242m [0m[38;2;248;248;242mAbstractDataSet[0m[38;2;248;248;242m[0m
  [38;2;248;248;242m[0m
  [38;2;255;121;198mclass[0m[38;2;248;248;242m [0m[38;2;248;248;242mExcelLocalDataSet[0m[38;2;248;248;242m([0m[38;2;248;248;242mAbstractDataSet[0m[38;2;248;248;242m)[0m[38;2;248;248;242m:[0m[38;2;248;248;242m[0m
  [38;2;248;248;242m[0m
  [38;2;248;248;242m    [0m[38;2;255;121;198mdef[0m[38;2;248;248;242m [0m[38;2;80;250;123m_describe[0m[38;2;248;248;242m([0m[3m[38;2;248;248;242mself[0m[38;2;248;248;242m)[0m[38;2;248;248;242m [0m[38;2;255;121;198m-[0m[38;2;255;121;198m>[0m[38;2;248;248;242m [0m[38;2;248;248;242mDict[0m[38;2;248;248;242m[[0m[3m[38;2;139;233;253mstr[0m[38;2;248;248;242m,[0m[38;2;248;248;242m [0m[38;2;248;248;242mAny[0m[38;2;248;248;242m][0m[38;2;248;248;242m:[0m[38;2;248;248;242m[0m
  [38;2;248;248;242m        [0m[38;2;255;121;198mreturn[0m[38;2;248;248;242m [0m[38;2;248;248;242mdict[0m[38;2;248;248;242m([0m[38;2;248;248;242mfilepath[0m[38;2;255;121;198m=[0m[3m[38;2;248;248;242mself[0m[38;2;255;121;198m.[0m[38;2;248;248;242m_filepath[0m[38;2;248;248;242m,[0m[38;2;248;248;242m[0m
  [38;2;248;248;242m                    [0m[38;2;248;248;242mengine[0m[38;2;255;121;198m=[0m[3m[38;2;248;248;242mself[0m[38;2;255;121;198m.[0m[38;2;248;248;242m_engine[0m[38;2;248;248;242m,[0m[38;2;248;248;242m[0m
  [38;2;248;248;242m                    [0m[38;2;248;248;242mload_args[0m[38;2;255;121;198m=[0m[3m[38;2;248;248;242mself[0m[38;2;255;121;198m.[0m[38;2;248;248;242m_load_args[0m[38;2;248;248;242m,[0m[38;2;248;248;242m[0m
  [38;2;248;248;242m                    [0m[38;2;248;248;242msave_args[0m[38;2;255;121;198m=[0m[3m[38;2;248;248;242mself[0m[38;2;255;121;198m.[0m[38;2;248;248;242m_save_args[0m[38;2;248;248;242m)[0m[38;2;248;248;242m[0m
  [38;2;248;248;242m[0m
  [38;2;248;248;242m    [0m[38;2;255;121;198mdef[0m[38;2;248;248;242m [0m[38;2;80;250;123m__init__[0m[38;2;248;248;242m([0m[38;2;248;248;242m[0m
  [38;2;248;248;242m        [0m[3m[38;2;248;248;242mself[0m[38;2;248;248;242m,[0m[38;2;248;248;242m[0m
  [38;2;248;248;242m        [0m[38;2;248;248;242mfilepath[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[3m[38;2;139;233;253mstr[0m[38;2;248;248;242m,[0m[38;2;248;248;242m[0m
  [38;2;248;248;242m        [0m[38;2;248;248;242mengine[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[3m[38;2;139;233;253mstr[0m[38;2;248;248;242m [0m[38;2;255;121;198m=[0m[38;2;248;248;242m [0m[38;2;241;250;140m"[0m[38;2;241;250;140mxlsxwriter[0m[38;2;241;250;140m"[0m[38;2;248;248;242m,[0m[38;2;248;248;242m[0m
  [38;2;248;248;242m        [0m[38;2;248;248;242mload_args[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;248;248;242mDict[0m[38;2;248;248;242m[[0m[3m[38;2;139;233;253mstr[0m[38;2;248;248;242m,[0m[38;2;248;248;242m [0m[38;2;248;248;242mAny[0m[38;2;248;248;242m][0m[38;2;248;248;242m [0m[38;2;255;121;198m=[0m[38;2;248;248;242m [0m[38;2;248;248;242mNone[0m[38;2;248;248;242m,[0m[38;2;248;248;242m[0m
  [38;2;248;248;242m        [0m[38;2;248;248;242msave_args[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;248;248;242mDict[0m[38;2;248;248;242m[[0m[3m[38;2;139;233;253mstr[0m[38;2;248;248;242m,[0m[38;2;248;248;242m [0m[38;2;248;248;242mAny[0m[38;2;248;248;242m][0m[38;2;248;248;242m [0m[38;2;255;121;198m=[0m[38;2;248;248;242m [0m[38;2;248;248;242mNone[0m[38;2;248;248;242m,[0m[38;2;248;248;242m[0m
  [38;2;248;248;242m    [0m[38;2;248;248;242m)[0m[38;2;248;248;242m [0m[38;2;255;121;198m-[0m[38;2;255;121;198m>[0m[38;2;248;248;242m [0m[38;2;248;248;242mNone[0m[38;2;248;248;242m:[0m[38;2;248;248;242m[0m
  [38;2;248;248;242m[0m
  [38;2;248;248;242m        [0m[3m[38;2;248;248;242mself[0m[38;2;255;121;198m.[0m[38;2;248;248;242m_filepath[0m[38;2;248;248;242m [0m[38;2;255;121;198m=[0m[38;2;248;248;242m [0m[38;2;248;248;242mfilepath[0m[38;2;248;248;242m[0m
  [38;2;248;248;242m        [0m[38;2;248;248;242mdefault_save_args[0m[38;2;248;248;242m [0m[38;2;255;121;198m=[0m[38;2;248;248;242m [0m[38;2;248;248;242m{[0m[38;2;248;248;242m}[0m[38;2;248;248;242m[0m
  [38;2;248;248;242m        [0m[38;2;248;248;242mdefault_load_args[0m[38;2;248;248;242m [0m[38;2;255;121;198m=[0m[38;2;248;248;242m [0m[38;2;248;248;242m{[0m[38;2;241;250;140m"[0m[38;2;241;250;140mengine[0m[38;2;241;250;140m"[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;241;250;140m"[0m[38;2;241;250;140mxlrd[0m[38;2;241;250;140m"[0m[38;2;248;248;242m}[0m[38;2;248;248;242m[0m
  [38;2;248;248;242m[0m
  [38;2;248;248;242m        [0m[3m[38;2;248;248;242mself[0m[38;2;255;121;198m.[0m[38;2;248;248;242m_load_args[0m[38;2;248;248;242m [0m[38;2;255;121;198m=[0m[38;2;248;248;242m [0m[38;2;248;248;242m{[0m[38;2;255;121;198m*[0m[38;2;255;121;198m*[0m[38;2;248;248;242mdefault_load_args[0m[38;2;248;248;242m,[0m[38;2;248;248;242m [0m[38;2;255;121;198m*[0m[38;2;255;121;198m*[0m[38;2;248;248;242mload_args[0m[38;2;248;248;242m}[0m[38;2;248;248;242m [0m[38;2;248;248;242m\[0m
  [38;2;248;248;242m            [0m[38;2;255;121;198mif[0m[38;2;248;248;242m [0m[38;2;248;248;242mload_args[0m[38;2;248;248;242m [0m[38;2;248;248;242mis[0m[38;2;248;248;242m [0m[38;2;255;121;198mnot[0m[38;2;248;248;242m [0m[38;2;248;248;242mNone[0m[38;2;248;248;242m [0m[38;2;255;121;198melse[0m[38;2;248;248;242m [0m[38;2;248;248;242mdefault_load_args[0m[38;2;248;248;242m[0m
  [38;2;248;248;242m        [0m[3m[38;2;248;248;242mself[0m[38;2;255;121;198m.[0m[38;2;248;248;242m_save_args[0m[38;2;248;248;242m [0m[38;2;255;121;198m=[0m[38;2;248;248;242m [0m[38;2;248;248;242m{[0m[38;2;255;121;198m*[0m[38;2;255;121;198m*[0m[38;2;248;248;242mdefault_save_args[0m[38;2;248;248;242m,[0m[38;2;248;248;242m [0m[38;2;255;121;198m*[0m[38;2;255;121;198m*[0m[38;2;248;248;242msave_args[0m[38;2;248;248;242m}[0m[38;2;248;248;242m [0m[38;2;248;248;242m\[0m
  [38;2;248;248;242m            [0m[38;2;255;121;198mif[0m[38;2;248;248;242m [0m[38;2;248;248;242msave_args[0m[38;2;248;248;242m [0m[38;2;248;248;242mis[0m[38;2;248;248;242m [0m[38;2;255;121;198mnot[0m[38;2;248;248;242m [0m[38;2;248;248;242mNone[0m[38;2;248;248;242m [0m[38;2;255;121;198melse[0m[38;2;248;248;242m [0m[38;2;248;248;242mdefault_save_args[0m[38;2;248;248;242m[0m
  [38;2;248;248;242m        [0m[3m[38;2;248;248;242mself[0m[38;2;255;121;198m.[0m[38;2;248;248;242m_engine[0m[38;2;248;248;242m [0m[38;2;255;121;198m=[0m[38;2;248;248;242m [0m[38;2;248;248;242mengine[0m[38;2;248;248;242m[0m
  [38;2;248;248;242m[0m
  [38;2;248;248;242m    [0m[38;2;255;121;198mdef[0m[38;2;248;248;242m [0m[38;2;80;250;123m_load[0m[38;2;248;248;242m([0m[3m[38;2;248;248;242mself[0m[38;2;248;248;242m)[0m[38;2;248;248;242m [0m[38;2;255;121;198m-[0m[38;2;255;121;198m>[0m[38;2;248;248;242m [0m[38;2;248;248;242mUnion[0m[38;2;248;248;242m[[0m[38;2;248;248;242mpd[0m[38;2;255;121;198m.[0m[38;2;248;248;242mDataFrame[0m[38;2;248;248;242m,[0m[38;2;248;248;242m [0m[38;2;248;248;242mDict[0m[38;2;248;248;242m[[0m[3m[38;2;139;233;253mstr[0m[38;2;248;248;242m,[0m[38;2;248;248;242m [0m[38;2;248;248;242mpd[0m[38;2;255;121;198m.[0m[38;2;248;248;242mDataFrame[0m[38;2;248;248;242m][0m[38;2;248;248;242m][0m[38;2;248;248;242m:[0m[38;2;248;248;242m[0m
  [38;2;248;248;242m        [0m[38;2;255;121;198mreturn[0m[38;2;248;248;242m [0m[38;2;248;248;242mpd[0m[38;2;255;121;198m.[0m[38;2;248;248;242mread_excel[0m[38;2;248;248;242m([0m[3m[38;2;248;248;242mself[0m[38;2;255;121;198m.[0m[38;2;248;248;242m_filepath[0m[38;2;248;248;242m,[0m[38;2;248;248;242m [0m[38;2;255;121;198m*[0m[38;2;255;121;198m*[0m[3m[38;2;248;248;242mself[0m[38;2;255;121;198m.[0m[38;2;248;248;242m_load_args[0m[38;2;248;248;242m)[0m[38;2;248;248;242m[0m
  [38;2;248;248;242m[0m
  [38;2;248;248;242m    [0m[38;2;255;121;198mdef[0m[38;2;248;248;242m [0m[38;2;80;250;123m_save[0m[38;2;248;248;242m([0m[3m[38;2;248;248;242mself[0m[38;2;248;248;242m,[0m[38;2;248;248;242m [0m[38;2;248;248;242mdata[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;248;248;242mpd[0m[38;2;255;121;198m.[0m[38;2;248;248;242mDataFrame[0m[38;2;248;248;242m)[0m[38;2;248;248;242m [0m[38;2;255;121;198m-[0m[38;2;255;121;198m>[0m[38;2;248;248;242m [0m[38;2;248;248;242mNone[0m[38;2;248;248;242m:[0m[38;2;248;248;242m[0m
  [38;2;248;248;242m        [0m[38;2;248;248;242mwriter[0m[38;2;248;248;242m [0m[38;2;255;121;198m=[0m[38;2;248;248;242m [0m[38;2;248;248;242mpd[0m[38;2;255;121;198m.[0m[38;2;248;248;242mExcelWriter[0m[38;2;248;248;242m([0m[3m[38;2;248;248;242mself[0m[38;2;255;121;198m.[0m[38;2;248;248;242m_filepath[0m[38;2;248;248;242m,[0m[38;2;248;248;242m [0m[38;2;248;248;242mengine[0m[38;2;255;121;198m=[0m[3m[38;2;248;248;242mself[0m[38;2;255;121;198m.[0m[38;2;248;248;242m_engine[0m[38;2;248;248;242m)[0m[38;2;248;248;242m[0m
  [38;2;248;248;242m        [0m[38;2;248;248;242mdata[0m[38;2;255;121;198m.[0m[38;2;248;248;242mto_excel[0m[38;2;248;248;242m([0m[38;2;248;248;242mwriter[0m[38;2;248;248;242m,[0m[38;2;248;248;242m [0m[38;2;255;121;198m*[0m[38;2;255;121;198m*[0m[3m[38;2;248;248;242mself[0m[38;2;255;121;198m.[0m[38;2;248;248;242m_save_args[0m[38;2;248;248;242m)[0m[38;2;248;248;242m[0m
  [38;2;248;248;242m        [0m[38;2;248;248;242mwriter[0m[38;2;255;121;198m.[0m[38;2;248;248;242msave[0m[38;2;248;248;242m([0m[38;2;248;248;242m)[0m[38;2;248;248;242m[0m
  [38;2;248;248;242m[0m
  [38;2;248;248;242m    [0m[38;2;255;121;198mdef[0m[38;2;248;248;242m [0m[38;2;80;250;123m_exists[0m[38;2;248;248;242m([0m[3m[38;2;248;248;242mself[0m[38;2;248;248;242m)[0m[38;2;248;248;242m [0m[38;2;255;121;198m-[0m[38;2;255;121;198m>[0m[38;2;248;248;242m [0m[38;2;248;248;242mbool[0m[38;2;248;248;242m:[0m[38;2;248;248;242m[0m
  [38;2;248;248;242m        [0m[38;2;255;121;198mreturn[0m[38;2;248;248;242m [0m[38;2;248;248;242misfile[0m[38;2;248;248;242m([0m[3m[38;2;248;248;242mself[0m[38;2;255;121;198m.[0m[38;2;248;248;242m_filepath[0m[38;2;248;248;242m)[0m

[1m[38;2;189;147;249mExecution order is taken care of[0m
[38;2;68;71;90m────────────────────────────────[0m

As you build up complex pipelines containing 10’s or 100’s of nodes it becomes difficult to splice in new nodes/steps without messing up or a framework to help. Kedro simply needs a set of nodes that each takes in catalog entries as input and output to catalog entries and it will figure out the order for you.

These nodes can be made for one-off purposes, take in functions from reusable libraries, and even be dynamically generated from a configuration. There is no need to worry about hand curating the execution order, that’s all taken care of.

[1m[38;2;189;147;249mEasily slice up a pipeline[0m
[38;2;68;71;90m──────────────────────────[0m

Since kedro is a DAG that takes in a pile of nodes and figures out all of the dependencies for you it knows a lot about your pipeline. You can slice it up to only the specific pieces that you need.

[38;2;248;248;242m[code][0m
  # single nodes
  pipeline.only_nodes("node1")

  # single nodes and all of thier dependencies
  pipeline.to_nodes("node1", "node2")

  # from a dataset to all of its dependants
  pipeline.from_inputs("dataset1", "dataset2")

  # to a an outputs with all of its dependencies
  pipeline.to_outputs("dataset6", "dataset7")

[1m[38;2;189;147;249mplugins/hooks[0m
[38;2;68;71;90m─────────────[0m

Creating your own modifications to how kedro behaves is made really simple through the use of hooks. There are several hooks that happen at different points in the kedro lifecycle. For instance, you can hook in before pipeline run or after pipeline run to do whatever your project needs.

[4m[38;2;248;248;242mcreating the kedro-preflight hook[0m <[38;2;248;248;242m/creating-the-kedro-preflight-hook/[0m>

[1m[38;2;189;147;249m### pip install plugin[0m

There is a growing list of plugins available from pypi that is only a [38;2;189;147;249mpip install[0m away. Most of them are on [4m[38;2;248;248;242mGitHub[0m <[38;2;248;248;242mhttps://github.com/topics/kedro-plugin[0m> and tagged as a [4m[38;2;248;248;242mkedro-plugin[0m <[38;2;248;248;242mhttps://github.com/topics/kedro-plugin[0m> topic.

[1m[38;2;189;147;249mflexible cli[0m
[38;2;68;71;90m────────────[0m

In the end, you have a cli for your project that can run your pipeline in all sorts of cool ways since it knows about each node’s dependencies. This makes running and scheduling production a breeze.

[38;2;248;248;242m[code][0m
  # single nodes
  kedro run --node node1

  # single nodes and all of their dependencies
  kedro run --to-nodes node1,node2

  # from a dataset to all of its dependents
  kedro run --from-inputs dataset1,dataset2

  # to outputs with all of their dependencies
  kedro run --to-outputs dataset6,dataset7

[1m[38;2;189;147;249mTry it out[0m
[38;2;68;71;90m──────────[0m

Hopefully this post gave you the inspiration to get started today, if it did [38;2;189;147;249mpip install kedro[0m and run [38;2;189;147;249mkedro new[0m to try it out.
