chase albright
10/10/2025, 3:46 PMMarvin
10/10/2025, 3:46 PMMarvin
10/10/2025, 3:48 PMprefect.blocks.notifications.SlackWebhook
- Integration (Chat API): Prefect Slack integration docs
- Microsoft Teams: use the prefect.blocks.notifications.MicrosoftTeamsWebhook block
Typical usage (no Cloud required):
from prefect import flow
from prefect.blocks.notifications import SlackWebhook, MicrosoftTeamsWebhook
@flow
def my_flow():
try:
# your work
...
except Exception as e:
# Send to Slack
SlackWebhook.load("slack-alerts").notify(f"my_flow failed: {e}")
# Or send to Teams
# MicrosoftTeamsWebhook.load("teams-alerts").notify(f"my_flow failed: {e}")
raise
Creating blocks:
- Either create/save them in code:
SlackWebhook(url="<https://hooks.slack.com/services/...>").save("slack-alerts", overwrite=True)
MicrosoftTeamsWebhook(url="<https://outlook.office.com/webhook/...>").save("teams-alerts", overwrite=True)
- Or create them in the UI, then load(...) by name in your flows.
What’s Cloud-only:
- Prefect Cloud adds Automations (event/state-based, policy-driven alerts) and team features. In OSS you’ll trigger notifications from your flow code (like above) or via your own monitoring flows.
Docs and references:
- Blocks API (Slack/Teams, others): Notification blocks API
- Slack integration (Chat API helper tasks/blocks): Prefect Slack integration
- Cloud vs OSS overview: Cloud vs OSS
Note: If you ever see a missing dependency error related to notifications, install the suggested package (e.g., apprise) and retry.