1GRequests: Asynchronous Requests 2=============================== 3 4GRequests allows you to use Requests with Gevent to make asynchronous HTTP 5Requests easily. 6 7 8Usage 9----- 10 11Usage is simple: 12 13.. code-block:: python 14 15 import grequests 16 17 urls = [ 18 'http://www.heroku.com', 19 'http://python-tablib.org', 20 'http://httpbin.org', 21 'http://python-requests.org', 22 'http://fakedomain/', 23 'http://kennethreitz.com' 24 ] 25 26Create a set of unsent Requests: 27 28.. code-block:: python 29 30 >>> rs = (grequests.get(u) for u in urls) 31 32Send them all at the same time: 33 34.. code-block:: python 35 36 >>> grequests.map(rs) 37 [<Response [200]>, <Response [200]>, <Response [200]>, <Response [200]>, None, <Response [200]>] 38 39Optionally, in the event of a timeout or any other exception during the connection of 40the request, you can add an exception handler that will be called with the request and 41exception inside the main thread: 42 43.. code-block:: python 44 45 >>> def exception_handler(request, exception): 46 ... print "Request failed" 47 48 >>> reqs = [ 49 ... grequests.get('http://httpbin.org/delay/1', timeout=0.001), 50 ... grequests.get('http://fakedomain/'), 51 ... grequests.get('http://httpbin.org/status/500')] 52 >>> grequests.map(reqs, exception_handler=exception_handler) 53 Request failed 54 Request failed 55 [None, None, <Response [500]>] 56 57 58Installation 59------------ 60 61Installation is easy with pip:: 62 63 $ pip install grequests 64