python multiprocess requests on API

1.9k views Asked by At

I need to get data from API which url based on different ID.

url = "http://123456789/" id = "jimmy"

I have a list of ID, here are my code

for id in ID:
   response = requests.get(url+id)
   info = response.json(encoding = "utf-8")
   ##save info 

But I have 400,000 ID and it will take to long to grab all data, So I want use multiprocess to finish this job. Cut the ID list into 10 or more small list and run them in the same time. How can I do that? Please help, thanks!

1

There are 1 answers

1
christliu On

You can use Pool. Cut the list of IDs into many subIds, and different process handle different ids. https://docs.python.org/2/library/multiprocessing.html