Skip to content

Instantly share code, notes, and snippets.

@jnhmcknight
Forked from wasi0013/download_large_file.py
Created October 25, 2023 16:43
Show Gist options
  • Save jnhmcknight/9814fc8116b50ee477a947881c7b0bc3 to your computer and use it in GitHub Desktop.
Save jnhmcknight/9814fc8116b50ee477a947881c7b0bc3 to your computer and use it in GitHub Desktop.
how to download large file using python, requests without exhausting device ram.
import requests
chunk_size = 4096
filename = "logo.png"
document_url = "https://wasi0013.files.wordpress.com/2018/11/my_website_logo_half_circle_green-e1546027650125.png"
with requests.get(document_url, stream=True) as r:
with open(filename, 'wb') as f:
for chunk in r.iter_content(chunk_size):
if chunk:
f.write(chunk)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment