
The asyncio and threading modules include a number of synchronization primitives. In particular, a Semaphore allows you to limit the number of concurrent tasks if you need to stay under some capacity constraint. However, none of the existing primitives provide for rate limiting, as in making sure there are no more than n tasks started per second. I believe this Stack Overflow question shows that adding such a primitive would be useful: https://stackoverflow.com/questions/35196974/aiohttp-set-maximum-number-of-r... The asker clearly wants rate limiting, but the answers provided limit concurrency instead. I found an excellent answer by Martijn Pieters, which includes an implementation of the leaky bucket algorithm, here https://stackoverflow.com/a/45502319/1475412 The AsyncLeakyBucket is used in exactly the same way as a Semaphore.