Skip to content

Commit 936a888

Browse files
committed
Implement rate-limiting using less libraries
1 parent 1cae062 commit 936a888

2 files changed

Lines changed: 16 additions & 10 deletions

File tree

frameioclient/client.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
from .upload import FrameioUploader
2-
from ratelimit import RateLimitException
3-
from backoff import on_exception, expo
41
import requests
2+
from .upload import FrameioUploader
3+
from requests.adapters import HTTPAdapter
4+
from requests.packages.urllib3.util.retry import Retry
55

66
class PaginatedResponse(object):
77
def __init__(self, results=[], page=0, page_size=0, total=0, total_pages=0):
@@ -19,16 +19,26 @@ class FrameioClient(object):
1919
def __init__(self, token, host='https://api.frame.io'):
2020
self.token = token
2121
self.host = host
22+
self.retry_strategy = Retry(
23+
total=3,
24+
backoff_factor=1,
25+
status_forcelist=[429],
26+
method_whitelist=["POST", "OPTIONS"]
27+
)
2228

23-
@on_exception(expo, RateLimitException, max_tries=10)
2429
def _api_call(self, method, endpoint, payload={}):
2530
url = '{}/v2{}'.format(self.host, endpoint)
2631

2732
headers = {
2833
'Authorization': 'Bearer {}'.format(self.token)
2934
}
3035

31-
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(
3242
method,
3343
url,
3444
json=payload,
@@ -47,9 +57,6 @@ def _api_call(self, method, endpoint, payload={}):
4757

4858
return r.json()
4959

50-
if r.status_code == "429":
51-
raise RateLimitException
52-
5360
return r.raise_for_status()
5461

5562
def get_me(self):

setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
version='0.6.0',
1010
install_requires=[
1111
"requests",
12-
"ratelimit",
13-
"backoff",
12+
"urllib3",
1413
],
1514
description='Client library for the Frame.io API',
1615
long_description=long_description,

0 commit comments

Comments
 (0)