Slack Client (Legacy Package)

2.9.4 · deprecated · verified Thu Apr 09

The `slackclient` library is the legacy Python client for the Slack Web API and RTM API. Version 2.9.4 is the last release, and the project is officially deprecated. Users are strongly advised to migrate to the `slack-sdk` package, which is the actively maintained and officially supported Slack Python SDK. While `slackclient` v2.x shared similar import paths with `slack-sdk` (e.g., `from slack import WebClient`), the `slack-sdk` project has continued development and introduced new features and improvements.

Warnings

Install

Imports

Quickstart

This example demonstrates how to send a message to a Slack channel using the `WebClient` from the `slackclient` library (v2.x). Ensure you have a Slack bot token (`SLACK_BOT_TOKEN`) set as an environment variable or hardcoded for testing. This pattern is similar to `slack-sdk`, but future compatibility and new features are only available in `slack-sdk`.

import os
from slack import WebClient

# This quickstart is for the legacy `slackclient` v2.x.
# It is highly recommended to use `slack-sdk` instead.

# Get a Slack bot token from environment variable
SLACK_BOT_TOKEN = os.environ.get('SLACK_BOT_TOKEN', 'xoxb-YOUR-TOKEN')

if not SLACK_BOT_TOKEN:
    print("Error: SLACK_BOT_TOKEN environment variable not set.")
    exit(1)

client = WebClient(token=SLACK_BOT_TOKEN)

try:
    # Call the chat.postMessage method using the WebClient
    response = client.chat_postMessage(
        channel="#general", # Replace with your channel ID or name
        text="Hello from `slackclient` (legacy)! Please consider using `slack-sdk` instead."
    )
    print(f"Message sent: {response['ts']}")
except Exception as e:
    print(f"Error sending message: {e}")

view raw JSON →