22
33This package supports Python 3.6 and higher. We recommend using [ PyPI] ( https://pypi.python.org/pypi ) to install. Run the following command:
44
5- ``` bash
5+ ``` bash
66pip install slack_sdk
77```
88
99Alternatively, you can always pull the source code directly into your
1010project:
1111
12- ``` bash
12+ ``` bash
1313git clone https://github.com/slackapi/python-slack-sdk.git
1414cd python-slack-sdk
1515python3 -m venv .venv
@@ -20,7 +20,7 @@ pip install -e . # install the SDK project into the virtual env
2020
2121Create a ` ./test.py ` file with the following:
2222
23- ``` python title="test.py"
23+ ``` python title="test.py"
2424# test.py
2525import sys
2626# Enable debug logging
@@ -34,7 +34,7 @@ api_response = client.api_test()
3434
3535Then, run the script:
3636
37- ``` bash
37+ ``` bash
3838python test.py
3939```
4040
@@ -52,12 +52,11 @@ ability to read and write data. Treat these tokens just as you would a
5252password — don't publish them, don't check them into source code, and
5353don't share them with others.
5454
55-
5655::: danger
5756
5857Never do the following:
5958
60- ``` python
59+ ``` python
6160token = ' xoxb-111-222-xxxxx'
6261```
6362
@@ -67,13 +66,13 @@ We recommend you pass tokens in as environment variables, or persist
6766them in a database that is accessed at runtime. You can add a token to
6867the environment by starting your app as:
6968
70- ``` python
69+ ``` python
7170SLACK_BOT_TOKEN = " xoxb-111-222-xxxxx" python myapp.py
7271```
7372
7473Then retrieve the key with:
7574
76- ``` python
75+ ``` python
7776import os
7877SLACK_BOT_TOKEN = os.environ[" SLACK_BOT_TOKEN" ]
7978```
@@ -111,7 +110,7 @@ scopes are determined by the functionality of the app — every method
111110you wish to access has a corresponding scope and your app will need to
112111request that scope in order to be able to access the method. Review the [ full list of Slack OAuth scopes] ( https://api.slack.com/scopes ) .
113112
114- ``` python
113+ ``` python
115114import os
116115from slack_sdk import WebClient
117116from flask import Flask, request
@@ -136,7 +135,7 @@ This link directs the user to the Slack OAuth acceptance page, where the
136135user will review and accept or refuse the permissions your app is
137136requesting as defined by the scope(s).
138137
139- ``` python
138+ ``` python
140139@app.route (" /slack/install" , methods = [" GET" ])
141140def pre_install ():
142141 state = " randomly-generated-one-time-value"
@@ -154,7 +153,7 @@ will redirect the user to your auth completion page, which includes a
154153[ endpoint] ( https://api.slack.com/methods/oauth.v2.access ) that will
155154finally grant you the token.
156155
157- ``` python
156+ ``` python
158157@app.route (" /slack/oauth_redirect" , methods = [" GET" ])
159158def post_install ():
160159 # Verify the "state" parameter
@@ -176,7 +175,7 @@ def post_install():
176175A successful request to ` oauth.v2.access ` will yield a JSON payload with
177176at least one token, a bot token that begins with ` xoxb ` .
178177
179- ``` python
178+ ``` python
180179@app.route (" /slack/oauth_redirect" , methods = [" GET" ])
181180def post_install ():
182181 # Verify the "state" parameter
@@ -216,7 +215,7 @@ We recommend using [virtualenv
216215(venv)] ( https://docs.python.org/3/tutorial/venv.html ) to set up your
217216Python runtime.
218217
219- ``` bash
218+ ``` bash
220219# Create a dedicated virtual env for running your Python scripts
221220python -m venv .venv
222221
@@ -233,7 +232,7 @@ export SLACK_BOT_TOKEN=xoxb-***
233232Then, verify the following code works on the Python REPL (you can start
234233it by just ` python ` ).
235234
236- ``` python
235+ ``` python
237236import os
238237import logging
239238from slack_sdk import WebClient
@@ -247,4 +246,4 @@ package. That being said, the code you're working on may be still using
247246the old package. If you encounter an error saying
248247` AttributeError: module 'slack' has no attribute 'WebClient' ` , run
249248` pip list ` . If you find both ` slack_sdk ` and ` slack ` in the output, try
250- removing ` slack ` by ` pip uninstall slack ` and reinstalling ` slack_sdk ` .
249+ removing ` slack ` by ` pip uninstall slack ` and reinstalling ` slack_sdk ` .
0 commit comments