How To Add A Progress Bar In Python

Search for a command to run...

Hey @ayushi7rawat
I read your article on Progress bar in python using tqdm
and I made a simple timer with it using the code:
from tqdm import tqdm, trange
import time
for i in tqdm(range(60)):
time.sleep(1.0)
print("time's up")

By the way, it doesn't actually run the print command, but it works :)
The series content will mostly cover Technical Python tutorials and my recent learnings and experience in Python.
Hello world! I am attending a Technical Writing Bootcamp at @hashnode. Hashnode Bootcamp II is a free virtual Bootcamp to help beginner technical writers to improve their writing skill. This article is inspired by the latest session by Anna McDougall...
All you need to know about Hacktoberfest 2021

Hello reader! Well, Hacktoberfest is something, you are gonna hear a lot about in the coming month. You can refer to my YouTube video Tutorial to see a working tutorial for better understanding and a step-by-step guide of the same. https://www.yo...

Hello reader! In this Blog post, I will share some useful code snippets and functions in Python. Give it a read. Let's get started! 1. Memory The method getsizeof can be used to retrieve the size of any object. Here's an example of the same. import...

Hello reader! Whenever a client sends a request to the server, the response always contains a status code. You might not see it always but it's returned at every client-server interaction. Well, even if you are not a programmer, you would still know...

Hello reader! Microsoft subsidiary GitHub launched Copilot to power pair programming with AI. In this blog post, I will share all you need to know about it. You can refer to my YouTube video Tutorial to see a working tutorial for better understandin...

Hello world!
When you happen to install a software, download an application or media or load a page, you see a progress bar give you an estimate of how long the process would take to complete or render. You can add one in your code too. In this Blog article, we will learn how to Create Progress Bar. We will see the implementation in Python.
Check out the Repository for Ultimate Resource in python. Drop a star if you find it useful! Got anything to add? Open a PR on the same!
You can refer to my YouTube video Tutorial to see a working tutorial for better Understanding and a step by step Guide of the same.
1. tqdm Introduction
2. How to Create Progress Bar
tqdm Introduction:A progress bar is a graphical control element used to visualize the progression of an extended computer operation, such as a download, file transfer, or installation. We will make use of the Python library tqdm, to create simple progress bars which can be added in the code and make it look lively!
tqdm means "progress" in Arabic (taqadum, تقدّم) and is an abbreviation for "I love you so much" in Spanish (te quiero demasiado). tqdm is Fast and Extensible Progress Meter.
If you wish to know more about it, you can refer to tqdmDocumentation. Use this link to navigate to the documentation.
Now that you are aware of tqdm basics, we can move forward to the coding section. Let's get started!
You can find all the code at my GitHub Repository. Drop a star if you find it useful.
In order to access the Python library, you need to install it into your Python environment, use the following command to install tqdm
pip install tqdm
Now, let's import the package in our Python script.
from tqdm import tqdm, trange
We will require time package, so lets import that one as well
import time
Let's run a loop for an iterable
for i in range(10):
pass
In order to see the progress, lets make use of time module
for i in range(10):
time.sleep(0.4)
Once done, let's add a progress bar for the loop. In order to do so, let's wrap the iterable with tqdm method.
for i in tqdm(range(10)):
time.sleep(0.4)
Let's have a look at the output. It will look something like this:

If you wish to get rid of the iterable, you can do so by wrapping the iterable in trange module.
for i in trange(5):
sleep(0.4)
This is how you can add a progress bar in your python script. That's it!
Simple, isn't it? Hope this tutorial has helped. I would strongly recommend you to Check out the YouTube video of the same and don't forget to subscribe my Channel.
You can play around with the tqdm library and even explore more features. You can even make use of Python GUI using Tkinter.
You can find all the code at my GitHub Repository. Drop a star if you find it useful.
Thank you for reading, I would love to connect with you at Twitter | LinkedIn.
Do share your valuable suggestions, I appreciate your honest feedback!
You should definitely check out my other Blogs:
See you in my next Blog article, Take care