16 unstable releases (6 breaking)

0.7.0 Apr 2, 2024
0.6.0 Oct 19, 2023
0.5.2 Aug 26, 2023
0.5.1 Jul 27, 2023
0.3.1 Feb 25, 2022

#94 in Command-line interface

Download history 4303/week @ 2024-01-24 2686/week @ 2024-01-31 2999/week @ 2024-02-07 2713/week @ 2024-02-14 2892/week @ 2024-02-21 5267/week @ 2024-02-28 5646/week @ 2024-03-06 4703/week @ 2024-03-13 4728/week @ 2024-03-20 4239/week @ 2024-03-27 7290/week @ 2024-04-03 5988/week @ 2024-04-10 5321/week @ 2024-04-17 5786/week @ 2024-04-24 4337/week @ 2024-05-01 3700/week @ 2024-05-08

20,657 downloads per month
Used in 6 crates

MIT/Apache

265KB
460 lines

tqdm Crates.io Version Crates.io Downloads Crates.io MSRV

Instantly make your loops show a smart progress meter - just wrap any iterable with tqdm(iterable), and you're done!

Rust implementation of the popular Python command line progress bar tool tqdm. The name "tqdm" derives from the Arabic word taqaddum (تقدّم) which can mean "progress", and is an abbreviation for "I love you so much" in Spanish (te quiero demasiado).

demo

Quick Start

Simply wrap tqdm::tqdm() around any iterable:

use tqdm::tqdm;
for i in tqdm(0..10000) {
    /* Your loop logic here */
}

This function returns a wrapper iterator that controls multiple progress bars, advancing the meter when next is called. Methods on the original iterable are bypassed using the auto-dereference trait, so they can be called with no overhead.

 76%|███████████████▉     | 7618/10000 [00:09<00:03, 782.14it/s]

Usage

Styles and other parameters can be configured in-place:

use tqdm::Style;
for i in tqdm(0..100)
    .style(Style::Balloon)
    .desc(Some("some description")) {
    /* Your loop logic here */
}
 47%|**********.          | 4792/10000 [00:06<00:06, 783.39it/s]

Expose the tqdm::Iter trait to allow method chaining:

use tqdm::Iter;
for i in (0..).take(10000).tqdm() {
    /* Your loop logic here */
}

Alternatively, create a progress bar with tqdm::pbar() and manually update it:

use tqdm::pbar;
let mut pbar = pbar(Some(44850));

for i in 0..300 {
    pbar.update(i).unwrap();
    /* Your loop logic here */
}

Advanced Usage

Multi-bars are also supported! Tqdm maintains a global registry to handle multiple bars:

use tqdm::tqdm;
for t in (0..3) {
    std::thread::spawn(move || {
        for i in tqdm(0..).desc(Some(i)) {
            /* Your loop logic here */
        }
    })
}
 38%|##########0               | 77/200 [00:00<00:01, 83.24it/s]
 77%|████████████████████      | 77/100 [00:00<00:00, 83.24it/s]
 19%|*****.                    | 77/400 [00:00<00:03, 83.24it/s]

Async iterator items can be tracked using tqdm::tqdm_async() (you may need an async runtime like tokio):

use tqdm::tqdm_async;

#[tokio::main]
async fn main() {
    use tokio::time::{sleep, Duration};
    let future_iter = (0..100).map(|i| sleep(Duration::from_secs_f64(i as f64 / 100.0)));
    futures::future::join_all(tqdm_async(future_iter)).await;
}

For more usage, please refer to doc.

License

Crates.io License

Dependencies

~1–12MB
~84K SLoC