{"id":12596,"date":"2025-06-24T10:14:16","date_gmt":"2025-06-24T10:14:16","guid":{"rendered":"https:\/\/www.bacancytechnology.com\/qanda\/?p=12596"},"modified":"2026-01-27T11:02:25","modified_gmt":"2026-01-27T11:02:25","slug":"progress-bar-in-python","status":"publish","type":"post","link":"https:\/\/www.bacancytechnology.com\/qanda\/python\/progress-bar-in-python","title":{"rendered":"Python Progress Bar"},"content":{"rendered":"<p>Adding a progress bar in Python is a great way to enhance user experience for long-running tasks. Whether you&#8217;re iterating over a loop, downloading files, or waiting for a time-consuming process, progress indicators can be easily implemented using libraries or manual approaches.<\/p>\n<h2>Method 1: Using the tqdm Library (Recommended)<\/h2>\n<p>The tqdm library is the most popular and simple way to display a progress bar.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">\r\nfrom tqdm import tqdm\r\nimport time\r\n\r\n# Simulating a long-running loop\r\nfor i in tqdm(range(100)):\r\n   time.sleep(0.05)  # Simulated workload\r\n<\/pre>\n<h3>Output:<\/h3>\n<p>A real-time progress bar with estimated time and percentage completes in the terminal.<\/p>\n<h2>Method 2: Manual Progress Bar with sys.stdout<\/h2>\n<p>For more control or if you don\u2019t want external dependencies:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">\r\nimport sys\r\nimport time\r\n\r\ndef print_progress_bar(iteration, total, length=50):\r\n   percent = (\"{0:.1f}\").format(100 * (iteration \/ float(total)))\r\n   filled_length = int(length * iteration \/\/ total)\r\n   bar = '\u2588' * filled_length + '-' * (length - filled_length)\r\n   sys.stdout.write(f'\\rProgress: |{bar}| {percent}% Complete')\r\n   sys.stdout.flush()\r\n# Simulate a task\r\ntotal = 100\r\nfor i in range(total):\r\n   time.sleep(0.05)\r\n   print_progress_bar(i + 1, total)\r\n<\/pre>\n<div class=\"qanda-read-box\"><div class=\"bg-light read-more-icon\"><img decoding=\"async\" src=\"https:\/\/assets.bacancytechnology.com\/qanda\/wp-content\/uploads\/2025\/04\/24061434\/read-txt.png\" alt=\"Also Read\"><p><\/p><h3>Also Read:<\/h3><a href=\"https:\/\/www.bacancytechnology.com\/blog\/python-with-machine-learning\" target=\"_blank\">Python With Machine Learning<\/a><\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Adding a progress bar in Python is a great way to enhance user experience for long-running tasks. Whether you&#8217;re iterating over a loop, downloading files, or waiting for a time-consuming process, progress indicators can be easily implemented using libraries or manual approaches. Method 1: Using the tqdm Library (Recommended) The tqdm library is the most [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":12603,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[16],"tags":[],"class_list":["post-12596","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/12596"}],"collection":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/comments?post=12596"}],"version-history":[{"count":3,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/12596\/revisions"}],"predecessor-version":[{"id":12604,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/12596\/revisions\/12604"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/media\/12603"}],"wp:attachment":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/media?parent=12596"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/categories?post=12596"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/tags?post=12596"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}