import wandb
from wandb.automations import OnRunMetric, RunEvent, SendNotification
api = wandb.Api()
project = api.project("<my-project>", entity="<my-team>")
# Use the first Slack integration for the team
slack_hook = next(api.slack_integrations(entity="<my-team>"))
# Create a trigger event
event = OnRunMetric(
scope=project,
filter=RunEvent.metric("custom-metric") > 10,
)
# Create an action that responds to the event
action = SendNotification.from_integration(slack_hook)
# Create the automation
automation = api.create_automation(
event >> action,
name="my-automation",
description="Send a Slack message whenever 'custom-metric' exceeds 10.",
)