Skip to content

Commit eb44ff6

Browse files
authored
fix: Update README / docstring for Authenticating Client (#684)
1 parent a6f6aa8 commit eb44ff6

File tree

2 files changed

+32
-21
lines changed

2 files changed

+32
-21
lines changed

README.md

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,26 @@ Getting started with the Twilio API couldn't be easier. Create a
5858

5959
### API Credentials
6060

61-
The `Twilio` needs your Twilio credentials. You can either pass these
61+
The `Twilio` client needs your Twilio credentials. You can either pass these
6262
directly to the constructor (see the code below) or via environment variables.
6363

64+
Authenticating with Account SID and Auth Token:
6465
```python
6566
from twilio.rest import Client
6667

67-
account = "ACXXXXXXXXXXXXXXXXX"
68-
token = "YYYYYYYYYYYYYYYYYY"
69-
client = Client(account, token)
68+
account_sid = "ACXXXXXXXXXXXXXXXXX"
69+
auth_token = "YYYYYYYYYYYYYYYYYY"
70+
client = Client(account_sid, auth_token)
71+
```
72+
73+
Authenticating with API Key and API Secret:
74+
```python
75+
from twilio.rest import Client
76+
77+
api_key = "XXXXXXXXXXXXXXXXX"
78+
api_secret = "YYYYYYYYYYYYYYYYYY"
79+
account_sid = "ACXXXXXXXXXXXXXXXXX"
80+
client = Client(api_key, api_secret, account_sid)
7081
```
7182

7283
Alternatively, a `Client` constructor without these parameters will
@@ -111,9 +122,9 @@ This will result in the `hostname` transforming from `api.twilio.com` to `api.sy
111122
```python
112123
from twilio.rest import Client
113124

114-
account = "ACXXXXXXXXXXXXXXXXX"
115-
token = "YYYYYYYYYYYYYYYYYY"
116-
client = Client(account, token)
125+
username = "ACXXXXXXXXXXXXXXXXX"
126+
password = "YYYYYYYYYYYYYYYYYY"
127+
client = Client(username, password)
117128

118129
call = client.calls.create(to="9991231234",
119130
from_="9991231234",
@@ -126,9 +137,9 @@ print(call.sid)
126137
```python
127138
from twilio.rest import Client
128139

129-
account = "ACXXXXXXXXXXXXXXXXX"
130-
token = "YYYYYYYYYYYYYYYYYY"
131-
client = Client(account, token)
140+
username = "ACXXXXXXXXXXXXXXXXX"
141+
password = "YYYYYYYYYYYYYYYYYY"
142+
client = Client(username, password)
132143

133144
message = client.messages.create(to="+12316851234", from_="+15555555555",
134145
body="Hello there!")
@@ -143,10 +154,10 @@ from twilio.http.async_http_client import AsyncTwilioHttpClient
143154
from twilio.rest import Client
144155

145156
async def main():
146-
account = "ACXXXXXXXXXXXXXXXXX"
147-
token = "YYYYYYYYYYYYYYYYYY"
157+
username = "ACXXXXXXXXXXXXXXXXX"
158+
password = "YYYYYYYYYYYYYYYYYY"
148159
http_client = AsyncTwilioHttpClient()
149-
client = Client(account, token, http_client=http_client)
160+
client = Client(username, password, http_client=http_client)
150161

151162
message = await client.messages.create_async(to="+12316851234", from_="+15555555555",
152163
body="Hello there!")
@@ -161,7 +172,7 @@ Log the API request and response data to the console:
161172
```python
162173
import logging
163174

164-
client = Client(account, token)
175+
client = Client(username, password)
165176
logging.basicConfig()
166177
client.http_client.logger.setLevel(logging.INFO)
167178
```
@@ -171,7 +182,7 @@ Log the API request and response data to a file:
171182
```python
172183
import logging
173184

174-
client = Client(account, token)
185+
client = Client(username, password)
175186
logging.basicConfig(filename='./log.txt')
176187
client.http_client.logger.setLevel(logging.INFO)
177188
```
@@ -182,9 +193,9 @@ client.http_client.logger.setLevel(logging.INFO)
182193
from twilio.rest import Client
183194
from twilio.base.exceptions import TwilioRestException
184195

185-
account = "ACXXXXXXXXXXXXXXXXX"
186-
token = "YYYYYYYYYYYYYYYYYY"
187-
client = Client(account, token)
196+
username = "ACXXXXXXXXXXXXXXXXX"
197+
password = "YYYYYYYYYYYYYYYYYY"
198+
client = Client(username, password)
188199

189200
try:
190201
message = client.messages.create(to="+12316851234", from_="+15555555555",

twilio/rest/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ def __init__(
2828
"""
2929
Initializes the Twilio Client
3030
31-
:param str username: Username to authenticate with
32-
:param str password: Password to authenticate with
33-
:param str account_sid: Account SID, defaults to Username
31+
:param str username: Username to authenticate with, either account_sid or api_key
32+
:param str password: Password to authenticate with, auth_token (if using account_sid) or api_secret (if using api_key)
33+
:param str account_sid: Account SID, required if using api_key to authenticate.
3434
:param str region: Twilio Region to make requests to, defaults to 'us1' if an edge is provided
3535
:param HttpClient http_client: HttpClient, defaults to TwilioHttpClient
3636
:param dict environment: Environment to look for auth details, defaults to os.environ

0 commit comments

Comments
 (0)