Slack SDK (Python)
Official Slack SDK for Python. Current version is 3.41.0 (Mar 2026). PyPI package is 'slack-sdk', imports as 'slack_sdk'. The predecessor 'slackclient' is in maintenance mode — vast amounts of tutorial code still references it. This is the official replacement.
Warnings
- breaking slackclient (pip install slackclient) is in maintenance mode. slack-sdk (pip install slack-sdk) is the official successor. They have different import paths: slack vs slack_sdk.
- breaking files.upload API is retired (Nov 12, 2025). New apps blocked from it since May 2024. Calling client.files_upload() on new apps returns method_deprecated error.
- breaking files_upload_v2 channel parameter is channel_id= (not channels= plural). Passing channels= silently fails or is ignored.
- breaking aiohttp is no longer a required dependency in slack-sdk v3. AsyncWebClient and AsyncWebhookClient will raise ImportError if aiohttp is not explicitly installed.
- gotcha WebClient.run_async option removed in v3. Use AsyncWebClient for async operations instead of the v2 run_async=True flag.
- gotcha files_upload_v2 is asynchronous on the Slack server side. Even after a successful response, the file may not immediately appear in channel. Polling files.info or using Events API is required for post-upload processing.
- gotcha Token type matters: Bot tokens (xoxb-) for most operations, User tokens (xoxp-) for user-scoped actions, App-level tokens (xapp-) for Socket Mode only. Mixing them causes invalid_auth or missing_scope errors.
Install
-
pip install slack-sdk -
pip install slackclient
Imports
- WebClient
from slack_sdk import WebClient
- SlackApiError
from slack_sdk.errors import SlackApiError
Quickstart
import os
from slack_sdk import WebClient
from slack_sdk.errors import SlackApiError
client = WebClient(token=os.environ['SLACK_BOT_TOKEN'])
try:
response = client.chat_postMessage(
channel='#general',
text='Hello world!'
)
except SlackApiError as e:
print(f"Error: {e.response['error']}")
# File upload (v2 — required for new apps)
client.files_upload_v2(
channel='C0123456789',
file='./report.pdf',
filename='report.pdf'
)