Skip to content
Myr

Progress examples (#1272)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* Progress examples * Update advanced.md

authored by Tom Christie · committed by GitHub · parent 930f377 · Browse files · 3 files+28 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: Florimond Manca <florimond.manca@gmail.com>

Diff stats

3 files+28 added−1 removed

  • other:+28 added−1 removed

3 files+28 added−1 removed

added:docs/img/rich-progress.gifbinary

A binary file, added.

added:docs/img/tqdm-progress.gifbinary

A binary file, added.

modified:docs/advanced.md+28 added-1 removed
244 unmodified lines
245 for chunk in response.iter_bytes():246 download_file.write(chunk)247 progress.update(response.num_bytes_downloaded - num_bytes_downloaded)248 num_bytes_downloaded = response.num_bytes_downloaded249 print(f"The total download size is {response.num_bytes_downloaded} bytes")249```250251![tqdm progress bar](img/tqdm-progress.gif)252253Or an alternate example, this time using the [`rich`](https://github.com/willmcgugan/rich) library…254255```python256import tempfile257import httpx258import rich.progress259260with tempfile.NamedTemporaryFile() as download_file:261 url = "https://speed.hetzner.de/100MB.bin"262 with httpx.stream("GET", url) as response:263 total = int(response.headers["Content-Length"])264265 with rich.progress.Progress(266 "[progress.percentage]{task.percentage:>3.0f}%",267 rich.progress.BarColumn(bar_width=None),268 rich.progress.DownloadColumn(),269 rich.progress.TransferSpeedColumn(),270 ) as progress:271 download_task = progress.add_task("Download", total=total)272 for chunk in response.iter_bytes():273 download_file.write(chunk)274 progress.update(download_task, completed=response.num_bytes_downloaded)275```276277![rich progress bar](img/rich-progress.gif)278279## .netrc Support280281HTTPX supports .netrc file. In `trust_env=True` cases, if auth parameter is282not defined, HTTPX tries to add auth into request's header from .netrc file.
725 unmodified lines