Yet Another Terminal Spinner
yaspin is a Python library that provides a simple and flexible way to display terminal spinners for CLI applications, indicating ongoing operations. It is currently at version 3.4.0 and maintains a regular release cadence, often updating with new features, dependency bumps, and Python version support.
Warnings
- breaking Python 3.8 and 3.9 support has been dropped in recent major versions. Yaspin v3.0.0 dropped Python 3.8, and v3.4.0 dropped Python 3.9. Ensure your environment uses Python 3.10 or newer.
- breaking Version 3.0.0 introduced significant breaking changes, including the removal of previously exposed modules (base_spinner, helpers, signal_handlers) and constants (constants.COLOR_MAP).
- deprecated The `is_jupyter()` method has been deprecated.
- gotcha While yaspin aims for 'pipe safety', early versions and certain terminal environments (especially on Windows) might exhibit issues where spinner control characters are visible when piping output to files or other programs.
- gotcha Integrating yaspin with complex multithreaded applications might require careful synchronization to prevent display glitches or unexpected behavior, as multiple threads writing to the console can interfere with the spinner's output.
Install
-
pip install yaspin
Imports
- yaspin
from yaspin import yaspin
- Spinner
from yaspin import Spinner
Quickstart
import time
from yaspin import yaspin
# Basic usage as a context manager
with yaspin(text="Processing...") as sp:
time.sleep(2) # Simulate work
sp.ok("✔") # Mark as success
# Example with custom spinner and colors
from yaspin.spinners import Spinners
with yaspin(Spinners.earth, text="Loading data...").white.on_blue as sp:
time.sleep(3)
if time.time() % 2 == 0: # Simulate a random outcome
sp.fail("✘") # Mark as failure
else:
sp.ok("✨") # Mark with a sparkle