常見的資料處理流程可租略分紅如下幾步:python
剛開始你的資料處理流程多是像這樣依序地執行腳本git
$ python get_data.py $ python clean_data.py $ python normalize.py $ python train.py $ python predict.py
稍微懶一點的人因而會把全部腳本打包進一個腳本run_all.py
程序員
if __name__ == '__main__': get_data() clean_data() normalize() train() predict()
$ python run_all.py
可是若是想要作好錯誤處理(error handling), 腳本可能就會變成像這樣嘮叨的代碼github
try: get_data() try: clean_data() try: # ... except MoreErrors: # ... except CleanDataError as e: # handle CleanDataError except GetDataError as e: # handle GetDataError
一旦步驟切分得更細或是步驟愈來愈多時, 錯誤處理變成一項繁瑣的工做, 這樣的重複的結構也使得代碼不易閱讀. 一些框架如Luigi和Airflow能將程序員從這項勞動中解放出來, 提高開發的效率,算法
Luigi是一套管理上述工做流程的python框架,讓開發人員專一在數據處理的邏輯,而沒必要重複的撰寫經常使用的代碼, 例如前面舉例的錯誤處理. 另外, 若是某個數據處理的步驟發生了錯誤或是更動,使用Luigi能夠避免從新計算不被影響的結果.瀏覽器
$ pip install luigi
$ pip install git+https://github.com/spotify/luigi.git
$ luigid
http://localhost:8082