For streaming response from requests, download the content one CHUNK at a time

def save_response_content(response, filename='data.csv', destination=os.path.curdir, chunksize=32768):
    """ For streaming response from requests, download the content one CHUNK at a time """
    chunksize = chunksize or 32768
    if os.path.sep in filename:
        full_destination_path = filename
    else:
        full_destination_path = os.path.join(destination, filename)
    full_destination_path = expand_filepath(full_destination_path)
    with open(full_destination_path, "wb") as f:
        for chunk in tqdm(response.iter_content(CHUNK_SIZE)):
            if chunk:  # filter out keep-alive new chunks
                f.write(chunk)
    return full_destination_path