python - Managing calls to rate-limited API from Flask application -


i have flask application (among other things) must interact rate-limited api (i.e., cannot make more x requests api within given unit of time). however, demand flask application makes on api uneven -- demand far exceeds api allow, there's no demand minutes or hours @ time.

it's fine calls api occur asynchronously -- there's no need flask application block , wait response.

so i'm wondering how best implement this.

i'm thinking best approach have separate process fifo queue makes calls @ fixed interval (less limit rate api) -- kind of leaky-bucket algorithm.

from multiprocessing import queue  q = queue()  ...  # runs time while true:     sleep(some_time)     if q.empty() == false:        # pop data , use make api call 

but i'm not sure how set , have flask application interact queue (just pushing new requests on occur).

it seems celery (or similar) overkill.

should looking python-daemon or creating subprocess multiprocessing.queue? what's best way approach this?

i think celery best solution problem. celery does, , highly adopted python community solve issues yours.

it not overkill it's not hard setup & configure, and can read in flasks documentation itself.

thats 30 lines of code:)


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -