Python rich progress bar and httpx

Thu, Dec 15, 2022 One-minute read

Python rich progress bar and httpx

How to create a progress bar using rich and httpx:

path = "/tmp/file"
url = httpx.URL("")

with"GET", url=url, verify=False, follow_redirects=True) as r:
  with Progress() as progress:
    size = int(r.headers["Content-Length"]
    with open(path, "wb") as dest:
      dl = progress.add_task("[red]Downloading Ubuntu[/red]", total=size)
      for data in r.iter_raw():
        progress.update(dl, advance=len(data), description="[yellow]Downloading...[/yellow]")
      progress.update(dl, description="[green]Download Complete[/green]")


#python #httpx