Skip to content

Latest commit

 

History

History
32 lines (21 loc) · 924 Bytes

progress-bars.md

File metadata and controls

32 lines (21 loc) · 924 Bytes

Progress bars for long-running loops or tasks

If you have a loop that has a number of iterations or takes a long time to run, you can get an easy progress bar (with an estimated time to completion) using tools like tqdm or Rich. They also work in Jupyter notebooks.

tqdm

Change your loop from:

for i in range(10000):
    ...

to:

from tqdm import tqdm
for i in tqdm(range(10000)):
    ...

And get this for free:

76%|████████████████████████████         | 7568/10000 [00:33<00:10, 229.00it/s]

You can also manually update the progress bar in your code using tqdm.update().

Rich

Rich works in a similar way, and also provides rich console output more generally.