Skip to content

Instantly share code, notes, and snippets.

@daviwesley
Created March 2, 2022 19:26
Show Gist options
  • Save daviwesley/c321fbd4bb8931294be7c41011583c93 to your computer and use it in GitHub Desktop.
Save daviwesley/c321fbd4bb8931294be7c41011583c93 to your computer and use it in GitHub Desktop.
import asyncio
import httpx
import time
start_time = time.time()
async def get_pokemon(client, url):
resp = await client.get(url)
pokemon = resp.json()
return pokemon["name"]
async def main():
async with httpx.AsyncClient() as client:
tasks = []
for number in range(1, 151):
url = f"https://pokeapi.co/api/v2/pokemon/{number}"
tasks.append(asyncio.ensure_future(get_pokemon(client, url)))
original_pokemon = await asyncio.gather(*tasks)
for pokemon in original_pokemon:
print(pokemon)
asyncio.run(main())
print("--- %s seconds ---" % (time.time() - start_time))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment