There are several approaches for making asynchronous requests from python. One simple way is to use the requests-futures
library.
from requests_futures.sessions import FuturesSession
session = FuturesSession(max_workers=10)
names = df.index.values.tolist()
urls = ['some_url'+name for name in names]
fire_requests = [session.get(url) for url in urls]
results = [item.result() for item in fire_requests]
You may have to call .json()
on item.result()
. I've always used this approach though it strikes me now that it makes use of list-comprehension side effects so it may be better practice to break it down into a standard for
loop in the case of fire_requests
.