Menu Close

How to make asynchronous requests with Python requests?

Sometimes, we want to make asynchronous requests with Python requests.

In this article, we’ll look at how to make asynchronous requests with Python requests.

How to make asynchronous requests with Python requests?

To make asynchronous requests with Python requests, we can use the grequests module.

To install it, we run

pip install grequests

Then we use it by writing

import grequests

urls = [
    'http://www.heroku.com',
    'http://example.org',
    'http://httpbin.org',
    'http://python-requests.org',
    'http://abc.com'
]

rs = (grequests.get(u) for u in urls)

to call grequests.get with the URLs in urls to make async GET requests with each URL.

Conclusion

To make asynchronous requests with Python requests, we can use the grequests module.

Posted in Python, Python Answers