A new kind of Progress Bar, with real-time throughput, ETA, and very cool animations!
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Advanced animation creation system with factories for custom spinners and bars. Supports frame-based, scrolling, bouncing, sequential, alongside, and delayed animations with extensive customization options for creating unique visual effects.
Factory function for creating custom bar animations with configurable styles, effects, and behaviors.
def bar_factory(chars=None, *, tip=None, background=None, borders=None, errors=None):
"""
Create custom bar animations.
Parameters:
- chars (Optional[str]): The sequence of increasing glyphs to fill the bar. Can be None for transparent fill.
- tip (Optional[str]): The tip in front of the bar. Can be None unless chars is also None.
- background (Optional[str]): The pattern to be used underneath the bar.
- borders (Optional[Union[str, Tuple[str, str]]]): The pattern or patterns to be used before and after the bar.
- errors (Optional[Union[str, Tuple[str, str]]]): The pattern or patterns to be used for error indication.
Returns:
Bar factory function that creates bar instances
"""from alive_progress.animations import bar_factory
from alive_progress import alive_bar
# Create custom bar with specific characters
custom_bar = bar_factory(
chars='▁▂▃▄▅▆▇█',
background='░',
tip='▶'
)
with alive_bar(1000, bar=custom_bar) as bar:
for i in range(1000):
process_item(i)
bar()Creates spinners from sequences of frames, supporting static frame sequences and custom frame timing.
def frame_spinner_factory(*frames):
"""
Create frame-based spinners from character sequences.
Parameters:
- *frames (Union[str, Tuple[str, ...]]): The frames to be displayed, split by cycles.
If sent only a string, it is interpreted as frames of a single char each.
Returns:
Spinner factory function that creates frame-based spinners
"""from alive_progress.animations import frame_spinner_factory
from alive_progress import alive_bar
# Simple rotating spinner
rotating_spinner = frame_spinner_factory('|/-\\')
with alive_bar(1000, spinner=rotating_spinner) as bar:
for i in range(1000):
process_item(i)
bar()
# Complex multi-character frames
complex_spinner = frame_spinner_factory('◐◓◑◒')
# Custom timing - multiple cycles
timed_spinner = frame_spinner_factory(
('⠋', '⠙', '⠹', '⠸', '⠼'), # First cycle
('⠴', '⠦', '⠧', '⠇', '⠏') # Second cycle
)Creates horizontally scrolling spinner animations with configurable direction, speed, and wrapping behavior.
def scrolling_spinner_factory(chars, length=None, block=None, background=None, *,
right=True, hide=True, wrap=True, overlay=False):
"""
Create horizontally scrolling spinner animations.
Parameters:
- chars (str): The characters to be scrolled, either together or split in blocks.
- length (Optional[int]): The natural length that should be used in the style.
- block (Optional[int]): If defined, split chars in blocks with this size.
- background (Optional[str]): The pattern to be used besides or underneath the animations.
- right (bool): The scroll direction to animate (default: True).
- hide (bool): Controls whether the animation goes through the borders or not (default: True).
- wrap (bool): Makes the animation wrap borders or stop when not hiding (default: True).
- overlay (bool): Fixes the background in place if overlay, scrolls it otherwise (default: False).
Returns:
Spinner factory function that creates scrolling spinners
"""from alive_progress.animations import scrolling_spinner_factory
from alive_progress import alive_bar
# Simple left-scrolling text
scroll_left = scrolling_spinner_factory('Processing...', right=False)
with alive_bar(1000, spinner=scroll_left) as bar:
for i in range(1000):
process_item(i)
bar()
# Right-scrolling with custom characters
scroll_right = scrolling_spinner_factory('◆◇◆◇', right=True, length=8)
# Marquee-style scrolling
marquee = scrolling_spinner_factory(
'Loading Data',
length=15,
right=True,
wrap=True,
spacing=3
)Creates spinners with bouncing animations that move back and forth across a defined space.
def bouncing_spinner_factory(chars, length=None, block=None, background=None, *,
right=True, hide=True, overlay=False):
"""
Create spinners that bounce back and forth.
Parameters:
- chars (str): The characters to animate in bouncing motion.
- length (Optional[int]): The natural length that should be used in the style.
- block (Optional[int]): If defined, split chars in blocks with this size.
- background (Optional[str]): The pattern to be used besides or underneath the animations.
- right (bool): The initial direction to animate (default: True).
- hide (bool): Controls whether the animation goes through the borders or not (default: True).
- overlay (bool): Fixes the background in place if overlay, scrolls it otherwise (default: False).
Returns:
Spinner factory function that creates bouncing spinners
"""from alive_progress.animations import bouncing_spinner_factory
from alive_progress import alive_bar
# Simple bouncing ball
bouncing_ball = bouncing_spinner_factory('●', length=10)
with alive_bar(1000, spinner=bouncing_ball) as bar:
for i in range(1000):
process_item(i)
bar()
# Multi-character bouncing
bouncing_arrow = bouncing_spinner_factory('→', length=15, speed=2)
# Bouncing with trail effect
bouncing_trail = bouncing_spinner_factory('★', length=12, trail=True)Creates spinners with character sequences that change over time, supporting various progression patterns.
def sequential_spinner_factory(*spinner_factories, intermix=True):
"""
Create spinners that combine other spinners sequentially.
Parameters:
- *spinner_factories (spinner): The spinners to be combined.
- intermix (bool): Intermixes the cycles if True, generating all possible combinations;
runs each one until depletion otherwise (default: True).
Returns:
Spinner factory function that creates sequential spinners
"""from alive_progress.animations import sequential_spinner_factory
from alive_progress import alive_bar
# Sequential combination of different spinners
spinner1 = frame_spinner_factory('⠀⠄⠆⠇⡇⡗⡟⡿⣿')
spinner2 = frame_spinner_factory('░▒▓█')
loading_seq = sequential_spinner_factory(spinner1, spinner2)
with alive_bar(1000, spinner=loading_seq) as bar:
for i in range(1000):
process_item(i)
bar()
# Multiple spinner sequence without intermixing
fast_spinner = frame_spinner_factory('|/-\\')
slow_spinner = frame_spinner_factory('◐◓◑◒')
brightness = sequential_spinner_factory(fast_spinner, slow_spinner, intermix=False)
# Three-phase sequential animation
phase1 = frame_spinner_factory('123')
phase2 = frame_spinner_factory('456')
phase3 = frame_spinner_factory('789🚀')
countdown = sequential_spinner_factory(phase1, phase2, phase3)Creates spinners that display multiple elements together, supporting parallel animations and composite effects.
def alongside_spinner_factory(*spinner_factories, pivot=None):
"""
Create spinners that display multiple elements together.
Parameters:
- *spinner_factories (spinner): The spinners to be combined.
- pivot (Optional[int]): The index of the spinner to dictate the animation cycles.
If None, the whole animation will be compiled into a unique cycle.
Returns:
Spinner factory function that creates alongside spinners
"""from alive_progress.animations import alongside_spinner_factory, frame_spinner_factory
from alive_progress import alive_bar
# Combine multiple spinners
spinner1 = frame_spinner_factory('|/-\\')
spinner2 = frame_spinner_factory('◐◓◑◒')
combined = alongside_spinner_factory(spinner1, spinner2)
with alive_bar(1000, spinner=combined) as bar:
for i in range(1000):
process_item(i)
bar()
# Text and animation together with pivot control
text_spinner = frame_spinner_factory(('Loading.', 'Loading..', 'Loading...'))
symbol_spinner = frame_spinner_factory('⠋⠙⠹⠸')
loading_combo = alongside_spinner_factory(text_spinner, symbol_spinner, pivot=0)Creates spinners with timing delays and custom pacing for sophisticated animation control.
def delayed_spinner_factory(spinner_factory, copies, offset=1, *, dynamic=True):
"""
Create spinners with timing delays and custom pacing.
Parameters:
- spinner_factory (spinner): The source spinner.
- copies (int): The number of copies.
- offset (int): The offset to be applied incrementally to each copy (default: 1).
- dynamic (bool): Dynamically changes the number of copies based on available space (default: True).
Returns:
Spinner factory function that creates delayed spinners
"""from alive_progress.animations import delayed_spinner_factory, frame_spinner_factory
from alive_progress import alive_bar
# Base spinner
base = frame_spinner_factory('⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏')
# Create delayed spinner with 3 copies
delayed = delayed_spinner_factory(base, copies=3, offset=1)
with alive_bar(1000, spinner=delayed) as bar:
for i in range(1000):
process_item(i)
bar()
# More copies with larger offset
multi_copy = delayed_spinner_factory(base, copies=5, offset=2)
# Fixed number of copies (non-dynamic)
fixed_copies = delayed_spinner_factory(
base,
copies=4,
offset=1,
dynamic=False # Won't adjust based on available space
)Utility function for playing and controlling spinner animations programmatically.
def spinner_player(spinner):
"""
Create an infinite generator that plays all cycles of a spinner indefinitely.
Parameters:
- spinner: Spinner factory to play
Returns:
Generator that yields animation frames indefinitely
"""from alive_progress.animations import spinner_player, frame_spinner_factory
# Create and play spinner
spinner = frame_spinner_factory('⠋⠙⠹⠸')
player = spinner_player(spinner)
# Manually control animation
import time
for i, frame in enumerate(player):
print(f'\r{frame}', end='', flush=True)
time.sleep(0.1)
# Stop after some condition
if i > 50: # Stop after 50 frames
breakfrom alive_progress.animations import (
frame_spinner_factory,
delayed_spinner_factory,
scrolling_spinner_factory
)
# Create base animation
base_frames = ['◐', '◓', '◑', '◒']
base_spinner = frame_spinner_factory(base_frames)
# Add delay
delayed_spinner = delayed_spinner_factory(base_spinner, delay=10)
# Use in progress bar
with alive_bar(1000, spinner=delayed_spinner) as bar:
passimport os
from alive_progress.animations import frame_spinner_factory, scrolling_spinner_factory
# Choose factory based on environment
if os.getenv('SIMPLE_ANIMATIONS'):
spinner_factory = frame_spinner_factory(['|', '/', '-', '\\'])
else:
spinner_factory = scrolling_spinner_factory('Processing...', length=15)
with alive_bar(1000, spinner=spinner_factory) as bar:
pass# For high-performance scenarios, use simpler animations
fast_spinner = frame_spinner_factory(['.', 'o', 'O']) # Minimal frames
# For visual appeal, use complex animations
beautiful_spinner = alongside_spinner_factory(
scrolling_spinner_factory('Loading', right=True),
bouncing_spinner_factory('●', length=10),
separator=' | '
)
# Choose based on performance requirements
spinner = fast_spinner if high_performance_mode else beautiful_spinnerInstall with Tessl CLI
npx tessl i tessl/pypi-alive-progress