DEV Community

Free Python Code
Free Python Code

Posted on • Updated on

How to create a progress bar for downloading files in Python

hi πŸ™‚πŸ–

In this post, I will share with you How to create a progress bar for downloading files in Python.


import requests
from tqdm import tqdm

url = 'https://player.vimeo.com/external/121142413.sd.mp4?s=1b8ed80f9ce01d9ecf4af3eb12c879e00f29850f&profile_id=112&oauth2_token_id=57447761'

res = requests.get(url, stream = True)
total_size = int(res.headers.get('content-length', 0))
progress_bar = tqdm(total = total_size, unit = 'iB', unit_scale = True)

with open('video.mp4', 'wb') as file:
    for data in res.iter_content(1024):
        file.write(data)
        progress_bar.update(len(data))


progress_bar.close()

Enter fullscreen mode Exit fullscreen mode

Top comments (0)