Skip to main content
Execute shell commands from within Prefect flows.

Getting started

Install prefect-shell

The following command will install a version of prefect-shell compatible with your installed version of prefect. If you don’t already have prefect installed, it will install the newest version of prefect as well.
Upgrade to the latest versions of prefect and prefect-shell:

Register newly installed block types

Register the block types in the prefect-shell module to make them available for use.

Examples

Integrate shell commands with Prefect flows

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:
Running this script results in output like this:

Save shell commands in Prefect blocks

You can save commands within a ShellOperation block, then reuse them across multiple flows. Save the block with desired commands:

Resources

Refer to the prefect-shell SDK documentation to explore all the capabilities of the prefect-shell library.