Skip to content

Commit 2f75504

Browse files
cleanup (#1699)
1 parent 1b61c36 commit 2f75504

19 files changed

+762
-1573
lines changed

docs/content/audit-logs.md

Lines changed: 15 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,20 @@
1-
# Audit Logs API Client
1+
# Audit Logs API client
22

3-
[Audit Logs API](https://api.slack.com/admins/audit-logs) is a set of APIs for monitoring what's happening in your [Enterprise Grid](https://api.slack.com/enterprise/grid) organization.
3+
The [Audit Logs API](https://docs.slack.dev/admins/audit-logs-api) is a set of APIs that you can use to monitor what's happening in your [Enterprise Grid](https://docs.slack.dev/enterprise-grid) organization.
44

5-
The Audit Logs API can be used by security information and event management (SIEM) tools to provide an analysis of how your Slack organization is being accessed. You can also use this API to write your own applications to see how members of your organization are using Slack.
5+
The Audit Logs API can be used by Security Information and Event Management (SIEM) tools to provide an analysis of how your Slack organization is being accessed. You can also use this API to write your own apps to see how members of your organization are using Slack.
66

7-
Follow the instructions in [the API document](https://api.slack.com/admins/audit-logs) to get a valid token for using Audit Logs API. The Slack app using the Audit Logs API needs to be installed in the Enterprise Grid Organization, not an individual workspace within the organization.
7+
You'll need a valid token in order to use the Audit Logs API. In addition, the Slack app using the Audit Logs API needs to be installed in the Enterprise Grid organization, not an individual workspace within the organization.
88

99
---
1010

11-
## AuditLogsClient
11+
## AuditLogsClient {#auditlogsclient}
1212

13-
An OAuth token with [the admin
14-
scope](https://api.slack.com/scopes/admin) is required to access this
15-
API.
13+
An OAuth token with [the admin scope](https://docs.slack.dev/reference/scopes/admin) is required to access this API.
1614

17-
You will likely use the `/logs` endpoint as it's the essential part of
18-
this API.
15+
You'll likely use the `/logs` endpoint as it's the essential part of this API.
1916

20-
To learn about the available parameters for this endpoint, check out
21-
[this
22-
guide](https://api.slack.com/admins/audit-logs#how_to_call_the_audit_logs_api).
23-
You can also learn more about the data structure of
24-
`api_response.typed_body` from [the class source
25-
code](https://github.com/slackapi/python-slack-sdk/blob/main/slack_sdk/audit_logs/v1/logs.py).
17+
To learn about the available parameters for this endpoint, check out [using the Audit Logs API](https://docs.slack.dev/admins/audit-logs-api). You can also learn more about the data structure of `api_response.typed_body` from [the class source code](https://github.com/slackapi/python-slack-sdk/blob/main/slack_sdk/audit_logs/v1/logs.py).
2618

2719
``` python
2820
import os
@@ -42,10 +34,9 @@ api_response = client.schemas()
4234
api_response = client.actions()
4335
```
4436

45-
## AsyncAuditLogsClient
37+
## AsyncAuditLogsClient {#asyncauditlogsclient}
4638

47-
If you are keen to use asyncio for SCIM API calls, we offer
48-
AsyncSCIMClient for it. This client relies on aiohttp library.
39+
If you are keen to use asyncio for SCIM API calls, we offer AsyncSCIMClient for it. This client relies on aiohttp library.
4940

5041
``` python
5142
from slack_sdk.audit_logs.async_client import AsyncAuditLogsClient
@@ -57,18 +48,11 @@ api_response.typed_body # slack_sdk.audit_logs.v1.LogsResponse
5748

5849
---
5950

60-
## RetryHandler
51+
## RetryHandler {#retryhandler}
6152

62-
With the default settings, only `ConnectionErrorRetryHandler` with its
63-
default configuration (=only one retry in the manner of [exponential
64-
backoff and
65-
jitter](https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/))
66-
is enabled. The retry handler retries if an API client encounters a
67-
connectivity-related failure (e.g., Connection reset by peer).
53+
With the default settings, only `ConnectionErrorRetryHandler` with its default configuration (=only one retry in the manner of [exponential backoff and jitter](https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/)) is enabled. The retry handler retries if an API client encounters a connectivity-related failure (e.g., connection reset by peer).
6854

69-
To use other retry handlers, you can pass a list of `RetryHandler` to
70-
the client constructor. For instance, you can add the built-in
71-
`RateLimitErrorRetryHandler` this way:
55+
To use other retry handlers, you can pass a list of `RetryHandler` to the client constructor. For instance, you can add the built-in `RateLimitErrorRetryHandler` this way:
7256

7357
``` python
7458
import os
@@ -83,11 +67,7 @@ rate_limit_handler = RateLimitErrorRetryHandler(max_retry_count=1)
8367
client.retry_handlers.append(rate_limit_handler)
8468
```
8569

86-
Creating your own ones is also quite simple. Defining a new class that
87-
inherits `slack_sdk.http_retry.RetryHandler` (`AsyncRetryHandler` for
88-
asyncio apps) and implements required methods (internals of `can_retry`
89-
/ `prepare_for_next_retry`). Check the built-in ones' source code for
90-
learning how to properly implement.
70+
You can also create one on your own by defining a new class that inherits `slack_sdk.http_retry RetryHandler` (`AsyncRetryHandler` for asyncio apps) and implements required methods (internals of `can_retry` / `prepare_for_next_retry`). Check out the source code for the ones that are built in to learn how to properly implement them.
9171

9272
``` python
9373
import socket
@@ -120,10 +100,4 @@ client = AuditLogsClient(
120100
)
121101
```
122102

123-
For asyncio apps, `Async` prefixed corresponding modules are available.
124-
All the methods in those methods are async/await compatible. Check [the
125-
source
126-
code](https://github.com/slackapi/python-slack-sdk/blob/main/slack_sdk/http_retry/async_handler.py)
127-
and
128-
[tests](https://github.com/slackapi/python-slack-sdk/blob/main/tests/slack_sdk_async/web/test_async_web_client_http_retry.py)
129-
for more details.
103+
For asyncio apps, `Async` prefixed corresponding modules are available. All the methods in those methods are async/await compatible. Check [the source code](https://github.com/slackapi/python-slack-sdk/blob/main/slack_sdk/http_retry/async_handler.py) for more details.

docs/content/index.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Python Slack SDK
22

3-
The Slack Python SDK has corresponding package for Slack APIs. They are small and powerful when used independently, and work seamlessly when used together, too.
3+
The Slack Python SDK has corresponding packages for Slack APIs. They are small and powerful when used independently, and work seamlessly when used together, too.
44

5-
The Slack platform offers several APIs to build apps. Each Slack API delivers part of the capabilities from the platform, so that you can pick just those that fit for your needs.
5+
The Slack platform offers several APIs to build apps. Each Slack API delivers part of the capabilities from the platform, so that you can pick just those that fit your needs.
66

7-
## Features
7+
## Features {#features}
88

99
| Feature | Use | Package |
1010
|--------------------------------|----------|-------|
@@ -20,17 +20,17 @@ The Slack platform offers several APIs to build apps. Each Slack API delivers pa
2020

2121
You can also view the [Python module documents](https://tools.slack.dev/python-slack-sdk/api-docs/slack_sdk/)!
2222

23-
## Getting help
23+
## Getting help {#getting-help}
2424

2525
These docs have lots of information on the Python Slack SDK. There's also an in-depth Reference section. Please explore!
2626

27-
If you otherwise get stuck, we're here to help. The following are the best ways to get assistance working through your issue:
27+
If you get stuck, we're here to help. The following are the best ways to get assistance working through your issue:
2828

2929
* [Issue Tracker](http://github.com/slackapi/python-slack-sdk/issues) for questions, bug reports, feature requests, and general discussion related to the Python Slack SDK. Try searching for an existing issue before creating a new one.
3030
* [Email](mailto:[email protected]) our developer support team: `[email protected]`.
3131

32-
## Contributing
32+
## Contributing {#contributing}
3333

3434
These docs live within the [Python Slack SDK](https://github.com/slackapi/python-slack-sdk) repository and are open source.
3535

36-
We welcome contributions from everyone! Please check out our [Contributor's Guide](https://github.com/slackapi/python-slack-sdk/blob/main/.github/contributing.md) for how to contribute in a helpful and collaborative way.
36+
We welcome contributions from everyone! Please check out our [Contributor's Guide](https://github.com/slackapi/python-slack-sdk/blob/main/.github/contributing.md) for how to contribute in a helpful and collaborative way.

docs/content/installation.md

Lines changed: 29 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
# Installation
22

3-
This package supports Python 3.6 and higher. We recommend using [PyPI](https://pypi.python.org/pypi) to install. Run the following command:
3+
This package supports Python 3.6 and higher. We recommend using [PyPI](https://pypi.python.org/pypi) for installation. Run the following command:
44

55
```bash
66
pip install slack_sdk
77
```
88

9-
Alternatively, you can always pull the source code directly into your
10-
project:
9+
Alternatively, you can always pull the source code directly into your project:
1110

1211
```bash
1312
git clone https://github.com/slackapi/python-slack-sdk.git
@@ -40,24 +39,13 @@ python test.py
4039

4140
It's also good to try on the Python REPL.
4241

43-
## Access Tokens {#handling-tokens}
42+
## Access tokens {#handling-tokens}
4443

45-
Making calls to the Slack API often requires a [token](https://docs.slack.dev/authentication/tokens) with associated scopes that grant access to resources.
46-
47-
Collecting a token can be done from app settings or with an OAuth installation depending on your app's requirements:
48-
49-
- [Single Workspace Install](#single-workspace-install)
50-
- [Multiple Workspace Install](#multiple-workspace-install)
44+
Making calls to the Slack API often requires a [token](https://docs.slack.dev/authentication/tokens) with associated scopes that grant access to resources. Collecting a token can be done from app settings or with an OAuth installation depending on your app's requirements.
5145

5246
**Always keep your access tokens safe.**
5347

54-
The OAuth token you use to call the Slack API has access to the data on
55-
the workspace where it is installed.
56-
57-
Depending on the scopes granted to the token, it potentially has the
58-
ability to read and write data. Treat these tokens just as you would a
59-
password — don't publish them, don't check them into source code, and
60-
don't share them with others.
48+
The OAuth token you use to call the Slack Web API has access to the data on the workspace where it is installed. Depending on the scopes granted to the token, it potentially has the ability to read and write data. Treat these tokens just as you would a password — don't publish them, don't check them into source code, and don't share them with others.
6149

6250
:::danger
6351

@@ -69,51 +57,34 @@ token = 'xoxb-111-222-xxxxx'
6957

7058
:::
7159

72-
We recommend you pass tokens in as environment variables, or persist
73-
them in a database that is accessed at runtime. You can add a token to
74-
the environment by starting your app as:
60+
We recommend you pass tokens in as environment variables, or store them in a database that is accessed at runtime. You can add a token to the environment by starting your app as follows:
7561

7662
```python
7763
SLACK_BOT_TOKEN="xoxb-111-222-xxxxx" python myapp.py
7864
```
7965

80-
Then retrieve the key with:
66+
Then, retrieve the key as follows:
8167

8268
```python
8369
import os
8470
SLACK_BOT_TOKEN = os.environ["SLACK_BOT_TOKEN"]
8571
```
8672

87-
For additional information, please see the [Safely Storing
88-
Credentials](https://api.slack.com/authentication/best-practices) page within the Slack API docs.
73+
Refer to our [best practices for security](https://docs.slack.dev/authentication/best-practices-for-security) page for more information.
8974

90-
## Workspace Installations
75+
## Installing on a single workspace {#single-workspace}
9176

92-
### Single Workspace Install
77+
If you're building an application for a single Slack workspace, there's no need to build out the entire OAuth flow. Once you've set up your features, click the **Install App to Team** button on the **Install App** page. If you add new permission scopes or Slack app features after an app has been installed, you must reinstall the app to your workspace for the changes to take effect.
9378

94-
If you're building an application for a single Slack workspace, there's no need to build out the entire OAuth flow.
79+
Refer to the [quickstart](https://docs.slack.dev/quickstart) guide for more details.
9580

96-
After [creating an app](https://api.slack.com/apps?new_app=1) and adding [scopes](http://docs.slack.dev/reference/scopes) on the **OAuth & Permissions** page, go to the **Install App** page and click the **Install to Team** button to authorize the app and generate a token.
81+
## Installing on multiple workspaces {#multi-workspace}
9782

98-
If you add new permission scopes or Slack app features after an app has been installed, you must reinstall the app to your workspace for changes to take effect.
83+
If you intend for an app to be installed on multiple Slack workspaces, you will need to handle this installation via the industry-standard OAuth protocol. Read more about [installing with OAuth](https://docs.slack.dev/authentication/installing-with-oauth).
9984

100-
## Multiple Workspace Install
85+
The OAuth exchange is facilitated via HTTP and requires a webserver; in this example, we'll use [Flask](https://flask.palletsprojects.com/).
10186

102-
If you intend for an app to be installed on multiple Slack workspaces,
103-
you will need to handle this installation via the industry-standard
104-
OAuth protocol. You can read more about [how Slack handles
105-
Oauth](https://api.slack.com/authentication/oauth-v2).
106-
107-
(The OAuth exchange is facilitated via HTTP and requires a webserver; in
108-
this example, we'll use [Flask](https://flask.palletsprojects.com/).)
109-
110-
To configure your app for OAuth, you'll need a client ID, a client
111-
secret, and a set of one or more scopes that will be applied to the
112-
token once it is granted. The client ID and client secret are available
113-
from your [app's configuration page](https://api.slack.com/apps). The
114-
scopes are determined by the functionality of the app — every method
115-
you wish to access has a corresponding scope and your app will need to
116-
request that scope in order to be able to access the method. Review the [full list of Slack OAuth scopes](http://docs.slack.dev/reference/scopes).
87+
To configure your app for OAuth, you'll need a client ID, a client secret, and a set of one or more scopes that will be applied to the token once it is granted. The client ID and client secret are available from the [app page](https://api.slack.com/apps). The scopes are determined by the functionality of the app — every method you wish to access has a corresponding scope, and your app will need to request that scope in order to be able to access the method. Review the full list of [OAuth scopes](https://docs.slack.dev/reference/scopes).
11788

11889
```python
11990
import os
@@ -127,18 +98,12 @@ oauth_scope = os.environ["SLACK_SCOPES"]
12798
app = Flask(__name__)
12899
```
129100

130-
### The OAuth initiation link
101+
### The OAuth initiation link {#oauth-link}
131102

132-
To begin the OAuth flow that will install your app on a workspace,
133-
you'll need to provide the user with a link to the Slack OAuth page.
134-
This can be a simple link to `https://slack.com/oauth/v2/authorize` with
135-
`scope` and `client_id` query parameters, or you can use our pre-built
136-
[Add to Slack button](https://api.slack.com/docs/slack-button) to do all
137-
the work for you.
103+
To begin the OAuth flow that will install your app on a workspace, you'll need to provide the user with a link to the Slack OAuth page. This can be a simple link to `https://slack.com/oauth/v2/authorize` with the
104+
`scope` and `client_id` query parameters.
138105

139-
This link directs the user to the Slack OAuth acceptance page, where the
140-
user will review and accept or refuse the permissions your app is
141-
requesting as defined by the scope(s).
106+
This link directs the user to the OAuth acceptance page, where the user will review and accept or decline the permissions your app is requesting as defined by the scope(s).
142107

143108
```python
144109
@app.route("/slack/install", methods=["GET"])
@@ -149,14 +114,9 @@ def pre_install():
149114
'Add to Slack</a>'
150115
```
151116

152-
### The OAuth completion page
117+
### The OAuth completion page {#oauth-completion}
153118

154-
Once the user has agreed to the permissions you've requested, Slack
155-
will redirect the user to your auth completion page, which includes a
156-
`code` query string param. You'll use the `code` param to call the
157-
`oauth.v2.access`
158-
[endpoint](https://api.slack.com/methods/oauth.v2.access) that will
159-
finally grant you the token.
119+
Once the user has agreed to the permissions you've requested, Slack will redirect the user to your auth completion page, which includes a `code` query string parameter. You'll use the `code` parameter to call the [`oauth.v2.access`](https://docs.slack.dev/reference/methods/oauth.v2.access) API method that will grant you the token.
160120

161121
```python
162122
@app.route("/slack/oauth_redirect", methods=["GET"])
@@ -177,8 +137,7 @@ def post_install():
177137
)
178138
```
179139

180-
A successful request to `oauth.v2.access` will yield a JSON payload with
181-
at least one token, a bot token that begins with `xoxb`.
140+
A successful request to the `oauth.v2.access` API method will yield a JSON payload with at least one token: a bot token that begins with `xoxb`.
182141

183142
```python
184143
@app.route("/slack/oauth_redirect", methods=["GET"])
@@ -210,14 +169,13 @@ if __name__ == "__main__":
210169
app.run("localhost", 3000)
211170
```
212171

213-
Once your user has completed the OAuth flow, you'll be able to use the
214-
provided tokens to call any of the Slack API methods that require an
215-
access token.
172+
Once your user has completed the OAuth flow, you'll be able to use the provided tokens to call any of the Slack Web API methods that require an access token.
173+
174+
Refer to the [basic usage](https://tools.slack.dev/python-slack-sdk/legacy/basic_usage) page for more examples.
216175

217-
## Installation Troubleshooting
176+
## Installation troubleshooting {#troubleshooting}
218177

219-
We recommend using [virtualenv
220-
(venv)](https://docs.python.org/3/tutorial/venv.html) to set up your
178+
We recommend using [virtualenv (venv)](https://docs.python.org/3/tutorial/venv.html) to set up your
221179
Python runtime.
222180

223181
```bash
@@ -234,8 +192,7 @@ pip install "slack_sdk>=3.0"
234192
export SLACK_BOT_TOKEN=xoxb-***
235193
```
236194

237-
Then, verify the following code works on the Python REPL (you can start
238-
it by just `python`).
195+
Then, verify the following code works on the Python REPL:
239196

240197
```python
241198
import os
@@ -246,9 +203,4 @@ client = WebClient(token=os.environ["SLACK_BOT_TOKEN"])
246203
res = client.api_test()
247204
```
248205

249-
As the `slack` package is deprecated, we recommend switching to `slack_sdk`
250-
package. That being said, the code you're working on may be still using
251-
the old package. If you encounter an error saying
252-
`AttributeError: module 'slack' has no attribute 'WebClient'`, run
253-
`pip list`. If you find both `slack_sdk` and `slack` in the output, try
254-
removing `slack` by `pip uninstall slack` and reinstalling `slack_sdk`.
206+
As the `slack` package is deprecated, we recommend switching to `slack_sdk` package. That being said, the code you're working on may be still using the old package. If you encounter an error saying `AttributeError: module 'slack' has no attribute 'WebClient'`, run `pip list`. If you find both `slack_sdk` and `slack` in the output, try removing `slack` by `pip uninstall slack` and reinstalling `slack_sdk`.

0 commit comments

Comments
 (0)