Skip to content

Instantly share code, notes, and snippets.

@wassname
Created January 22, 2021 13:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wassname/df66d5b9bb4ac92486fc744f3654b9d1 to your computer and use it in GitHub Desktop.
Save wassname/df66d5b9bb4ac92486fc744f3654b9d1 to your computer and use it in GitHub Desktop.
rich tqdm
from rich.progress import (
ProgressColumn,
BarColumn,
DownloadColumn,
TextColumn,
TransferSpeedColumn,
TimeRemainingColumn,
Progress,
TaskID,
TimeElapsedColumn,
SpinnerColumn,
Text
)
class SpeedColumn(ProgressColumn):
"""Renders human readable transfer speed."""
def render(self, task: "Task") -> Text:
"""Show data transfer speed."""
speed = task.speed
if speed is None:
return Text("?", style="progress.data.speed")
return Text(f"{speed:2.2f} it/s", style="progress.data.speed")
def RichTQDM():
return Progress(
SpinnerColumn(),
"[progress.description]{task.description}",
BarColumn(),
TextColumn("{task.completed}/{task.total}"),
"[",
TimeElapsedColumn(),
"<",
TimeRemainingColumn(),
',',
SpeedColumn(),
']',
refresh_per_second=.1, speed_estimate_period=30
)
if __name__ == "__main__":
with RichTQDM() as prog:
task1 = prog.add_task("[red]steps", total=num_steps)
for i in range(num_steps):
prog.update(task1, advance=1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment