Click Spinner is a Python library that provides a simple context manager to display a spinning cursor in Click command-line interface (CLI) applications during long-running tasks where a precise progress bar isn't feasible. It aims to improve user experience by indicating activity. The library is currently at version 0.1.10 and is maintained as part of the `click-contrib` organization on GitHub.
pip install click-spinnerVerified import paths — ran on the pinned version, not inferred.
Wrap your long-running code block within the `spinner()` context manager to automatically display and hide a spinning cursor.
There is no built-in mechanism to suppress the spinner when output is redirected. For machine-readable output, consider conditionally disabling the spinner or ensuring such commands do not use it.
No action required, but be aware that upgrading from 0.1.9 to 0.1.10 will not introduce any changes.
Install the package using pip: `pip install click-spinner`
Ensure the `click` dependency is installed: `pip install click` or `pip install click-spinner` to ensure all dependencies are met.
Conditionally enable the spinner only when `sys.stdout` is connected to a TTY (interactive terminal).
```python
import sys
import time
import click_spinner
def long_running_task():
time.sleep(3) # Simulate work
if __name__ == '__main__':
# Check if stdout is a TTY before initializing the spinner
if sys.stdout.isatty():
with click_spinner.spinner():
long_running_task()
else:
# Run without spinner if output is redirected
long_running_task()
```