The `prefect-slack` library provides official integrations for connecting Prefect 2.x workflows with Slack. It enables sending notifications and messages to Slack channels using webhooks or bot tokens, typically via Prefect Blocks. The current stable version is `0.3.1`, and it's part of the PrefectHQ monorepo, with releases often following the Prefect core library's major versions, though `prefect-slack` `0.3.1` is specifically for Prefect `2.x`.
pip install prefect-slackVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to send a simple Slack notification from a Prefect flow using the `SlackWebhook` block. It requires a Slack incoming webhook URL, which should be set as an environment variable (`SLACK_WEBHOOK_URL`) for secure handling of credentials. In a production environment, it's recommended to create and save `SlackWebhook` blocks via the Prefect UI or API to reuse them across multiple flows and deployments.
Ensure your `prefect` core library version is within the compatible range (e.g., `pip install 'prefect>=2.10.0,<3.0.0'`) when using `prefect-slack==0.3.1`.
Always provide the `url` argument to `SlackWebhook` or `SlackMessage` blocks, ideally loading it from environment variables (e.g., `os.environ.get("SLACK_WEBHOOK_URL")`) or a Prefect secret block. For production, create and save the `SlackWebhook` block in the Prefect UI/API and load it by name (`await SlackWebhook.load("your-block-name")`).For reusable blocks with sensitive credentials (like webhook URLs), create and save them in the Prefect UI/API. Then, within your flow, load them using `await BlockClass.load("block-name")`. If instantiating directly in code, ensure credentials are sourced securely (e.g., from environment variables or a dedicated secret management system).Run `pip install prefect-slack` to install the library.
Ensure the `url` parameter passed to `SlackWebhook(url=...)` is a complete and valid Slack incoming webhook URL. If using environment variables, verify the variable is set and accessible.
Always pass the message content as the `body` argument to the `notify()` method, e.g., `webhook_block.notify(body='Your message here')`.