Python SDK

Install and start using the Python SDK.

Intro

The Slack Web API SDK provides access to the Slack Web API REST APIs.

Installation

Add the SDK to your project from its folder, with whichever package manager your project uses. Give each tool a path containing a slash, such as ../slack-web-api — a bare folder name is looked up on PyPI instead, and resolves to whatever project holds that name there:

Terminal
pip install <path-to-sdk>
Terminal
uv add <path-to-sdk>
Terminal
poetry add <path-to-sdk>

Quick Start

Synchronous client

Construct SlackWebApiClient with keyword arguments, and call close() when you are done. Every argument is optional.

Python
from slack_web_api import SlackWebApiClient
from slack_web_api.auth import SlackAuthScope
from slack_web_api.core import AuthorizationCodeCredentials


def prompt(url: str) -> str:
    return input(f"Open {url}, then paste the code: ")


client = SlackWebApiClient(
    slack_auth=AuthorizationCodeCredentials[SlackAuthScope](
        client_id="YOUR_CLIENT_ID", redirect_uri="YOUR_REDIRECT_URI", prompt_for_authorization_code=prompt
    ),
    environment="production",
)

client.close()

Alternatively, scope it — with SlackWebApiClient(...) as client: closes the pool on exit.

Asynchronous client

AsyncSlackWebApiClient mirrors SlackWebApiClient with identical method names, and every endpoint method is a coroutine. It takes the same arguments, with some differences — for example, the transport argument is custom_async_http_client.

Python
from asyncio import run, to_thread

from slack_web_api import AsyncSlackWebApiClient
from slack_web_api.auth import SlackAuthScope
from slack_web_api.core import AsyncAuthorizationCodeCredentials


async def prompt(url: str) -> str:
    print(f"Open {url}")
    return await to_thread(input, "Paste the code: ")


async def main() -> None:
    client = AsyncSlackWebApiClient(
        slack_auth=AsyncAuthorizationCodeCredentials[SlackAuthScope](
            client_id="YOUR_CLIENT_ID", redirect_uri="YOUR_REDIRECT_URI", prompt_for_authorization_code=prompt
        ),
        environment="production",
    )
    await client.aclose()


run(main())

Alternatively, scope it — async with AsyncSlackWebApiClient(...) as client: closes the pool on exit.

On this page