Member-only story
Enhancing Python Scripts with Alive-Progress: 5 Practical Examples
2 min readAug 17, 2024
pip install alive-progress
1. Simple Progress Bar
from alive_progress import alive_bar
import time
items = range(100)with alive_bar(len(items)) as bar:
for item in items:
time.sleep(0.05)
bar()
|████████████████████████████████████████| 100/100 [100%] in 5.0s (19.83/s)
2. Progress Bar with Custom Text
from alive_progress import alive_bar
import time
tasks = ['task1', 'task2', 'task3', 'task4']with alive_bar(len(tasks), title='Processing Tasks') as bar:
for task in tasks:
time.sleep(0.5)
bar.text = f'Working on {task}'
bar()
Processing Tasks |████████████████████████████████████████| 4/4 [100%] in 2.0s (2.00/s)
3. Nested Progress Bars
from alive_progress import alive_bar
import time
outer_items = range(3)
inner_items = range(5)