10000 Merge branch 'master' of https://github.com/twilio/twilio-python into… · SituProbability/twilio-python@c702a8d · GitHub
[go: up one dir, main page]

Skip to content

Commit c702a8d

Browse files
committed
Merge branch 'master' of https://github.com/twilio/twilio-python into remote-get-cert
2 parents 2ee4773 + 2f0f62d commit c702a8d

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

CHANGES.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,22 @@ twilio-python Changelog
33

44
Here you can see the full list of changes between each twilio-python release.
55

6+
[2017-07-14] Version 6.5.0
7+
---------------------------
8+
- Add connection pooling. This is enabled by default and will use one Session for all requests
9+
in Client.
10+
- To disable this, you can turn this off when creating your Twilio client.
11+
```python
12+
from twilio.rest import Client
13+
from twilio.http.http_client import TwilioHttpClient
14+
15+
client = Client(
16+
username,
17+
password,
18+
http_client=TwilioHttpClient(pool_connections=False)
19+
)
20+
```
21+
622
[2017-07-12] Version 6.4.3
723
---------------------------
824
**Api**

twilio/http/http_client.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ class TwilioHttpClient(HttpClient):
88
"""
99
General purpose HTTP Client for interacting with the Twilio API
1010
"""
11+
def __init__(self, pool_connections=True):
12+
self.session = Session() if pool_connections else None
13+
1114
def request(self, method, url, params=None, data=None, headers=None, auth=None, timeout=None,
1215
allow_redirects=False):
1316
"""
@@ -26,7 +29,7 @@ def request(self, method, url, params=None, data=None, headers=None, auth=None,
2629
:return: An http response
2730
:rtype: A :class:`Response <twilio.rest.http.response.Response>` object
2831
"""
29-
session = Session()
32+
session = self.session or Session()
3033
request = Request(method.upper(), url, params=params, data=data, headers=headers, auth=auth)
3134

3235
prepped_request = session.prepare_request(request)

twilio/http/validation_client.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
class ValidationClient(HttpClient):
1616
__SIGNED_HEADERS = ['authorization', 'host']
1717

18-
def __init__(self, account_sid, api_key_sid, credential_sid, private_key):
18+
def __init__(self, account_sid, api_key_sid, credential_sid, private_key, pool_connections=True):
1919
"""
2020
Build a ValidationClient which signs requests with private_key and allows Twilio to
2121
validate request has not been tampered with.
@@ -30,6 +30,7 @@ def __init__(self, account_sid, api_key_sid, credential_sid, private_key):
3030
self.credential_sid = credential_sid
3131
self.api_key_sid = api_key_sid
3232
self.private_key = private_key
33+
self.session = Session() if pool_connections else None
3334

3435
def request(self, method, url, params=None, data=None, headers=None, auth=None, timeout=None,
3536
allow_redirects=False):
@@ -49,7 +50,7 @@ def request(self, method, url, params=None, data=None, headers=None, auth=None,
4950
:return: An http response
5051
:rtype: A :class:`Response <twilio.rest.http.response.Response>` object
5152
"""
52-
session = Session()
53+
session = self.session or Session()
5354
request = Request(method.upper(), url, params=params, data=data, headers=headers, auth=auth)
5455
prepared_request = session.prepare_request(request)
5556

0 commit comments

Comments
 (0)
0