Skip to content

Commit aa5cba6

Browse files
Filip Majfilmaj
authored andcommitted
Add more documentation around contructor parameters for client, async_client and legacy_client as well as their base classes. In particular focusing on documenting the proxy and ssl parameters (relates to #1214).
1 parent da8c0a1 commit aa5cba6

File tree

6 files changed

+95
-9
lines changed

6 files changed

+95
-9
lines changed

slack_sdk/web/async_base_client.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,35 @@ def __init__(
4444
retry_handlers: Optional[List[RetryHandler]] = None,
4545
):
4646
self.token = None if token is None else token.strip()
47+
"""A string specifying an `xoxp-*` or `xoxb-*` token."""
4748
self.base_url = base_url
49+
"""A string representing the Slack API base URL.
50+
Default is `'https://www.slack.com/api/'`."""
4851
self.timeout = timeout
52+
"""The maximum number of seconds the client will wait
53+
to connect and receive a response from Slack.
54+
Default is 30 seconds."""
4955
self.ssl = ssl
56+
"""An [`ssl.SSLContext`](https://docs.python.org/3/library/ssl.html#ssl.SSLContext)
57+
instance, helpful for specifying your own custom
58+
certificate chain."""
5059
self.proxy = proxy
60+
"""String representing a fully-qualified URL to a proxy through which
61+
to route all requests to the Slack API. Even if this parameter
62+
is not specified, if any of the following environment variables are
63+
present, they will be loaded into this parameter: `HTTPS_PROXY`,
64+
`https_proxy`, `HTTP_PROXY` or `http_proxy`."""
5165
self.session = session
66+
"""An [`aiohttp.ClientSession`](https://docs.aiohttp.org/en/stable/client_reference.html#client-session)
67+
to attach to all outgoing requests."""
5268
# https://github.com/slackapi/python-slack-sdk/issues/738
5369
self.trust_env_in_session = trust_env_in_session
70+
"""Boolean setting whether aiohttp outgoing requests
71+
are allowed to read environment variables. Commonly used in conjunction
72+
with proxy support via the `HTTPS_PROXY`, `https_proxy`, `HTTP_PROXY` and
73+
`http_proxy` environment variables."""
5474
self.headers = headers or {}
75+
"""`dict` representing additional request headers to attach to all requests."""
5576
self.headers["User-Agent"] = get_user_agent(
5677
user_agent_prefix, user_agent_suffix
5778
)

slack_sdk/web/async_client.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,28 @@ class AsyncWebClient(AsyncBaseClient):
3939
as well as parsing any responses received into a `SlackResponse`.
4040
4141
Attributes:
42-
token (str): A string specifying an xoxp or xoxb token.
42+
token (str): A string specifying an `xoxp-*` or `xoxb-*` token.
4343
base_url (str): A string representing the Slack API base URL.
44-
Default is 'https://www.slack.com/api/'
44+
Default is `'https://www.slack.com/api/'`
4545
timeout (int): The maximum number of seconds the client will wait
4646
to connect and receive a response from Slack.
4747
Default is 30 seconds.
48+
ssl (SSLContext): An [`ssl.SSLContext`][1] instance, helpful for specifying
49+
your own custom certificate chain.
50+
proxy (str): String representing a fully-qualified URL to a proxy through
51+
which to route all requests to the Slack API. Even if this parameter
52+
is not specified, if any of the following environment variables are
53+
present, they will be loaded into this parameter: `HTTPS_PROXY`,
54+
`https_proxy`, `HTTP_PROXY` or `http_proxy`.
55+
session (ClientSession): [`aiohttp.ClientSession`][2] to attach to all outgoing requests.
56+
trust_env_in_session (bool): Boolean setting whether aiohttp outgoing requests
57+
are allowed to read environment variables. Commonly used in conjunction
58+
with proxy support via the `HTTPS_PROXY`, `https_proxy`, `HTTP_PROXY` and
59+
`http_proxy` environment variables.
60+
headers (dict): Additional request headers to attach to all requests.
4861
4962
Methods:
50-
api_call: Constructs a request and executes the API call to Slack.
63+
`api_call`: Constructs a request and executes the API call to Slack.
5164
5265
Example of recommended usage:
5366
```python
@@ -80,6 +93,9 @@ class AsyncWebClient(AsyncBaseClient):
8093
Any attributes or methods prefixed with _underscores are
8194
intended to be "private" internal use only. They may be changed or
8295
removed at anytime.
96+
97+
[1]: https://docs.python.org/3/library/ssl.html#ssl.SSLContext
98+
[2]: https://docs.aiohttp.org/en/stable/client_reference.html#client-session
8399
"""
84100

85101
async def admin_analytics_getFile(

slack_sdk/web/base_client.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,26 @@ def __init__(
5757
retry_handlers: Optional[List[RetryHandler]] = None,
5858
):
5959
self.token = None if token is None else token.strip()
60+
"""A string specifying an `xoxp-*` or `xoxb-*` token."""
6061
self.base_url = base_url
62+
"""A string representing the Slack API base URL.
63+
Default is `'https://www.slack.com/api/'`."""
6164
self.timeout = timeout
65+
"""The maximum number of seconds the client will wait
66+
to connect and receive a response from Slack.
67+
Default is 30 seconds."""
6268
self.ssl = ssl
69+
"""An [`ssl.SSLContext`](https://docs.python.org/3/library/ssl.html#ssl.SSLContext)
70+
instance, helpful for specifying your own custom
71+
certificate chain."""
6372
self.proxy = proxy
73+
"""String representing a fully-qualified URL to a proxy through which
74+
to route all requests to the Slack API. Even if this parameter
75+
is not specified, if any of the following environment variables are
76+
present, they will be loaded into this parameter: `HTTPS_PROXY`,
77+
`https_proxy`, `HTTP_PROXY` or `http_proxy`."""
6478
self.headers = headers or {}
79+
"""`dict` representing additional request headers to attach to all requests."""
6580
self.headers["User-Agent"] = get_user_agent(
6681
user_agent_prefix, user_agent_suffix
6782
)

slack_sdk/web/client.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,23 @@ class WebClient(BaseClient):
3030
as well as parsing any responses received into a `SlackResponse`.
3131
3232
Attributes:
33-
token (str): A string specifying an xoxp or xoxb token.
33+
token (str): A string specifying an `xoxp-*` or `xoxb-*` token.
3434
base_url (str): A string representing the Slack API base URL.
35-
Default is 'https://www.slack.com/api/'
35+
Default is `'https://www.slack.com/api/'`
3636
timeout (int): The maximum number of seconds the client will wait
3737
to connect and receive a response from Slack.
3838
Default is 30 seconds.
39+
ssl (SSLContext): An [`ssl.SSLContext`][1] instance, helpful for specifying
40+
your own custom certificate chain.
41+
proxy (str): String representing a fully-qualified URL to a proxy through
42+
which to route all requests to the Slack API. Even if this parameter
43+
is not specified, if any of the following environment variables are
44+
present, they will be loaded into this parameter: `HTTPS_PROXY`,
45+
`https_proxy`, `HTTP_PROXY` or `http_proxy`.
46+
headers (dict): Additional request headers to attach to all requests.
3947
4048
Methods:
41-
api_call: Constructs a request and executes the API call to Slack.
49+
`api_call`: Constructs a request and executes the API call to Slack.
4250
4351
Example of recommended usage:
4452
```python
@@ -71,6 +79,8 @@ class WebClient(BaseClient):
7179
Any attributes or methods prefixed with _underscores are
7280
intended to be "private" internal use only. They may be changed or
7381
removed at anytime.
82+
83+
[1]: https://docs.python.org/3/library/ssl.html#ssl.SSLContext
7484
"""
7585

7686
def admin_analytics_getFile(

slack_sdk/web/legacy_base_client.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,29 @@ def __init__(
5959
logger: Optional[logging.Logger] = None,
6060
):
6161
self.token = None if token is None else token.strip()
62+
"""A string specifying an `xoxp-*` or `xoxb-*` token."""
6263
self.base_url = base_url
64+
"""A string representing the Slack API base URL.
65+
Default is `'https://www.slack.com/api/'`."""
6366
self.timeout = timeout
67+
"""The maximum number of seconds the client will wait
68+
to connect and receive a response from Slack.
69+
Default is 30 seconds."""
6470
self.ssl = ssl
71+
"""An [`ssl.SSLContext`](https://docs.python.org/3/library/ssl.html#ssl.SSLContext)
72+
instance, helpful for specifying your own custom
73+
certificate chain."""
6574
self.proxy = proxy
75+
"""String representing a fully-qualified URL to a proxy through which
76+
to route all requests to the Slack API. Even if this parameter
77+
is not specified, if any of the following environment variables are
78+
present, they will be loaded into this parameter: `HTTPS_PROXY`,
79+
`https_proxy`, `HTTP_PROXY` or `http_proxy`."""
6680
self.run_async = run_async
6781
self.use_sync_aiohttp = use_sync_aiohttp
6882
self.session = session
6983
self.headers = headers or {}
84+
"""`dict` representing additional request headers to attach to all requests."""
7085
self.headers["User-Agent"] = get_user_agent(
7186
user_agent_prefix, user_agent_suffix
7287
)

slack_sdk/web/legacy_client.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,24 @@ class LegacyWebClient(LegacyBaseClient):
4141
as well as parsing any responses received into a `SlackResponse`.
4242
4343
Attributes:
44-
token (str): A string specifying an xoxp or xoxb token.
44+
token (str): A string specifying an `xoxp-*` or `xoxb-*` token.
4545
base_url (str): A string representing the Slack API base URL.
46-
Default is 'https://www.slack.com/api/'
46+
Default is `'https://www.slack.com/api/'`
4747
timeout (int): The maximum number of seconds the client will wait
4848
to connect and receive a response from Slack.
4949
Default is 30 seconds.
50+
ssl (SSLContext): An [`ssl.SSLContext`](https://docs.python.org/3/library/ssl.html#ssl.SSLContext)
51+
instance, helpful for specifying your own custom certificate
52+
chain.
53+
proxy (str): String representing a fully-qualified URL to a proxy through
54+
which to route all requests to the Slack API. Even if this parameter
55+
is not specified, if any of the following environment variables are
56+
present, they will be loaded into this parameter: `HTTPS_PROXY`,
57+
`https_proxy`, `HTTP_PROXY` or `http_proxy`.
58+
headers (dict): Additional request headers to attach to all requests.
5059
5160
Methods:
52-
api_call: Constructs a request and executes the API call to Slack.
61+
`api_call`: Constructs a request and executes the API call to Slack.
5362
5463
Example of recommended usage:
5564
```python

0 commit comments

Comments
 (0)