Rich Progress Bar for CLI
Display beautiful progress bars and status spinners in CLI applications using the Rich library.
from rich.progress import Progress, SpinnerColumn, BarColumn, TextColumn
import time
def process_files(files: list[str]) -> None:
with Progress(
SpinnerColumn(),
TextColumn("[bold blue]{task.description}"),
BarColumn(),
TextColumn("[progress.percentage]{task.percentage:>3.0f}%"),
TextColumn("({task.completed}/{task.total})"),
) as progress:
task = progress.add_task("Processing files", total=len(files))
for f in files:
# Simulate work
time.sleep(0.1)
progress.update(task, advance=1, description=f"Processing {f}")
# process_files(["file1.csv", "file2.csv", "file3.csv"])Use Cases
- Data processing scripts
- File download indicators
- Build step visualization
Tags
Related Snippets
Similar patterns you can reuse in the same workflow.
CLI Tool with argparse
Build a professional CLI tool with subcommands, typed arguments, environment variable fallbacks, and help text.
Click CLI Command Group
Build professional CLI tools with Click using command groups, options, arguments, and help text.
Async HTTP Client with httpx
Production-ready async HTTP client using httpx with retries, timeouts, and connection pooling.
Retry Decorator with Exponential Backoff
Generic retry decorator with configurable attempts, exponential backoff, and exception filtering.