Package: enlighten
OverviewEnlighten Progress Bar is a console progress bar library for Python.The main advantage of Enlighten is it allows writing to stdout and stderr without any
redirection or additional code. Just print or log as you normally would.Enlighten also includes experimental support for Jupyter Notebooks.The code for this animation can be found indemo.pyinexamples.Documentationhttps://python-enlighten.readthedocs.ioInstallationPIP$pipinstallenlightenRPMFedora and EL8 (RHEL/CentOS)(ForEPELrepositories must beconfigured)$dnfinstallpython3-enlightenDEBDebian and Ubuntu$apt-getinstallpython3-enlightenConda$condainstall-cconda-forgeenlightenHow to UseManagersThe first step is to create a manager. Managers handle output to the terminal and allow multiple
progress bars to be displayed at the same time.get_managercan be used to get aManagerinstance.
Managers will only display output when the output stream,sys.__stdout__by default,
is attached to a TTY. If the stream is not attached to a TTY, the manager instance returned will be
disabled.In most cases, a manager can be created like this.importenlightenmanager=enlighten.get_manager()If you need to use a different output stream, or override the defaults, see the documentation forget_managerProgress BarsFor a basic progress bar, invoke theManager.countermethod.importtimeimportenlightenmanager=enlighten.get_manager()pbar=manager.counter(total=100,desc='Basic',unit='ticks')fornuminrange(100):time.sleep(0.1)# Simulate workpbar.update()Additional progress bars can be created with additional calls to theManager.countermethod.importtimeimportenlightenmanager=enlighten.get_manager()ticks=manager.counter(total=100,desc='Ticks',unit='ticks')tocks=manager.counter(total=20,desc='Tocks',unit='tocks')fornuminrange(100):time.sleep(0.1)# Simulate workprint(num)ticks.update()ifnotnum%5:tocks.update()manager.stop()CountersTheCounterclass has two output formats, progress bar and counter.The progress bar format is used when a total is notNoneand the count is less than the
total. If neither of these conditions are met, the counter format is used:importtimeimportenlightenmanager=enlighten.get_manager()counter=manager.counter(desc='Basic',unit='ticks')fornuminrange(100):time.sleep(0.1)# Simulate workcounter.update()Status BarsStatus bars are bars that work similarly to progress bars and counters, but present relatively
static information. Status bars are created withManager.status_bar.importenlightenimporttimemanager=enlighten.get_manager()status_bar=manager.status_bar('Static Message',color='white_on_red',justify=enlighten.Justify.CENTER)time.sleep(1)status_bar.update('Updated static message')time.sleep(1)Status bars can also use formatting with dynamic variables.importenlightenimporttimemanager=enlighten.get_manager()status_format='{program}{fill}Stage:{stage}{fill}Status{status}'status_bar=manager.status_bar(status_format=status_format,color='bold_slategray',program='Demo',stage='Loading',status='OKAY')time.sleep(1)status_bar.update(stage='Initializing',status='OKAY')time.sleep(1)status_bar.update(status='FAIL')Status bars, like other bars can be pinned. To pin a status bar to the top of all other bars,
initialize it before any other bars. To pin a bar to the bottom of the screen, useposition=1when initializing.SeeStatusBarfor more details.ColorStatus bars and the bar component of a progress bar can be colored by setting thecolorkeyword argument. SeeSeries Colorfor more
information about valid colors.importtimeimportenlightenmanager=enlighten.get_manager()counter=manager.counter(total=100,desc='Colorized',unit='ticks',color='red')fornuminrange(100):time.sleep(0.1)# Simulate workcounter.update()Additionally, any part of the progress bar can be colored usingcounter
formattingand thecolor capabilitiesof the underlyingBlessedTerminal.importenlightenmanager=enlighten.get_manager()# Standard bar formatstd_bar_format=u'{desc}{desc_pad}{percentage:3.0f}%|{bar}| '+\u'{count:{len_total}d}/{total:d}'+\u'[{elapsed}<{eta},{rate:.2f}{unit_pad}{unit}/s]'# Red textbar_format=manager.term.red(std_bar_format)# Red on white backgroundbar_format=manager.term.red_on_white(std_bar_format)# X11 colorsbar_format=manager.term.peru_on_seagreen(std_bar_format)# RBG textbar_format=manager.term.color_rgb(2,5,128)(std_bar_format)# RBG backgroundbar_format=manager.term.on_color_rgb(255,190,195)(std_bar_format)# RGB text and backgroundbar_format=manager.term.on_color_rgb(255,190,195)(std_bar_format)bar_format=manager.term.color_rgb(2,5,128)(bar_format)# Apply color to select partsbar_format=manager.term.red(u'{desc}')+u'{desc_pad}'+\manager.term.blue(u'{percentage:3.0f}%')+u'|{bar}|'# Apply to counterticks=manager.counter(total=100,desc='Ticks',unit='ticks',bar_format=bar_format)If thecoloroption is applied to aCounter,
it will override any foreground color applied.MulticoloredThe bar component of a progress bar can be multicolored to track multiple categories in a single
progress bar.The colors are drawn from right to left in the order they were added.By default, when multicolored progress bars are used, additional fields are available forbar_format:count_n (int) - Current value ofcountcount_0(int) - Remaining count after deducting counts for all subcounterscount_00 (int) - Sum of counts from all subcounterspercentage_n (float) - Percentage completepercentage_0(float) - Remaining percentage after deducting percentages
for all subcounterspercentage_00 (float) - Total of percentages from all subcountersWhenCounter.add_subcounteris called withall_fieldsset toTrue,
the subcounter will have the additional fields:eta_n (str) - Estimated time to completionrate_n (float) - Average increments per second since parent was createdMore information aboutbar_formatcan be found in theFormatsection of the API.One use case for multicolored progress bars is recording the status of a series of tests.
In this example, Failures are red, errors are white, and successes are green. The count of each is
listed in the progress bar.importrandomimporttimeimportenlightenbar_format=u'{desc}{desc_pad}{percentage:3.0f}%|{bar}| '+\u'S:{count_0:{len_total}d} '+\u'F:{count_2:{len_total}d} '+\u'E:{count_1:{len_total}d} '+\u'[{elapsed}<{eta},{rate:.2f}{unit_pad}{unit}/s]'manager=enlighten.get_manager()success=manager.counter(total=100,desc='Testing',unit='tests',color='green',bar_format=bar_format)errors=success.add_subcounter('white')failures=success.add_subcounter('red')whilesuccess.count<100:time.sleep(random.uniform(0.1,0.3))# Random processing timeresult=random.randint(0,10)ifresult==7:errors.update()ifresultin(5,6):failures.update()else:success.update()A more complicated example is recording process start-up. In this case, all items will start red,
transition to yellow, and eventually all will be green. The count, percentage, rate, and eta fields
are all derived from the second subcounter added.importrandomimporttimeimportenlightenservices=100bar_format=u'{desc}{desc_pad}{percentage_2:3.0f}%|{bar}|'+\u' {count_2:{len_total}d}/{total:d}'+\u'[{elapsed}<{eta_2},{rate_2:.2f}{unit_pad}{unit}/s]'manager=enlighten.get_manager()initializing=manager.counter(total=services,desc='Starting',unit='services',color='red',bar_format=bar_format)starting=initializing.add_subcounter('yellow')started=initializing.add_subcounter('green',all_fields=True)whilestarted.count<services:remaining=services-initializing.countifremaining:num=random.randint(0,min(4,remaining))initializing.update(num)ready=initializing.count-initializing.subcountifready:num=random.randint(0,min(3,ready))starting.update_from(initializing,num)ifstarting.count:num=random.randint(0,min(2,starting.count))started.update_from(starting,num)time.sleep(random.uniform(0.1,0.5))# Random processing timeAdditional Examplesbasic- Basic progress barcontext manager- Managers and counters as context managersfloats- Support totals and counts that arefloatsmulticolored- Multicolored progress barsmultiple with logging- Nested progress bars and loggingFTP downloader- Show progress downloading files from FTPCustomizationEnlighten is highly configurable. For information on modifying the output, see theSeriesandFormatsections of theCounterdocumentation.