with open(local_filename, 'wb') as f:
    for chunk in r.iter_content(chunk_size=1024):
        if chunk:
            f.write(chunk)
f.flush()
os.fsync()
How to download large file in python with requests.py?