httpx icon indicating copy to clipboard operation
httpx copied to clipboard

How can I limit the number of requests made per second?

Open Midnighter opened this issue 5 years ago • 26 comments
trafficstars

In this comment @florimondmanca suggests that the connection pool limits can be used to rate-limit the number of requests made. I can see, of course, how setting those limits will constrain the number of 'concurrent' requests made by httpx. However, what if I want to limit the number of requests made per unit of time?

Say the API I'm hitting allows 10 requests per second, I guess a naive approach would be to set the hard limit of the connection pool to 10 and asyncio.sleep 1/10 s after every request. Does that sound about right or am I missing something obvious?

Midnighter avatar Feb 13 '20 17:02 Midnighter