Skip to content

Commit fcc9832

Browse files
authored
Merge pull request #6 from AgarFu/master
Use requests sessions to improve performance
2 parents dc278e6 + 1242f93 commit fcc9832

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

akamai/netstorage/netstorage.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def __init__(self, hostname, keyname, key, ssl=False):
4747
self.keyname = keyname
4848
self.key = key
4949
self.ssl = 's' if ssl else ''
50+
self.http_client = requests.Session()
5051

5152

5253
def _download_data_from_response(self, response, ns_path, local_destination, chunk_size=16*1024):
@@ -105,21 +106,21 @@ def _request(self, **kwargs):
105106
response = None
106107
if kwargs['method'] == 'GET':
107108
if kwargs['action'] == 'download':
108-
response = requests.get(request_url, headers=headers, stream=True)
109+
response = self.http_client.get(request_url, headers=headers, stream=True)
109110
if 'stream' not in kwargs.keys():
110111
self._download_data_from_response(response, kwargs['path'], kwargs['destination'])
111112
else:
112-
response = requests.get(request_url, headers=headers)
113+
response = self.http_client.get(request_url, headers=headers)
113114

114115
elif kwargs['method'] == 'POST':
115-
response = requests.post(request_url, headers=headers)
116+
response = self.http_client.post(request_url, headers=headers)
116117

117118
elif kwargs['method'] == 'PUT': # Use only upload
118119
if 'stream' in kwargs.keys():
119-
response = requests.put(request_url, headers=headers, data=kwargs['stream'])
120+
response = self.http_client.put(request_url, headers=headers, data=kwargs['stream'])
120121
elif kwargs['action'] == 'upload':
121122
mmapped_data = self._upload_data_to_request(kwargs['source'])
122-
response = requests.put(request_url, headers=headers, data=mmapped_data)
123+
response = self.http_client.put(request_url, headers=headers, data=mmapped_data)
123124
mmapped_data.close()
124125

125126
return response.status_code == 200, response
@@ -210,4 +211,4 @@ def stream_upload(self, data, ns_destination):
210211
return self._request(action='upload',
211212
method='PUT',
212213
stream=data,
213-
path=ns_destination)
214+
path=ns_destination)

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
setup (
1010
name = 'netstorageapi',
11-
version = '1.2.8',
11+
version = '1.2.9',
1212
description = 'Akamai Netstorage API for Python',
1313
long_description = readme,
1414
namespace_packages=['akamai'],
@@ -33,4 +33,4 @@
3333
'Programming Language :: Python :: Implementation :: CPython',
3434
'Programming Language :: Python :: Implementation :: PyPy'
3535
),
36-
)
36+
)

0 commit comments

Comments
 (0)