![]() |
VOOZH | about |
Progress bars are a great way to visually indicate progress in your Python programs, especially during tasks that take a significant amount of time. For example, they are commonly used during a for loop that processes large datasets, while downloading files from the internet or even when an application is starting up to indicate loading progress. Letβs now explore the different methods to create progress bars efficiently.
tqdm is one of the most popular and easiest libraries for showing progress bars in Python. It works well with loops and gives a neat, real-time progress bar in your terminal.
Output
Explanation: This code runs a loop 100 times and tqdm adds a progress bar to show how far along it is. Each loop pauses briefly using time.sleep(0.05) to mimic a task taking time. As it runs, the progress bar updates in real time, giving you a clear visual of the taskβs progress.
rich is a modern Python library for beautiful terminal output, including progress bars with colors and animations. It makes your console output visually appealing.
Output
Explanation: rich.progress create a colorful progress bar for a 100-step task. It updates the bar step-by-step with a short pause time.sleep(0.05) to simulate work, providing a smooth, real-time view of progress until completion.
alive_progress adds a fun twist to progress bars by showing animated bars and spinners. It's very user-friendly and adds a bit of life to long-running tasks.
Output
Explanation: alive_progress show an animated progress bar. It runs a 100-step loop with a brief pause time.sleep(0.05) to simulate work, updating the progress bar after each iteration.
progressbar2 is a more traditional progress bar library that gives you a classic loading bar feel. It's a solid choice and has been around for a while.
Output
Explanation: progressbar2 library display a terminal progress bar for a 100-step task. It starts the bar, simulates work with a short pause in each loop iteration, updates the progress with b.update(i + 1) and finishes cleanly with b.finish().