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

Getting Started

Prerequisites

Requires an installation of Python 3.9+ We recommend using a Python virtual environment manager such as pipenv, conda or virtualenv. These tasks are designed to work with Prefect 3.

Install prefect-shell

Install or update to the latest version of the prefect-shell library and dependencies.

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 linked in the sidebar to explore all the capabilities of the prefect-shell library.