Sign inGet started


Integrate Deepnote with Slack

Slack is the collaboration hub that brings the right people, information, and tools together to get work done. This guide walks you through using Slack to deliver notifications at different points of your data workflows on Deepnote (like updating you on the status of scheduled notebook runs).

Slack notifications workflow

How to set it up

The first step in integrating Slack with your Deepnote notebooks is creating a Slack app and getting your app's token. All you need to do to get started is:

  1. Create a Slack app by clicking the Create App button here.
  2. Copy the Slack token of your new app. It should start with "xoxb", for example xoxb-not-a-real-token-this-will-not-work.
  3. Store the token in a variable (such as SLACK_TOKEN). If you'd like to keep your data secure, consider storing the token as an environment variable. Environment variables in Deepnote are encrypted and provide a secure way of storing sensitive data.
  4. Install the slack_sdk __ Python __ package by running !pip install slack_sdk.

How to use

Once you've created your Slack app and installed the slack_sdk Python package, sending notifications via Slack becomes rather straightforward. The code below sends a notification into the #general channel informing everyone in that channel of a successful run.

import os
from datetime import datetime
import slack_sdk

CHANNEL = '#general' # Insert the name of channel here
USERNAME = 'Deepnote Bot'
ICON = '' # This is a URL pointing to the icon of your bot.
today ='%B %d, %Y at %H:%M UTC')
MESSAGE_TEXT = f'Experiment status: Success!\nLast run: {today}' # This is a sample message. Replace with your own text.

def post_message_to_slack(slack_token, text, channel, blocks=None):
        print('Sending message...')
        # Connect to the Slack client via token
        client = slack_sdk.WebClient(token=SLACK_TOKEN)

        # Post the Slack message
        request = client.chat_postMessage(
        print('Message was sent successfully.')
        return request

        # Print error
    except Exception as e:
        print(f'Error: {e}')

request = post_message_to_slack(SLACK_TOKEN, MESSAGE_TEXT, CHANNEL)

Using the function above to send a message will produce a Slack notification that is going to look a little something like this:

Slack notification from Deepnote

Next steps

Jump right into Deepnote & view an example of sending scheduled notebook run Slack updates here. You can also save yourself some setup work by hitting Duplicate button in the top-right corner to start exploring on your own!