from requests_futures.sessions import FuturesSession session = FuturesSession() response = session.put('http://example.com', data={'key': 'value'}) # Do other things while the request is being made # ... # Wait for the response and print the status code print(response.result().status_code)
from requests_futures.sessions import FuturesSession session = FuturesSession() urls = [ 'http://example.com/1', 'http://example.com/2', 'http://example.com/3', ] # Send all requests asynchronously responses = [session.get(url) for url in urls] # Wait for all responses and print the status codes for response in responses: print(response.result().status_code)In this example, we create a `FuturesSession` object and a list of URLs. We use a list comprehension to send all the requests asynchronously using the `get` method. We then loop through all the `Future` objects in the `responses` list and call `response.result()` to wait for each request to complete and get the actual `Response` object. We then print the status code of each response. Overall, the `requests_futures.sessions` library is a useful tool for making asynchronous HTTP requests in Python, and it is built on top of the popular `requests` library.