Spinners for Terminals

0.0.24 · maintenance · verified Sat Apr 11

A Python port of the `cli-spinners` Node.js library, this package provides access to over 60 different terminal spinner definitions. Each definition includes the animation frames and the recommended interval between frames. It serves as a data source for spinner designs rather than a full-featured spinning utility. For more advanced usage, such as animating spinners with context managers or decorators, other libraries like `halo` or `yaspin` are often recommended as wrappers. The current version is 0.0.24, released in February 2020. [1, 2, 6]

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to import the `Spinners` Enum and access the raw frame sequences and intervals for a specific spinner. It then provides a basic, manual loop to illustrate how this data can be used to animate a spinner in the terminal. It's important to note that this library only provides the spinner definitions; the animation logic itself needs to be implemented by the user or by using a wrapper library.

import time
from spinners import Spinners

# Get the data for a specific spinner (e.g., 'dots')
dots_spinner_data = Spinners.dots.value

print(f"Spinner frames for 'dots': {dots_spinner_data['frames']}")
print(f"Spinner interval for 'dots': {dots_spinner_data['interval']}ms")

# --- This library provides data; animation must be custom or via another library ---
# Example of manually animating a spinner based on its data:
print("\nManually animating 'dots' spinner for 2 seconds:")
end_time = time.time() + 2
while time.time() < end_time:
    for frame in dots_spinner_data['frames']:
        print(f"\r{frame} Loading...", end="", flush=True)
        time.sleep(dots_spinner_data['interval'] / 1000.0) # Convert ms to seconds

print("\rDone!         ") # Clear the line and print Done

view raw JSON →