{"id":14820,"library":"prefect-slack","title":"Prefect Slack Integration","description":"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`.","status":"active","version":"0.3.1","language":"en","source_language":"en","source_url":"https://github.com/PrefectHQ/prefect/tree/main/src/integrations/prefect-slack","tags":["prefect","slack","integrations","workflow","automation","notifications","data-orchestration"],"install":[{"cmd":"pip install prefect-slack","lang":"bash","label":"Install prefect-slack"}],"dependencies":[{"reason":"Core 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`.","package":"prefect","optional":false}],"imports":[{"symbol":"SlackWebhook","correct":"from prefect_slack.webhooks import SlackWebhook"},{"symbol":"SlackMessage","correct":"from prefect_slack.messages import SlackMessage"}],"quickstart":{"code":"import os\nfrom prefect import flow\nfrom prefect_slack.webhooks import SlackWebhook\n\n@flow(log_prints=True)\ndef send_slack_notification_flow(message: str = \"Hello from Prefect!\"):\n    \"\"\"Sends a custom message to Slack via a configured webhook.\"\"\"\n    # Retrieve Slack Webhook URL from environment variables or Prefect secrets\n    slack_webhook_url = os.environ.get(\"SLACK_WEBHOOK_URL\", \"\")\n    if not slack_webhook_url:\n        print(\"Warning: SLACK_WEBHOOK_URL environment variable is not set. Skipping Slack notification.\")\n        return\n\n    # Initialize the SlackWebhook block with the URL\n    # For production, consider creating and storing this block in the Prefect UI/API\n    # and loading it via await SlackWebhook.load(\"my-slack-webhook-block\")\n    webhook_block = SlackWebhook(url=slack_webhook_url)\n    \n    # Send the notification\n    webhook_block.notify(body=message)\n    print(f\"Successfully sent Slack notification: {message}\")\n\nif __name__ == \"__main__\":\n    # To run this example, set the SLACK_WEBHOOK_URL environment variable:\n    # export SLACK_WEBHOOK_URL=\"https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX\"\n    send_slack_notification_flow(message=\"This is a test notification from my Prefect flow!\")","lang":"python","description":"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."},"warnings":[{"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`.","message":"The `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.","severity":"breaking","affected_versions":"prefect-slack < 1.0.0 with prefect >= 3.0.0"},{"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\")`).","message":"Slack 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.","severity":"gotcha","affected_versions":"All versions"},{"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).","message":"When 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).","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Run `pip install prefect-slack` to install the library.","cause":"The `prefect-slack` library has not been installed in your Python environment.","error":"ModuleNotFoundError: No module named 'prefect_slack'"},{"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.","cause":"The `SlackWebhook` block was instantiated without a valid `url` or the provided URL was empty/invalid.","error":"pydantic_core._pydantic_core.ValidationError: 1 validation error for SlackWebhook\nurl\n  URL is not a valid URL [type=url_parsing, input_value='']"},{"fix":"Always pass the message content as the `body` argument to the `notify()` method, e.g., `webhook_block.notify(body='Your message here')`.","cause":"The `notify()` method of `SlackWebhook` or `SlackMessage` was called without providing the `body` argument, which is the message content.","error":"TypeError: notify() missing 1 required positional argument: 'body'"}],"ecosystem":"pypi"}