<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Amit Vyas on Medium]]></title>
        <description><![CDATA[Stories by Amit Vyas on Medium]]></description>
        <link>https://medium.com/@amitvy?source=rss-4f20442623a7------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*ts5aDp0sNRR7df6N.</url>
            <title>Stories by Amit Vyas on Medium</title>
            <link>https://medium.com/@amitvy?source=rss-4f20442623a7------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 21:39:39 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@amitvy/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Using tqdm in python]]></title>
            <link>https://medium.com/@amitvy/using-tqdm-in-python-f9634da916ee?source=rss-4f20442623a7------2</link>
            <guid isPermaLink="false">https://medium.com/p/f9634da916ee</guid>
            <category><![CDATA[debugging]]></category>
            <category><![CDATA[tqdm]]></category>
            <category><![CDATA[python3]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Amit Vyas]]></dc:creator>
            <pubDate>Tue, 22 Jun 2021 15:06:31 GMT</pubDate>
            <atom:updated>2021-06-22T15:06:31.982Z</atom:updated>
            <content:encoded><![CDATA[<p>Did you ever wonder if you could print a progress bar while doing the loop in the python onto the console, if yes then you have come to the right page, my fellow coders. I used to think what if there is some easy way to do it like you add some simple keyword while iterating the for loop and that keyword just magically bring the progress meter onto your console and <strong><em>voilà, </em></strong><em>you are basically done with it by adding that magic keyword.</em></p><p>So let me introduce you to the cool library, which will feel like magic for first use but let me warn you my pythoneer friends, once you use it in your code and sees the output you instantaneously become addicted to this library. So without further adieu, let’s start our simplest implementation on the tqdm program.</p><p>Installing the tqdm library from pip. <a href="https://pypi.org/project/tqdm/">https://pypi.org/project/tqdm/</a></p><pre>pip install tqdm</pre><p>This is all you need to use the tqdm library,</p><p>So let’s go ahead and create our sample code for this demo.</p><p>First, let’s imports some basic modules which we will be needing for the demo code, and in this particular demo code we will be using the rest based API and JSON so we will be adding these modules as well,</p><pre><em>import</em> time, requests, json</pre><pre><em>from</em> tqdm <em>import</em> tqdm</pre><p><em>Our dummy API URL to create employees for this test code, which actually works.</em></p><pre>url = &#39;https://dummy.restapiexample.com/api/v1/create&#39;</pre><p>Now, Suppose we got our employees list from some CSV or some other system and now we are planning to call some third party API to use the POST API iteratively, so for our test code let’s assume we are getting our employees list in the below array format.</p><pre>employees = [{&#39;name&#39;: &#39;test 1&#39;, &#39;salary&#39;: &#39;100&#39;, &#39;age&#39;: &#39;21&#39;}, {&#39;name&#39;: &#39;test 2&#39;, &#39;salary&#39;: &#39;200&#39;, &#39;age&#39;: &#39;22&#39;},{&#39;name&#39;: &#39;test 3&#39;, &#39;salary&#39;: &#39;300&#39;, &#39;age&#39;: &#39;23&#39;},{&#39;name&#39;: &#39;test 4&#39;, &#39;salary&#39;: &#39;400&#39;, &#39;age&#39;: &#39;24&#39;},{&#39;name&#39;: &#39;test 5&#39;, &#39;salary&#39;: &#39;500&#39;, &#39;age&#39;: &#39;25&#39;},{&#39;name&#39;: &#39;test 6&#39;, &#39;salary&#39;: &#39;600&#39;, &#39;age&#39;: &#39;26&#39;},{&#39;name&#39;: &#39;test 7&#39;, &#39;salary&#39;: &#39;700&#39;, &#39;age&#39;: &#39;27&#39;},{&#39;name&#39;: &#39;test 8&#39;, &#39;salary&#39;: &#39;800&#39;, &#39;age&#39;: &#39;28&#39;},{&#39;name&#39;: &#39;test 9&#39;, &#39;salary&#39;: &#39;900&#39;, &#39;age&#39;: &#39;29&#39;},{&#39;name&#39;: &#39;test 10&#39;, &#39;salary&#39;: &#39;1000&#39;, &#39;age&#39;: &#39;30&#39;}]</pre><p>In below for for loop, if you noticed close enough you will realise that I am using tqdm function and passing our employees list into that and that tqdm will be creating the progress meter as we will be iterating over each employee in this for loop. So this is all you need to do in order to use the tdqm library.</p><pre><em>for</em> employee <em>in</em> tqdm(employees):</pre><pre>    response = requests.request(&#39;POST&#39;, url, <em>headers</em>={&#39;Content-Type&#39;: &#39;application/json&#39;}, <em>data</em>=json.dumps(employee))</pre><pre>    print(response.text)</pre><pre>    time.sleep(2)</pre><p>Result from our console application with progress meter in it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mWSIJ_nVL15cYjRl4FXVjA.png" /></figure><p>You can also use tqdm with a manual mode where you explicitly provide the number of iterations and update the value based on your custom logic while iterating, below is a simple example to do that.</p><pre>pbar = tqdm(total=100)<br>for i in range(10):<br>    sleep(0.1)<br>    pbar.update(10)<br>pbar.close()</pre><p>Hoping you like it and this will be useful for your console-based Python programs.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f9634da916ee" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>