Registry / communication / slack_sdk

slack_sdk

JSON →
library3.42.0pypiunverified

The Slack SDK for Python provides a comprehensive and easy-to-use toolkit for building Slack applications. It offers corresponding packages for various Slack APIs, including Web API, Webhooks, Socket Mode, and OAuth. This library (and `slack_bolt`) is the official and actively maintained successor to `slackclient`. It is designed to be small, powerful, and to work seamlessly across different Slack platform features. The current version is 3.x, with frequent updates to support new Slack features and improvements.

pip install slack_sdk
INSTALL
IMPORT
SIG · SLACK_SDK
S
slack_sdk
communicationenv3.42.0
Install
2.7s avg
Import
371ms
Disk
31MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v3.42.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.930 runs
installs and imports cleanly · install 0.0s · import 0.389s · 31MB
glibc
py 3.103.930 runs
installs and imports cleanly · install 2.7s · import 0.352s · 33MB
31MB installed
● package 31MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

WebClient
from slack_sdk import WebClient
from slackclient import SlackClient
slackclient is in maintenance mode; slack_sdk is the successor.
App
from slack_bolt import App
from slack_sdk import App
The 'App' class for building Slack applications with event listeners is part of the `slack_bolt` framework, not directly `slack_sdk`.
SlackApiError
from slack_sdk.errors import SlackApiError
For handling API-specific errors.

This quickstart demonstrates sending a basic message to a Slack channel using the `WebClient` from `slack_sdk`. It handles authentication via an environment variable and includes basic error handling for common API issues. A commented-out example for a simple 'hello' response using the `slack_bolt` framework is also provided. Remember to set `SLACK_BOT_TOKEN` (and `SLACK_APP_TOKEN` for Socket Mode) environment variables.

