{"id":14920,"library":"slack_sdk","title":"Slack SDK for Python (Official)","description":"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.","status":"active","version":"3.27.0","language":"en","source_language":"en","source_url":"https://github.com/slackapi/python-slack-sdk","tags":["slack","api","sdk","chat","bots","webhooks","events"],"install":[{"cmd":"pip install slack_sdk","lang":"bash","label":"Basic Installation"},{"cmd":"pip install slack_bolt","lang":"bash","label":"For building Slack apps with Bolt framework"},{"cmd":"pip install slack_sdk aiohttp","lang":"bash","label":"For asynchronous WebClient usage"}],"dependencies":[{"reason":"Required for asynchronous WebClient (AsyncWebClient) operations and some Socket Mode clients.","package":"aiohttp","optional":true}],"imports":[{"note":"slackclient is in maintenance mode; slack_sdk is the successor.","wrong":"from slackclient import SlackClient","symbol":"WebClient","correct":"from slack_sdk import WebClient"},{"note":"The 'App' class for building Slack applications with event listeners is part of the `slack_bolt` framework, not directly `slack_sdk`.","wrong":"from slack_sdk import App","symbol":"App","correct":"from slack_bolt import App"},{"note":"For handling API-specific errors.","symbol":"SlackApiError","correct":"from slack_sdk.errors import SlackApiError"}],"quickstart":{"code":"import os\nfrom slack_sdk import WebClient\nfrom slack_sdk.errors import SlackApiError\n\n# Your bot token (xoxb-...) or user token (xoxp-...)\n# You can find these at https://api.slack.com/apps\nslack_token = os.environ.get('SLACK_BOT_TOKEN', 'YOUR_SLACK_BOT_TOKEN')\n\nclient = WebClient(token=slack_token)\n\ntry:\n    response = client.chat_postMessage(\n        channel='#general', # Or a channel ID like 'C12345ABC'\n        text='Hello from your Python Slack SDK app!'\n    )\n    print(f\"Message posted: {response['ts']}\")\nexcept SlackApiError as e:\n    # You will get a SlackApiError if 'ok' is False\n    print(f\"Error sending message: {e.response['error']}\")\n    # e.g., 'invalid_auth', 'channel_not_found', 'not_in_channel' etc.\n    if e.response['error'] == 'invalid_auth':\n        print(\"Please check your SLACK_BOT_TOKEN or SLACK_APP_TOKEN environment variable.\")\n    elif e.response['error'] == 'channel_not_found':\n        print(\"The specified channel does not exist or your bot is not in it.\")\n\n# Example for Slack Bolt App (requires 'pip install slack_bolt')\n# from slack_bolt import App\n# from slack_bolt.adapter.socket_mode import SocketModeHandler\n\n# app = App(token=os.environ.get('SLACK_BOT_TOKEN'))\n\n# @app.message(\"hello\")\n# def message_hello(message, say):\n#     say(f\"Hey there <@{message['user']}>!\")\n\n# if __name__ == \"__main__\":\n#     SocketModeHandler(app, os.environ.get(\"SLACK_APP_TOKEN\")).start()\n","lang":"python","description":"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."},"warnings":[{"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.","message":"The 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.","severity":"breaking","affected_versions":"slackclient < 2.x, slackclient 2.x to slack_sdk 3.x"},{"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.","message":"There 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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"The `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.","severity":"deprecated","affected_versions":"Apps created after May 16, 2024, and all apps by November 12, 2025."},{"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`.","message":"Support 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).","severity":"breaking","affected_versions":"All legacy custom bots and classic apps."},{"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-`.","message":"Incorrect 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'.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"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.","cause":"Attempting to import the old `slackclient` library after `slack_sdk` or `slack_bolt` has been installed, or `slackclient` was not installed at all.","error":"ModuleNotFoundError: No module named 'slackclient'"},{"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.","cause":"The Slack API token provided is invalid, expired, revoked, or lacks the necessary scopes for the requested operation.","error":"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'})"},{"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.","cause":"The specified channel ID or name does not exist, or the bot user is not a member of the channel.","error":"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'})"},{"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.","cause":"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`.","error":"UserWarning: slack package is deprecated. Please use slack_sdk.web/webhook/rtm package instead."}],"ecosystem":"pypi"}