Sync, using requests:
import requests
def main():
with requests.Session() as s:
r = s.get('https://...')
result = r.json()
main()
Async, using aiohttp: import aiohttp
import asyncio
async def main():
async with aiohttp.ClientSession() as s:
async with s.get('https://...') as r:
result = await r.json()
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
If you're making many HTTP requests, you can use async, queue them up and it greatly improves performance.See also https://docs.aiohttp.org/en/stable/http_request_lifecycle.ht...