Skip to content

Commit 4f085e0

Browse files
authored
Merge pull request #24 from jhodges10/rate-limiit
Add rate limit handling
2 parents f082a94 + 5f8bfad commit 4f085e0

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

frameioclient/client.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
from .upload import FrameioUploader
21
import requests
2+
from .upload import FrameioUploader
3+
from requests.adapters import HTTPAdapter
4+
from requests.packages.urllib3.util.retry import Retry
35

46
class PaginatedResponse(object):
57
def __init__(self, results=[], page=0, page_size=0, total=0, total_pages=0):
@@ -17,6 +19,12 @@ class FrameioClient(object):
1719
def __init__(self, token, host='https://api.frame.io'):
1820
self.token = token
1921
self.host = host
22+
self.retry_strategy = Retry(
23+
total=3,
24+
backoff_factor=1,
25+
status_forcelist=[429],
26+
method_whitelist=["POST", "OPTIONS", "GET"]
27+
)
2028

2129
def _api_call(self, method, endpoint, payload={}):
2230
url = '{}/v2{}'.format(self.host, endpoint)
@@ -25,7 +33,12 @@ def _api_call(self, method, endpoint, payload={}):
2533
'Authorization': 'Bearer {}'.format(self.token)
2634
}
2735

28-
r = requests.request(
36+
adapter = HTTPAdapter(max_retries=self.retry_strategy)
37+
38+
http = requests.Session()
39+
http.mount("https://", adapter)
40+
41+
r = http.request(
2942
method,
3043
url,
3144
json=payload,
@@ -43,6 +56,7 @@ def _api_call(self, method, endpoint, payload={}):
4356
)
4457

4558
return r.json()
59+
4660
return r.raise_for_status()
4761

4862
def get_me(self):

setup.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@
55

66
setuptools.setup(
77
name='frameioclient',
8+
version='0.7.0',
89
python_requires='>=2.6, !=3.8.*, <4',
9-
version='0.6.0',
10+
install_requires=[
11+
"requests",
12+
"urllib3",
13+
],
1014
description='Client library for the Frame.io API',
1115
long_description=long_description,
1216
long_description_content_type="text/markdown",

0 commit comments

Comments
 (0)