With prefect-shell, you can use shell commands (and/or scripts) in Prefect flows to provide observability and resiliency.
Prefect-shell can be a useful tool if you're transitioning your orchestration from shell scripts to Prefect.
Let's get the shell-abration started!
The Python code below has shell commands embedded in a Prefect flow:
fromprefectimportflowfromdatetimeimportdatetimefromprefect_shellimportShellOperation@flowdefdownload_data():today=datetime.today().strftime("%Y%m%d")# for short running operations, you can use the `run` method# which automatically manages the contextShellOperation(commands=["mkdir -p data","mkdir -p data/${today}"],env={"today":today}).run()# for long running operations, you can use a context managerwithShellOperation(commands=["curl -O https://masie_web.apps.nsidc.org/pub/DATASETS/NOAA/G02135/north/daily/data/N_seaice_extent_daily_v3.0.csv",],working_dir=f"data/{today}",)asdownload_csv_operation:# trigger runs the process in the backgrounddownload_csv_process=download_csv_operation.trigger()# then do other things here in the meantime, like download another file...# when you're ready, wait for the process to finishdownload_csv_process.wait_for_completion()# if you'd like to get the output lines, you can use the `fetch_result` methodoutput_lines=download_csv_process.fetch_result()if__name__=="__main__":download_data()