Skip to content

Instantly share code, notes, and snippets.

@bmbouter
Created August 9, 2018 21:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bmbouter/8665d36b1175ce8176ce63e7b403a906 to your computer and use it in GitHub Desktop.
Save bmbouter/8665d36b1175ce8176ce63e7b403a906 to your computer and use it in GitHub Desktop.
import asyncio
import aiohttp
async def my_download():
with open('/tmp/somefileintmp', 'wb') as the_file:
async with aiohttp.ClientSession(auto_decompress=False) as session:
async with session.get('https://repos.fedorapeople.org/pulp/pulp/fixtures/python-pypi/packages/shelf_reader-0.1-py2-none-any.whl') as resp:
while True:
chunk = await resp.content.read(1024 * 1024)
if not chunk:
break # the download is done
the_file.write(chunk)
loop = asyncio.get_event_loop()
loop.run_until_complete(my_download())
loop.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment