import requests_futures.sessions session = requests_futures.sessions.FuturesSession() url = "https://jsonplaceholder.typicode.com/users" response = session.get(url) future_response = response.result() print(future_response.status_code)
import requests_futures.sessions import concurrent.futures session = requests_futures.sessions.FuturesSession() urls = [ "https://jsonplaceholder.typicode.com/users", "https://jsonplaceholder.typicode.com/photos", "https://jsonplaceholder.typicode.com/albums" ] futures = [] for url in urls: futures.append(session.get(url)) for future_response in concurrent.futures.as_completed(futures): response = future_response.result() print(response.status_code, response.url)This code asynchronously sends GET requests to multiple URLs using a list of futures. It then waits for the response of each request and prints the status code and URL of each future response. Python requests_futures.sessions is a third-party package library that builds on top of the requests library. It provides an easy-to-use asynchronous interface for sending HTTP requests and receiving responses.