A thread safe, rate limited queue.
A rate limited wrapper for Python's thread safe queues.
Some external APIs have rate limits that allow faster-than-consecutive queries, e.g. if the rate limit is very high or the API response is quite slow. To make the most of the API, the best option is often to make API calls from multiple threads. Then you can put the requests or URLs to call in a
queue.Queue and have the threads consume the URLs as they make the calls. However, you still have to make sure that the total calls from all your threads don't exceed the rate limit, which requires some nontrivial coordination.
ratelimitqueue package extends the three built-in Python queues from from
queue package -
PriorityQueue - with configurable, rate limited counterparts. Specifically, the
get() method is rate limited across all threads so that workers can safely consume from the queue in an unlimited loop, and putting the items in the queue doesn't need to require blocking the main thread.
To get started, clone this repository and install it with
$ git clone https://github.com/JohnPaton/ratelimitqueue.git
$ cd ratelimitqueue
$ pip install .
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Hashes for ratelimitqueue-0.2.0-py3-none-any.whl