| Server IP : 54.37.205.81 / Your IP : 216.73.216.76 Web Server : nginx/1.22.1 System : Linux vps-249481fa 6.1.0-50-cloud-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.176-1 (2026-07-02) x86_64 User : debian ( 1000) PHP Version : 8.2.32 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /usr/share/doc/python3-tqdm/examples/ |
Upload File : |
"""An example of wrapping manual tqdm updates for `requests.get`.
See also: tqdm_wget.py.
Usage:
tqdm_requests.py [options]
Options:
-h, --help
Print this help message and exit
-u URL, --url URL : string, optional
The url to fetch.
[default: https://caspersci.uk.to/matryoshka.zip]
-o FILE, --output FILE : string, optional
The local file path in which to save the url [default: /dev/null].
"""
from os import devnull
import requests
from docopt import docopt
from tqdm.auto import tqdm
opts = docopt(__doc__)
eg_link = opts['--url']
eg_file = eg_link.replace('/', ' ').split()[-1]
eg_out = opts['--output'].replace("/dev/null", devnull)
response = requests.get(eg_link, stream=True)
with open(eg_out, "wb") as fout:
with tqdm(
# all optional kwargs
unit='B', unit_scale=True, unit_divisor=1024, miniters=1,
desc=eg_file, total=int(response.headers.get('content-length', 0))
) as pbar:
for chunk in response.iter_content(chunk_size=4096):
fout.write(chunk)
pbar.update(len(chunk))
# Even simpler progress by wrapping the output file's `write()`
response = requests.get(eg_link, stream=True)
with tqdm.wrapattr(
open(eg_out, "wb"), "write",
unit='B', unit_scale=True, unit_divisor=1024, miniters=1,
desc=eg_file, total=int(response.headers.get('content-length', 0))
) as fout:
for chunk in response.iter_content(chunk_size=4096):
fout.write(chunk)