Slack Client (Legacy Package)
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
- deprecated The `slackclient` Python package is deprecated. Its last version is 2.9.4. All new development and maintenance occurs in the `slack-sdk` package. You should migrate to `slack-sdk` for active support and new features.
- breaking Major API changes occurred between `slackclient` v1.x and v2.x. The `SlackClient` class was removed, and the `WebClient` and `RTMClient` classes were introduced with different constructor arguments and method signatures. This change also introduced the new `from slack import ...` import paths.
- gotcha Confusion often arises because `slackclient` v2.x introduced imports like `from slack import WebClient`, which are identical to `slack-sdk`. However, `slackclient` is a distinct (and now deprecated) package from `slack-sdk`. Installing `slackclient` will NOT give you the latest `slack-sdk` features or fixes.
Install
-
pip install slackclient -
pip install slack-sdk
Imports
- WebClient
from slack import WebClient
- RTMClient
from slack.rtm import RTMClient
- SlackClient
from slack_sdk import WebClient
Quickstart
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}")