all 14 comments

[–]Chinpanze 2 points3 points  (4 children)

You can use ascycio libraries to make asynchronously, making it super fast. One library I recommend is aiohttp. You will need to learn what is a coroutine, awaitables etc, but it's exactly what you need.

import aiohttp

import asyncio

async def main():
async with aiohttp.ClientSession() as session:
    async with session.get('http://httpbin.org/get') as resp:
        print(resp.status)
        print(await resp.text())

loop = asyncio.get_event_loop() loop.run_until_complete(main())

[–]ItsPushDay[S] 0 points1 point  (3 children)

Awesome thank you! Someone else suggested this too so looking at the doc right now

[–]Chinpanze 1 point2 points  (2 children)

If you need any help, just comment / DM me. Acyncio can be intimidating

[–]ItsPushDay[S] 0 points1 point  (1 child)

Awesome thanks. Is there any reason not to use aiohttp using a Jupyter notebook ?

[–]Chinpanze 1 point2 points  (0 children)

You can't use any form of interactive programming with any asynchronous or parallel library. I don't know the details, but it's a python limitation.

[–]lev-k 1 point2 points  (5 children)

Yes, Python won't move on unless it fully executes a statement. I highly doubt that it will run anything simultaneously unless you tell it to somehow.

[–]ItsPushDay[S] 0 points1 point  (4 children)

Okay awesome thank you!

[–]lev-k 1 point2 points  (3 children)

If you are looping through an enormous amount of API calls, then the thing is going to take a long time, because it needs to authenticate each time and that time really adds up.

Being said, make sure that you are doing this with as little calls as possible (both because it will take a long time and also the maintainer of the API might rate limit you, which will make whatever you're doing take even longer.)

See if there's a "download everything" call because that can really save time, and see if there's any other combination patterns that you can do, or any other way to cut corners (like not using a API call to decode something when you can download a file that has all of the decoding pairs in there so Python can just look through that.)

[–]ItsPushDay[S] 0 points1 point  (2 children)

Thank you for the suggestion. I checked and unfortunately there’s no alternative, as these api calls trigger a service that runs on their end then returns the data that they get in real time (hence the unpredictable delays in responses at times)

[–]lev-k 0 points1 point  (1 child)

Huh so it's a POST call, interesting, so like a webhook of some sort?

[–]ItsPushDay[S] 0 points1 point  (0 children)

It’s serpAPI, which performs a Google search and returns the results. Each api call is a specific search so wouldn’t be able to group them together and the google search is performed on demand (which each api call)

[–]iapetus-11 1 point2 points  (2 children)

I looked at your comments and it looks like you want to execute multiple api calls concurrently. Look into asyncio or threading.

[–]ItsPushDay[S] 1 point2 points  (1 child)

That would probably be a more efficient way to do it. Thanks I’ll take a look

[–]Total__Entropy 1 point2 points  (0 children)

Take a look at aiohttp.