Registry / workflow / prefect-slack

prefect-slack

JSON →
library0.3.1pypiunverified

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-slack
INSTALL
IMPORT
SIG · PREFECT-SLACK
P
prefect-slack
workflowenv0.3.1
Install
23.6s avg
Import
Disk
257MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.3.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 259.6MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 23.6s · import 0.000s · 262MB
257MB installed
● package 257MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

SlackWebhook
from prefect_slack.webhooks import SlackWebhook
SlackMessage
from prefect_slack.messages import SlackMessage

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.

import os from prefect import flow from prefect_slack.webhooks import SlackWebhook @flow(log_prints=True) def send_slack_notification_flow(message: str = "Hello from Prefect!"): """Sends a custom message to Slack via a configured webhook.""" # Retrieve Slack Webhook URL from environment variables or Prefect secrets slack_webhook_url = os.environ.get("SLACK_WEBHOOK_URL", "") if not slack_webhook_url: print("Warning: SLACK_WEBHOOK_URL environment variable is not set. Skipping Slack notification.") return # Initialize the SlackWebhook block with the URL # For production, consider creating and storing this block in the Prefect UI/API # and loading it via await SlackWebhook.load("my-slack-webhook-block") webhook_block = SlackWebhook(url=slack_webhook_url) # Send the notification webhook_block.notify(body=message) print(f"Successfully sent Slack notification: {message}") if __name__ == "__main__": # To run this example, set the SLACK_WEBHOOK_URL environment variable: # export SLACK_WEBHOOK_URL="https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX" send_slack_notification_flow(message="This is a test notification from my Prefect flow!")
Debug
Known issues
breakingThe `prefect-slack` library `0.3.1` is designed for Prefect core `2.x` (specifically versions `>=2.10.0,<3.0.0`). Using it with Prefect core `3.x` (which is currently in development/nightly releases) may lead to incompatibility issues or unexpected behavior. Always ensure your `prefect` core library version is compatible with your `prefect-slack` version.
fix
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`.
affects: prefect-slack < 1.0.0 with prefect >= 3.0.0
gotchaSlack integrations, particularly webhooks, require proper authentication. The `SlackWebhook` block needs a valid URL to post messages. Incorrectly configured URLs or missing environment variables/secrets will prevent notifications from being sent.
fix
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")`).
affects: All versions
gotchaWhen using `SlackWebhook` or `SlackMessage` blocks, ensure they are instantiated or loaded correctly within the Prefect flow context. If blocks are not saved in the Prefect backend, they must be instantiated directly in code, which might expose credentials if not handled carefully (e.g., via environment variables).
fix
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).
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'prefect_slack'
The `prefect-slack` library has not been installed in your Python environment.
fix
Run `pip install prefect-slack` to install the library.
pydantic_core._pydantic_core.ValidationError: 1 validation error for SlackWebhook url URL is not a valid URL [type=url_parsing, input_value='']
The `SlackWebhook` block was instantiated without a valid `url` or the provided URL was empty/invalid.
fix
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.
TypeError: notify() missing 1 required positional argument: 'body'
The `notify()` method of `SlackWebhook` or `SlackMessage` was called without providing the `body` argument, which is the message content.
fix
Always pass the message content as the `body` argument to the `notify()` method, e.g., `webhook_block.notify(body='Your message here')`.
Upgrade
Version history
0.3.1latest on PyPI · released Nov 15, 2024
Audit
Dependencies
prefectrequiredCore Prefect library is required to define and run flows and utilize integrations. Version `0.3.1` of `prefect-slack` is compatible with Prefect core versions `>=2.10.0,<3.0.0`.
Agent activity
20 hits · last 30 days
node
16
OpenAI (training)
1
Resources
prefect-slack — pip install prefect-slack · libregistry