### Install alive-progress with pip Source: https://github.com/rsalmei/alive-progress/blob/main/README.md This command installs the alive-progress library using pip, the Python package installer. Ensure you have Python and pip installed on your system. ```sh ❯ pip install alive-progress ``` -------------------------------- ### Run alive-progress showtime example Source: https://github.com/rsalmei/alive-progress/blob/main/README.md This Python code snippet demonstrates how to run the 'showtime' feature of alive-progress, which displays builtin spinner styles. It requires importing the 'showtime' function from 'alive_progress.styles'. ```python from alive_progress.styles import showtime showtime() ``` -------------------------------- ### showtime - View Available Styles (Python) Source: https://context7.com/rsalmei/alive-progress/llms.txt Provides examples of using the showtime utility to view available spinner, bar, and theme styles within the alive-progress library. It also demonstrates filtering styles by pattern and customizing display options like refresh rate and length. ```python from alive_progress.styles import showtime, Show # Display all spinner styles showtime(Show.SPINNERS) # Display all bar styles showtime(Show.BARS) # Display all themes showtime(Show.THEMES) # Filter by pattern showtime(pattern='boat|fish|crab') # Custom refresh rate and length showtime(fps=30, length=60) ``` -------------------------------- ### Interactive Transaction Reconciliation Example (Text) Source: https://github.com/rsalmei/alive-progress/blob/main/README.md This text-based output illustrates the interactive nature of the alive-progress pause mechanism. It shows the progress bar state before pausing and yielding a faulty transaction, and then the state after resuming the process. This output is typically seen in an IPython or REPL environment. ```text In [11]: gen = reconcile_transactions() In [12]: next(gen, None) |█████████████████████ | 105/200 [52%] in 5s (18.8/s, eta: 4s) Out[12]: Transaction<#123> In [21]: next(gen, None) |█████████████████████ | ▃▅ 106/200 [52%] in 5s (18.8/s, eta: 4s) ``` -------------------------------- ### Python: Display alive-progress bar styles Source: https://github.com/rsalmei/alive-progress/blob/main/README.md Demonstrates how to use the showtime exhibit from alive_progress.styles to display different progress bar styles, including bars and themes. Requires the alive-progress library to be installed. ```python from alive_progress.styles import showtime, Show showtime(Show.BARS) showtime(Show.THEMES) ``` -------------------------------- ### Force alive-progress Animations in Non-Interactive Terminals (Python) Source: https://github.com/rsalmei/alive-progress/blob/main/README.md This code snippet demonstrates how to force alive-progress animations to display even in non-interactive environments like PyCharm or Jupyter notebooks. It utilizes the `force_tty=True` argument within the `alive_bar` context manager. Ensure `alive-progress` and `time` are installed and imported. ```python import time from alive_progress import alive_bar with alive_bar(1000, force_tty=True) as bar: for i in range(1000): time.sleep(.01) bar() ``` -------------------------------- ### Pause and Yield Transactions with Python Source: https://github.com/rsalmei/alive-progress/blob/main/README.md This Python code demonstrates how to use the alive-progress pause mechanism to yield faulty transactions for manual reconciliation. It iterates through a queryset, checks for faulty transactions, and pauses the progress bar to yield the transaction. Dependencies include alive-progress and a Django ORM example (Transaction.objects.filter()). The input is a queryset of transactions, and the output is a generator yielding faulty transactions. ```python from alive_progress import alive_bar def reconcile_transactions(): # django example, or in sqlalchemy: session.query(Transaction).filter() qs = Transaction.objects.filter() with alive_bar(qs.count()) as bar: for transaction in qs: if faulty(transaction): with bar.pause(): yield transaction bar() ``` -------------------------------- ### Run alive-progress demo tool Source: https://github.com/rsalmei/alive-progress/blob/main/README.md This command executes the alive-progress demo tool, which showcases various progress bar and spinner styles. It is run as a Python module from the command line. ```sh ❯ python -m alive_progress.tools.demo ``` -------------------------------- ### Basic alive_bar Usage with Python Source: https://github.com/rsalmei/alive-progress/blob/main/README.md Demonstrates the fundamental usage of alive_bar as a context manager to display a progress bar during a loop. It shows how to initialize the bar with a total count and update it within the loop. Dependencies include the 'alive_progress' library and 'time' for pausing. ```python from alive_progress import alive_bar import time for x in 1000, 1500, 700, 0: with alive_bar(x) as bar: for i in range(1000): time.sleep(.005) bar() ``` -------------------------------- ### alive_bar - Unit Scaling with Automatic Formatting (Python) Source: https://context7.com/rsalmei/alive-progress/llms.txt Shows how to configure alive_bar to handle unit scaling for different data types, such as bytes (IEC scaling) and temperature. It automatically formats the displayed units for better readability. ```python from alive_progress import alive_bar import time # Bytes with IEC scaling (1024-based) with alive_bar(1048576, unit='B', scale='IEC', precision=2, title='Download') as bar: for i in range(1048576): bar(100) # Increment by 100 bytes # Output: Download |████████| 1.00MiB/1.00MiB [100%] in 5.2s (195.12KiB/s) # Temperature measurements with custom unit with alive_bar(1000, unit='°C', title='Sensors') as bar: for i in range(1000): time.sleep(0.005) bar() # Output: Sensors |████████| 1000°C/1000°C [100%] in 5.0s (200.0°C/s) ``` -------------------------------- ### Manual mode with alive_bar in Python Source: https://github.com/rsalmei/alive-progress/blob/main/README.md Demonstrates manual mode activation using `manual=True` with `alive_bar`. This requires explicit calls to `bar()` to update the progress, typically with a percentage. Dependencies: alive-progress library. ```python from alive_progress import alive_bar # Example: Simulate a process that reports percentage completion for i in range(100): # In a real scenario, you'd get a percentage from your process percentage = (i + 1) / 100.0 with alive_bar(manual=True) as bar: bar(percentage) # Manually set the progress to 15% # Simulate work import time time.sleep(0.05) ``` -------------------------------- ### alive_bar - Retrieve Widget Data and Receipt (Python) Source: https://context7.com/rsalmei/alive-progress/llms.txt Demonstrates how to retrieve real-time data from an alive_bar instance, such as current progress, monitor status, rate, ETA, and elapsed time. It also shows how to access the final receipt after the progress bar completes. ```python from alive_progress import alive_bar import time with alive_bar(100, title='Processing') as bar: for i in range(100): time.sleep(0.02) bar() if i == 50: print(f'Current: {bar.current}') print(f'Monitor: {bar.monitor}') print(f'Rate: {bar.rate}') print(f'ETA: {bar.eta}') print(f'Elapsed: {bar.elapsed:.2f}s') # Access final receipt after completion receipt = bar.receipt print(f'\nFinal receipt:\n{receipt}') ``` -------------------------------- ### config_handler - Global Configuration (Python) Source: https://context7.com/rsalmei/alive-progress/llms.txt Details how to use config_handler to set global default configurations for alive-progress bars, such as length, spinner, bar style, and theme. It also shows how local options can override global settings and how to reset to defaults. ```python from alive_progress import alive_bar, config_handler import time # Set global defaults config_handler.set_global( length=30, spinner='dots', bar='smooth', theme='smooth' ) # All subsequent bars use global config with alive_bar(100) as bar: for i in range(100): time.sleep(0.02) bar() # Local options override global with alive_bar(100, length=50, spinner='twirls') as bar: for i in range(100): time.sleep(0.02) bar() # Reset to defaults config_handler.reset() ``` -------------------------------- ### alive_it - With Bar Handle for Customization (Python) Source: https://context7.com/rsalmei/alive-progress/llms.txt Explains how to use alive_it with a bar handle, allowing for dynamic updates to the progress bar's text during iteration. This enables displaying context-specific information, like the current item being processed. ```python from alive_progress import alive_it import time items = range(100) bar = alive_it(items, title='Processing items') for item in bar: bar.text = f'Current: {item}' time.sleep(0.05) # Output updates with current item displayed ``` -------------------------------- ### Set Local alive_bar Configuration Source: https://github.com/rsalmei/alive-progress/blob/main/README.md Demonstrates how to configure alive-progress options directly within an `alive_bar` context manager. Local settings override global configurations. ```python from alive_progress import alive_bar total = 100 with alive_bar(total, title='Processing', length=20, bar='halloween') as bar: for i in range(total): # Simulate work pass ``` -------------------------------- ### alive_bar - Custom Styling with Themes and Animations (Python) Source: https://context7.com/rsalmei/alive-progress/llms.txt Illustrates how to customize the appearance of alive_bar progress bars using built-in themes, custom spinner and bar styles, and by hiding specific widgets. This allows for tailored visual feedback during long-running operations. ```python from alive_progress import alive_bar import time # Use built-in theme with alive_bar(1000, theme='smooth', title='Download') as bar: for i in range(1000): time.sleep(0.005) bar() # Custom spinner and bar styles with alive_bar(1000, spinner='dots', bar='blocks', title='Upload') as bar: for i in range(1000): time.sleep(0.005) bar() # Hide specific widgets with alive_bar(1000, spinner=None, monitor=False) as bar: for i in range(1000): time.sleep(0.005) bar() ``` -------------------------------- ### Create Custom Bar Style with bar_factory Source: https://context7.com/rsalmei/alive-progress/llms.txt Shows how to create custom progress bar styles using the bar_factory function. Allows customization of characters, tip, background, borders, and error indicators. These custom bars provide alternative visual representations for progress. ```python from alive_progress import alive_bar from alive_progress.animations.bars import bar_factory import time # Custom block-style bar custom_bar = bar_factory( chars=' ▏▎▍▌▋▊▉█', tip='▶', background='░', borders='|', errors=('⚠', '✗') ) with alive_bar(100, bar=custom_bar, unknown=None) as bar: for i in range(100): time.sleep(0.05) bar() # Transparent bar with only tip transparent_bar = bar_factory( chars=None, tip='▶▶▶', background='.', borders='[]' ) with alive_bar(100, bar=transparent_bar, unknown=None) as bar: for i in range(100): time.sleep(0.05) bar() ``` -------------------------------- ### Basic Progress Bar with Known Total (Python) Source: https://context7.com/rsalmei/alive-progress/llms.txt Demonstrates the basic usage of `alive_bar` to track progress with a known total number of items. It simulates work using `time.sleep` and increments the bar with `bar()`. The output shows the progress, percentage, and estimated time. ```python from alive_progress import alive_bar import time # Track progress for 1000 items with alive_bar(1000, title='Processing items') as bar: for i in range(1000): time.sleep(0.005) # Simulate work bar() # Increment progress # Output: Processing items |████████████████████| 1000/1000 [100%] in 5.8s (171.62/s) ``` -------------------------------- ### Integrating alive_bar with Custom Loops in Python Source: https://github.com/rsalmei/alive-progress/blob/main/README.md Illustrates how to wrap a standard Python loop with the alive_bar context manager. This allows for progress visualization by calling the bar() function at the end of each iteration. The 'total' variable should represent the expected number of items. ```python from alive_progress import alive_bar # Assume 'total' and 'items' are defined elsewhere # total = len(items) or a known count # items = [...] or any iterable with alive_bar(total) as bar: for item in items: # process each item print(item) bar() ``` -------------------------------- ### Set Global alive-progress Configuration Source: https://github.com/rsalmei/alive-progress/blob/main/README.md Shows how to set global configuration options for alive-progress using `config_handler`. These settings apply to all `alive_bar` instances created afterward, unless overridden locally. ```python from alive_progress import alive_bar, config_handler total = 100 # Set global configuration config_handler.set_global(length=20, spinner='wait') with alive_bar(total, bar='blocks', spinner='twirls') as bar: # The length will be 20 (global), the bar is 'blocks' (local), # and the spinner is 'twirls' (local). for i in range(total): # Simulate work pass ``` -------------------------------- ### Dual Line Progress Bar with Text Below (Python) Source: https://github.com/rsalmei/alive-progress/blob/main/README.md Demonstrates creating a dual-line progress bar using alive-progress, allowing text to be displayed below the main bar and handling print statements that scroll above it. This feature is useful for providing detailed status updates during long operations. ```python from alive_progress import alive_bar import time letters = [chr(ord('A') + x) for x in range(26)] with alive_bar(26, dual_line=True, title='Alphabet') as bar: for c in letters: bar.text = f'-> Teaching the letter: {c}, please wait...' if c in 'HKWZ': print(f'fail "{c}", retry later') time.sleep(0.3) bar() ``` -------------------------------- ### alive_it - Automatic Iterator Adapter (Python) Source: https://context7.com/rsalmei/alive-progress/llms.txt Introduces alive_it, a convenient adapter for iterators that automatically creates and manages a progress bar. It simplifies the process of displaying progress for loops iterating over sequences. ```python from alive_progress import alive_it import time # Simplest usage - automatically tracks items items = range(1000) for item in alive_it(items): time.sleep(0.005) # Output: |████████████████████| 1000/1000 [100%] in 5.0s (200.0/s) ``` -------------------------------- ### alive_bar - Custom Widget Formatting (Python) Source: https://context7.com/rsalmei/alive-progress/llms.txt Explains how to customize the text format of various widgets within alive_bar, including the count, percentage, elapsed time, and statistics. This allows for displaying information in a specific, user-defined layout. ```python from alive_progress import alive_bar import time with alive_bar( 1000, monitor='{count} of {total} ({percent:.1%})', elapsed='elapsed: {elapsed}', stats='speed: {rate}, remaining: {eta}', title='Custom Format' ) as bar: for i in range(1000): time.sleep(0.005) bar() # Output: Custom Format |████| 500 of 1000 (50.0%) elapsed: 2.5s speed: 200.0/s, remaining: 2.5s ``` -------------------------------- ### Python: Filter alive-progress themes with showtime Source: https://github.com/rsalmei/alive-progress/blob/main/README.md Shows how to use the showtime exhibit with a pattern argument to filter and display specific themes, such as marine-themed spinners. This allows for customized visual outputs in the progress bar. ```python showtime(pattern='boat|fish|crab') ``` -------------------------------- ### Manual Percentage Control Progress Bar (Python) Source: https://context7.com/rsalmei/alive-progress/llms.txt Illustrates manual control of the progress bar using percentages. The `manual=True` argument allows explicit setting of the bar's completion status by calling `bar()` with a float between 0.0 and 1.0. This is useful for tasks where progress is not directly item-based. ```python from alive_progress import alive_bar import time # Manually control bar position with percentages with alive_bar(4, manual=True, title='Processing') as bar: time.sleep(1) bar(0.1) # 10% complete time.sleep(1) bar(0.4) # 40% complete time.sleep(1) bar(0.6) # 60% complete time.sleep(1) bar(1.0) # 100% complete # Output: Processing |████████████████████| 100.0% in 4.0s ``` -------------------------------- ### Naive Loop-less Progress Bar Update with alive-progress Source: https://github.com/rsalmei/alive-progress/blob/main/README.md Demonstrates a basic method to update alive-progress for a fixed sequence of operations without loops. Each bar() call signifies the completion of a distinct step. This approach is naive as it assumes each step takes equal time, potentially leading to misleading ETAs. ```python from alive_progress import alive_bar # Assume read_file, tokenize, process, send are defined elsewhere # corpus = read_file(file) # tokens = tokenize(corpus) # data = process(tokens) # resp = send(data) with alive_bar(4) as bar: corpus = read_file(file) bar() # file was read, tokenizing tokens = tokenize(corpus) bar() # tokens generated, processing data = process(tokens) bar() # process finished, sending response resp = send(data) bar() # we're done! four bar calls with `total=4` ``` -------------------------------- ### Skipping Items for Accurate ETA (Python) Source: https://context7.com/rsalmei/alive-progress/llms.txt Demonstrates how to use the `skipped=True` argument in `bar()` to account for items that do not require processing. This ensures that the Estimated Time of Arrival (ETA) remains accurate by only considering the time spent on actual work. ```python from alive_progress import alive_bar # Skip already-processed items to maintain accurate ETA with alive_bar(120000) as bar: bar(60000, skipped=True) # Skip first 60k items for i in range(60000, 120000): # Process only remaining items bar() ``` -------------------------------- ### Print Integration for Logging (Python) Source: https://context7.com/rsalmei/alive-progress/llms.txt Shows how `alive_bar` automatically handles `print` statements, ensuring they appear above the progress bar without disrupting its animation. This allows for integrated logging and status messages alongside progress tracking. ```python from alive_progress import alive_bar import time with alive_bar(100) as bar: for i in range(100): if i % 25 == 0: print(f'Checkpoint: {i} items processed') time.sleep(0.05) bar() # Output: # on 0: Checkpoint: 0 items processed # on 25: Checkpoint: 25 items processed # on 50: Checkpoint: 50 items processed # on 75: Checkpoint: 75 items processed # |████████████████████| 100/100 [100%] in 5.0s (20.0/s) ``` -------------------------------- ### Auto-iterating with alive_it in Python Source: https://github.com/rsalmei/alive-progress/blob/main/README.md Demonstrates the basic usage of alive_it to wrap an iterable, automatically tracking progress. The loop processes each item, and the progress bar updates without manual intervention. Dependencies: alive-progress library. ```python from alive_progress import alive_it items = range(100) # Example iterable for item in alive_it(items): # process each item print(item) # This would typically be your processing logic ``` -------------------------------- ### Measuring Step Durations with about-time for Accurate ETA Source: https://github.com/rsalmei/alive-progress/blob/main/README.md Utilizes the 'about-time' library to measure the duration of individual steps within a block of code. This allows for the calculation of relative timings, which can then be used to provide a more accurate progress indication and ETA in alive-progress. ```python from about_time import about_time from alive_progress import alive_bar # Assume read_file, tokenize, process, send are defined elsewhere # file = "your_file.txt" with about_time() as t_total: # this about_time will measure the whole time of the block. with about_time() as t1: # the other four will get the relative timings within the whole. corpus = read_file(file) # `about_time` supports several calling conventions, including one-liners. with about_time() as t2: # see its documentation for more details. tokens = tokenize(corpus) with about_time() as t3: data = process(tokens) with about_time() as t4: resp = send(data) percentage1 = t1.duration / t_total.duration percentage2 = t2.duration / t_total.duration percentage3 = t3.duration / t_total.duration percentage4 = t4.duration / t_total.duration print(f'percentage1 = {percentage1}') print(f'percentage2 = {percentage2}') print(f'percentage3 = {percentage3}') print(f'percentage4 = {percentage4}') # Example of using these percentages with alive_bar with alive_bar(4, manual=True) as bar: corpus = read_big_file() # Assume read_big_file is defined bar(percentage1) # First step completion tokens = tokenize(corpus) bar(percentage1 + percentage2) # Second step completion (cumulative) data = process(tokens) bar(percentage1 + percentage2 + percentage3) # Third step completion (cumulative) resp = send(data) bar(1.0) # Always 1.0 in the last step ``` -------------------------------- ### alive_bar Bar Handler Methods in Python Source: https://github.com/rsalmei/alive-progress/blob/main/README.md Showcases various methods available on the 'bar' handler object after initializing alive_bar. These methods allow dynamic control and information retrieval, such as setting messages, titles, and accessing current status like elapsed time, ETA, and rate. ```python # Assume 'bar' is an alive_bar instance # Set a situational message bar.text('Processing item...') # Or bar.text = 'Processing item...' # Set a title bar.title('Data Import') # Or bar.title = 'Data Import' # Retrieve current bar count or percentage current_count = bar.current # Get formatted monitor text monitor_text = bar.monitor # Get formatted ETA text eta_text = bar.eta # Get formatted throughput text rate_text = bar.rate # Get elapsed time in seconds elapsed_time = bar.elapsed # Get an on-demand receipt receipt_info = bar.receipt # Pause the bar bar.pause() ``` -------------------------------- ### Dynamic Text and Title Updates (Python) Source: https://context7.com/rsalmei/alive-progress/llms.txt Demonstrates how to dynamically update the text displayed below the progress bar and the title of the bar itself during execution. This allows for providing real-time status updates relevant to the current step of the operation. ```python from alive_progress import alive_bar import time with alive_bar(100, title='Database sync') as bar: for i in range(100): bar.text = f'Processing record {i+1}' time.sleep(0.05) bar() if i == 50: bar.title = 'Database sync - halfway there!' # Output updates in real-time with current text displayed ``` -------------------------------- ### Create Custom Spinner with frame_spinner_factory Source: https://context7.com/rsalmei/alive-progress/llms.txt Demonstrates how to create custom spinners using the frame_spinner_factory function from alive_progress. Supports simple rotating strings and multi-frame animations. Spinners are used as the visual indicator in the progress bar. ```python from alive_progress import alive_bar from alive_progress.animations.spinners import frame_spinner_factory import time # Simple rotating spinner custom_spinner = frame_spinner_factory('|/-\\') with alive_bar(100, spinner=custom_spinner) as bar: for i in range(100): time.sleep(0.05) bar() # Multi-frame spinner with cycles fancy_spinner = frame_spinner_factory( ('⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏') ) with alive_bar(100, spinner=fancy_spinner) as bar: for i in range(100): time.sleep(0.05) bar() ``` -------------------------------- ### Unknown mode without total in alive_bar in Python Source: https://github.com/rsalmei/alive-progress/blob/main/README.md Illustrates 'unknown mode' where `total` is not provided to `alive_bar`. Progress is indeterminable, showing an animated bar, spinner, counter, and throughput without ETA. Dependencies: alive-progress library. ```python from alive_progress import alive_bar import time # No total provided, enters unknown mode with alive_bar() as bar: for i in range(200): # Simulate some work time.sleep(0.01) bar() # Increment the progress bar ``` -------------------------------- ### alive_bar - Error Handling and CTRL+C Behavior (Python) Source: https://context7.com/rsalmei/alive-progress/llms.txt Details how to manage CTRL+C interruptions and handle exceptions within alive_bar. It shows how to disable interruption for a smoother user experience and how to gracefully display the progress bar's final state even when errors occur. ```python from alive_progress import alive_bar import time # Disable CTRL+C interruption for smoother experience with alive_bar(1000, ctrl_c=False, title='Processing') as bar: for i in range(1000): time.sleep(0.005) bar() # Pressing CTRL+C stops current iteration but shows receipt # Handle exceptions while showing final state try: with alive_bar(1000) as bar: for i in range(1000): if i == 500: raise ValueError('Simulated error') time.sleep(0.005) bar() except ValueError: print('Error occurred but bar shows progress up to failure') ``` -------------------------------- ### Auto mode with total in alive_bar in Python Source: https://github.com/rsalmei/alive-progress/blob/main/README.md Shows the 'auto mode' where `total` is provided to `alive_bar`. This enables all widgets, including precise bar, spinner, percentage, counter, throughput, and ETA. Dependencies: alive-progress library. ```python from alive_progress import alive_bar import time total_items = 150 with alive_bar(total_items) as bar: for i in range(total_items): # Simulate some work time.sleep(0.02) bar() # Increment the progress bar ``` -------------------------------- ### Progress Bar for Unknown Total (Python) Source: https://context7.com/rsalmei/alive-progress/llms.txt Shows how to use `alive_bar` in an unknown total mode when the total number of items is not known beforehand. The bar will animate without a specific count or percentage until the loop finishes. This is useful for streaming data or indeterminate processes. ```python from alive_progress import alive_bar import time # Track progress without knowing the total with alive_bar() as bar: for i in range(1000): time.sleep(0.005) bar() # Output: |████████████████████| 1000 in 5.8s (172.45/s) ``` -------------------------------- ### alive_it - With Finalize Callback for Final Receipt (Python) Source: https://context7.com/rsalmei/alive-progress/llms.txt Demonstrates how to use a finalize callback with alive_it to perform actions or update the progress bar's state after iteration is complete. This is useful for displaying a final summary or confirmation message. ```python from alive_progress import alive_it import time def finalize_handler(bar): bar.title = 'Database updated' bar.text = f'{bar.current} entries changed' items = range(100) for item in alive_it(items, finalize=finalize_handler, receipt_text=True): time.sleep(0.02) # Output: Database updated |████████| 100/100 [100%] in 2.0s (50.0/s) 100 entries changed ``` -------------------------------- ### Resume Computations in alive-progress (Python) Source: https://github.com/rsalmei/alive-progress/blob/main/README.md Demonstrates how to use the 'skipped' parameter in alive-progress to correctly report ETAs when resuming interrupted or scattered computations. This prevents incorrect ETA calculations by informing the progress bar about items that were already processed. ```python from alive_progress import alive_bar # Example 1: Known number of skipped items with alive_bar(120000) as bar: bar(60000, skipped=True) for i in range(60000, 120000): # process item bar() # Example 2: Unknown or scattered skipped items with alive_bar(120000) as bar: for i in range(120000): if done(i): bar(skipped=True) continue # process item bar() ``` -------------------------------- ### Interacting with alive_it via variable assignment in Python Source: https://github.com/rsalmei/alive-progress/blob/main/README.md Shows how to assign alive_it to a variable to gain access to the internal alive_bar for customization. This allows setting text messages during iteration. Dependencies: alive-progress library. ```python from alive_progress import alive_it items = range(50) # Example iterable bar = alive_it(items) # Assign alive_it to a variable for item in bar: # process each item print(item) # This would typically be your processing logic bar.text(f'Processing item: {item}') # Update text dynamically ``` -------------------------------- ### Using finalize with alive_it in Python Source: https://github.com/rsalmei/alive-progress/blob/main/README.md Illustrates how to use the 'finalize' parameter with alive_it to set a final message or title for the progress bar after iteration completes. Dependencies: alive-progress library. ```python from alive_progress import alive_it items = range(20) # Example iterable # Finalize with a success message alive_it(items, finalize=lambda bar: bar.text('All items processed successfully!')) # Example of processing items within the finalize lambda (though typically for setting text) # alive_it(items, finalize=lambda bar: bar.text(f'Finished processing {bar.current} items')) ``` -------------------------------- ### Interactive Pause Mechanism (Python) Source: https://context7.com/rsalmei/alive-progress/llms.txt Features the `bar.pause()` context manager, which allows the progress bar to be temporarily suspended. This returns control to the Python prompt, enabling interactive debugging or user intervention during long-running operations without terminating the bar. ```python from alive_progress import alive_bar import time def reconcile_transactions(): with alive_bar(200) as bar: for i in range(200): time.sleep(0.05) if i % 50 == 0 and i > 0: # Fault detected with bar.pause(): yield i # Return control to user bar() # Usage in interactive REPL: gen = reconcile_transactions() next(gen, None) # Processes until first fault, then pauses # Bar pauses: |█████████████| 50/200 [25%] in 2.5s (20.0/s, eta: 7.5s) ``` -------------------------------- ### Dual-Line Mode for Long Messages (Python) Source: https://context7.com/rsalmei/alive-progress/llms.txt Utilizes `dual_line=True` to display longer messages or status updates on a separate line below the main progress bar. This prevents cluttering the progress bar itself and is useful for detailed logging during the operation. ```python from alive_progress import alive_bar import time letters = [chr(ord('A') + x) for x in range(26)] with alive_bar(26, dual_line=True, title='Teaching Alphabet') as bar: for c in letters: bar.text = f'-> Teaching letter: {c}, please wait...' if c in 'HKWZ': print(f'Failed "{c}", retry later') time.sleep(0.3) bar() # Output: # on 7: Failed "H", retry later # Teaching Alphabet |███████████████| ▃▅▇ 18/26 [69%] in 6s (3.2/s, eta: 3s) # -> Teaching letter: S, please wait... ``` -------------------------------- ### Progress Bar with Disabled CTRL+C (Python) Source: https://github.com/rsalmei/alive-progress/blob/main/README.md Illustrates how to disable the CTRL+C interrupt for an alive-progress bar. This can make interactive applications smoother, especially when the progress bar is at the top level of the program, by preventing stack traces upon interruption. Caution is advised when used within loops. ```python from alive_progress import alive_bar import time for i in range(10): with alive_bar(100, ctrl_c=False, title=f'Download {i}') as bar: for j in range(100): time.sleep(0.02) bar() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.