You can use python tqdm module to display the progress bar for a python script or command.
Install python module tqdm using pip
1 2 |
## install tqdm pip install tqdm |
Usage Examples:
Iterable-based:
Wrap tqdm()
around any iterable:
1 2 3 4 5 6 7 |
from tqdm import tqdm from time import sleep text = "" for char in tqdm(["a", "b", "c", "d"]): sleep(0.25) text = text + char |
trange(i)
is a special optimised instance of tqdm(range(i))
:
1 2 3 4 |
from tqdm import trange for i in trange(100): sleep(0.01) |
Instantiation outside of the loop allows for manual control over tqdm()
:
1 2 3 4 |
pbar = tqdm(["a", "b", "c", "d"]) for char in pbar: sleep(0.25) pbar.set_description("Processing %s" % char) |
Manual control of tqdm()
updates using a with
statement:
1 2 3 4 |
with tqdm(total=100) as pbar: for i in range(10): sleep(0.1) pbar.update(10) |
Module
Perhaps the most wonderful use of tqdm
is in a script or on the command line. Simply inserting tqdm
(or python -m tqdm
) between pipes will pass through all stdin
to stdout
while printing progress to stderr
.
1 2 3 4 5 6 7 8 9 |
## search progress find . -name '*.py' -type f -exec cat \{} \; | tqdm --unit loc --unit_scale --total 857366 >> /dev/null 100%|█████████████████████████████████| 857K/857K [00:04<00:00, 246Kloc/s] ## backup progress tar -zcf - docs/ | tqdm --bytes --total `du -sb docs/ | cut -f1` \ > backup.tgz 44%|██████████████▊ | 153M/352M [00:14<00:18, 11.0MB/s] |
To get more details on tqdm, please refer https://github.com/tqdm/tqdm