RequestsThrottler is an Apache2 Licensed HTTP library, written in Python, and powered by futures and Requests. See the full documentation.
With RequestsThrottler you can easily throttle HTTP requests! After having created your throttler with a delay of your choice, you just have to:
- Start the throttler
- Submit your requests
- Shutdown the throttler
Here's an example:
import requests
from requests_throttler import BaseThrottler
bt = BaseThrottler(name='base-throttler', delay=1.5)
request = requests.Request(method='GET', url='http://www.google.com')
reqs = [request for i in range(0, 5)]
bt.start()
throttled_requests = bt.multi_submit(reqs)
bt.shutdown()
responses = [tr.response for tr in throttled_requests]
Too hard? Then just submit your requests inside a with statement! Here's an example:
import requests
from requests_throttler import BaseThrottler
with BaseThrottler(name='base-throttler', delay=1.5) as bt:
request = requests.Request(method='GET', url='http://www.google.com')
reqs = [request for i in range(0, 5)]
throttled_requests = bt.multi_submit(reqs)
responses = [tr.response for tr in throttled_requests]
Use pip
to install RequestsThrottler:
$ pip install RequestsThrottler
BaseThrottler
a simple throttler with a fixed amount of delay