Dagster Slack
The `dagster-slack` library provides a Slack client resource for integrating Slack notifications and messaging capabilities into Dagster data pipelines. It enables users to send messages to Slack channels from ops, assets, schedules, and sensors, facilitating real-time communication about pipeline status and events. The current version is 0.29.0, and it follows the frequent release cadence of the broader Dagster ecosystem.
Warnings
- gotcha When interacting with the Slack client directly from the `SlackResource`, use `slack.get_client().chat_postMessage(...)` instead of `slack.chat_postMessage(...)`. The `get_client()` method ensures you are calling the method on the underlying `slack_sdk.WebClient` instance.
- breaking When configuring hooks and sensors (e.g., `make_slack_on_run_failure_sensor`), the `dagit_base_url` parameter has been deprecated and replaced with `webserver_base_url` for generating deep links to runs in the UI.
- gotcha To use `dagster-slack`, you must first create a Slack App in your workspace, configure bot users, install the app to your workspace, and obtain a bot token. This token should be stored securely, ideally as an environment variable (e.g., `MY_SLACK_TOKEN`), and passed to the `SlackResource`.
- deprecated In `make_slack_on_run_failure_sensor`, the `job_selection` and `monitor_all_repositories` parameters are deprecated. Use `monitored_jobs` for specifying jobs to monitor.
Install
-
pip install dagster-slack
Imports
- SlackResource
from dagster_slack import SlackResource
- make_slack_on_run_failure_sensor
from dagster_slack import make_slack_on_run_failure_sensor
- make_slack_on_step_failure_hook
from dagster_slack import make_slack_on_step_failure_hook
Quickstart
import os
from dagster import Definitions, EnvVar, asset
from dagster_slack import SlackResource
@asset
def send_slack_message(slack: SlackResource):
"""An asset that sends a message to Slack."""
channel = os.environ.get('SLACK_CHANNEL', '#general') # Ensure channel exists
slack.get_client().chat_postMessage(channel=channel, text=":wave: Hello from Dagster!")
defs = Definitions(
assets=[send_slack_message],
resources={
"slack": SlackResource(token=EnvVar("MY_SLACK_TOKEN"))
},
)