9951 explained code solutions for 126 technologies


python-aiohttpHow to rate limit with Python Aiohttp?


Rate limiting with Python Aiohttp can be done using the aiohttp.ClientSession.get() method. This method takes an optional limit parameter which can be used to limit the number of requests per second.

Example code

import aiohttp

async with aiohttp.ClientSession() as session:
    async with session.get('http://example.com', limit=2) as response:
        print(response.status)

Output example

200

The code above limits the number of requests to 2 per second.

Helpful links

Edit this code on GitHub