import os from slack_sdk import WebClient from slack_sdk.errors import SlackApiError # Your bot token (xoxb-...) or user token (xoxp-...) # You can find these at https://api.slack.com/apps slack_token = os.environ.get('SLACK_BOT_TOKEN', 'YOUR_SLACK_BOT_TOKEN') client = WebClient(token=slack_token) try: response = client.chat_postMessage( channel='#general', # Or a channel ID like 'C12345ABC' text='Hello from your Python Slack SDK app!' ) print(f"Message posted: {response['ts']}") except SlackApiError as e: # You will get a SlackApiError if 'ok' is False print(f"Error sending message: {e.response['error']}") # e.g., 'invalid_auth', 'channel_not_found', 'not_in_channel' etc. if e.response['error'] == 'invalid_auth': print("Please check your SLACK_BOT_TOKEN or SLACK_APP_TOKEN environment variable.") elif e.response['error'] == 'channel_not_found': print("The specified channel does not exist or your bot is not in it.") # Example for Slack Bolt App (requires 'pip install slack_bolt') # from slack_bolt import App # from slack_bolt.adapter.socket_mode import SocketModeHandler # app = App(token=os.environ.get('SLACK_BOT_TOKEN')) # @app.message("hello") # def message_hello(message, say): # say(f"Hey there <@{message['user']}>!") # if __name__ == "__main__": # SocketModeHandler(app, os.environ.get("SLACK_APP_TOKEN")).start()
Debug
Known issues
breakingThe original `slackclient` library is in maintenance mode, and `slack_sdk` is its official successor. Direct migration from `slackclient` v1.x to v2.x (and then to `slack_sdk` v3.x) involved significant breaking changes in import paths and API usage.
fix
Migrate your application to `slack_sdk`. Review the official migration guides for `slackclient` v1.x to v2.x and v2.x to `slack_sdk` v3.x. Key changes include importing `slack_sdk` instead of `slackclient`, and explicit dependency on `aiohttp` for async clients.
affects: slackclient < 2.x, slackclient 2.x to slack_sdk 3.x
gotchaThere is an unrelated, minimally maintained Python package also named `slack` (version 0.0.3) on PyPI, which is described as 'a DI container'. This is *not* the official Slack library for interacting with the Slack platform. Installing `pip install slack` will install the DI container, not the Slack API client.
fix
Always install `slack_sdk` (for the core SDK) or `slack_bolt` (for the framework) when intending to interact with the Slack API. E.g., `pip install slack_sdk`. Do not install `pip install slack` for Slack API interaction.
affects: All versions
deprecatedThe `files.upload` Web API method has been deprecated as of May 16, 2024, for newly created Slack apps. It will be fully retired on November 12, 2025.
fix
Migrate to the new asynchronous upload flow for files. Refer to the Slack Developer documentation for details on `files_upload_v2` and the recommended asynchronous approach.
affects: Apps created after May 16, 2024, and all apps by November 12, 2025.
breakingSupport for legacy custom bots and classic apps will be discontinued. Legacy custom bots will cease to function after March 31, 2025. Support for classic apps will be discontinued in November 2026 (though this date has been subject to change).
fix
Migrate existing legacy custom bots and classic apps to new Slack apps built with modern Slack Platform features and libraries like `slack_sdk` or `slack_bolt`.
affects: All legacy custom bots and classic apps.
gotchaIncorrect token usage (e.g., using a bot token `xoxb-` where a user token `xoxp-` is expected, or vice-versa) is a common source of 'invalid_auth' or 'BotUserAccessError'.
fix
Ensure the correct token type is used for the specific API method being called and that the token has the necessary scopes. User tokens start with `xoxp-`, bot tokens with `xoxb-`, and app-level tokens (for Socket Mode) with `xapp-`.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'slackclient'
Attempting to import the old `slackclient` library after `slack_sdk` or `slack_bolt` has been installed, or `slackclient` was not installed at all.
fix
Install `slack_sdk` (`pip install slack_sdk`) and update your imports from `slackclient` to `slack_sdk`. If you need to support older code, explicitly install `slackclient==2.x` (e.g., `pip install slackclient==2.9.3`) but migration to `slack_sdk` is strongly recommended.
slack_sdk.errors.SlackApiError: The request to the Slack API failed. (url: https://slack.com/api/chat.postMessage, status: 403, body: {'ok': False, 'error': 'invalid_auth'})
The Slack API token provided is invalid, expired, revoked, or lacks the necessary scopes for the requested operation.
fix
Verify that your `SLACK_BOT_TOKEN` or `SLACK_USER_TOKEN` environment variable is correctly set and contains a valid token. Check your Slack App's 'OAuth & Permissions' page to ensure the token is still active and has the required OAuth scopes (e.g., `chat:write`, `channels:read`). Reinstalling the app to your workspace often resolves token issues.
slack_sdk.errors.SlackApiError: The request to the Slack API failed. (url: https://slack.com/api/chat.postMessage, status: 200, body: {'ok': False, 'error': 'channel_not_found'})
The specified channel ID or name does not exist, or the bot user is not a member of the channel.
fix
Ensure the channel ID or name is correct. If using a bot token, invite the bot user to the target channel (e.g., by mentioning it in the channel `/@your_bot_name`). For public channels, consider adding `chat:write.public` scope to your bot token.
UserWarning: slack package is deprecated. Please use slack_sdk.web/webhook/rtm package instead.
You are importing modules from the transitional `slack` package, which is a deprecated alias provided for backward compatibility after the rename from `slackclient` to `slack_sdk`.
fix
Update your import statements to use `slack_sdk` directly. For example, change `from slack.web import WebClient` to `from slack_sdk.web import WebClient` or simply `from slack_sdk import WebClient` if directly importing the top-level class.
Upgrade
Version history
3.42.0latest on PyPI · released May 18, 2026
Audit
Dependencies
aiohttpoptionalRequired for asynchronous WebClient (AsyncWebClient) operations and some Socket Mode clients.
Agent activity
16 hits · last 30 days
node
14
OpenAI (training)
1
Resources
slack_sdk — pip install slack_sdk · libregistry