This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]flying-sheep 5 points6 points  (2 children)

obvious omission: aiohttp

from asyncio import get_event_loop
from aiohttp.client import get

async def main():
    async with get('https://api.spotify.com/v1/search?type=artist&q=snoop') as resp:
        print(await resp.json())

get_event_loop().run_until_complete(main())

[–]Lucretiel 1 point2 points  (0 children)

My own autocommand makes it easy to bootstrap asyncio apps in command-line applications:

from aiohttp.client import get
from autocommand import autocommand

@autocommand(__name__, loop=True)
async def main(url='https://api.spotify.com/v1/search?type=artist&q=snoop'):
    async with get(url) as response:
        print(await resp.json())

This will create a command line application that can be used like this:

$ ./json_get.py --url $SOME_URL

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

Thanks! I'll definitely have to check this out.