An easy to use decorator to show a console spinner during function execution.
Project description
⏳ console-animation
A lightweight and flexible Python decorator to show a console animation (loading animation) while a function is running. Useful for long-running CLI tasks, data processing, I/O, or just making your tools feel more alive.
🔧 Features
- Add a console animation with a single line
- Optional start, end, and error messages
- Customizable animation style and speed
- Gracefully handles exceptions
- Works with or without decorator arguments
- Clean terminal output (hides cursor during spin)
📦 Installation
# pip install
pip install console_animation
# or
# Clone the repo
git clone https://github.com/KoushikEng/console_animation.git
cd console_animation
# Install locally
pip install .
You can also install it in editable mode during development:
pip install -e .
🚀 Usage
✅ Basic animation (no args)
from console_animation import animate
@animate
def task():
import time
time.sleep(3)
This will show a rotating animation while task() runs.
⚙️ With Custom Messages
@animate(start="Processing...", loaded="✅ Task complete!", error="❌ Something broke.")
def do_work():
time.sleep(5)
start– message shown before animationloadedorend– message shown after successful runerror– message shown if exception occurs
🎯 Custom animation and Speed
@animate(spinner="⠋⠙⠚⠞⠖⠦⠴⠲⠳⠓", interval=0.05)
def fancy_task():
time.sleep(3)
spinner: any iterable of charactersinterval: time (in seconds) between frames
❗ Error Handling
If error is not provided:
- The animation will stop
- Cursor will be restored
- The original exception is raised as-is
If error is set:
- It will be printed
- Full traceback is also printed for debugging
🧪 Example Script
from console_animation import animate
import time
@animate(start="Crunching numbers...", loaded="✅ Done!", error="🔥 Failed.")
def math_task():
time.sleep(3)
@animate
def quick_task():
time.sleep(1)
@animate(start="Breaking...", error="Oops.")
def will_fail():
raise RuntimeError("Intentional failure.")
math_task()
quick_task()
will_fail()
🤝 Contributing
Contributions are welcome and appreciated!
If you want to:
- Add features (like async support, presets, color, etc.)
- Improve performance or compatibility
- Fix bugs
- Write tests or improve docs
Please feel free to:
- Fork the repo
- Create a new branch (
feature/your-feature) - Commit your changes
- Push and open a PR
Issues and suggestions are also welcome in the Issues tab.
📄 License
This project is licensed under the MIT License — see the LICENSE file for details.
🙌 Credits
Built with frustration from boring terminal waits and love for clean CLI UX.
🛠️ To Do (Open for PRs)
- Async function support (
async def) - Color support (via
colorama) - Predefined animation styles
- Timeout decorator option
- PyPI upload
Made by Koushik 🔥
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file console_animation-0.2.4.tar.gz.
File metadata
- Download URL: console_animation-0.2.4.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4d2267b43254b3526c7114c751d52bf7fc6b87de0f58f8e50efadbbb0b86f164
|
|
| MD5 |
23a027990329d1bdc1858ae664807d20
|
|
| BLAKE2b-256 |
f8a3de7c18f90d7296f6bade1304d61a29a5c266802c6b9a93caab1c4e004615
|
Provenance
The following attestation bundles were made for console_animation-0.2.4.tar.gz:
Publisher:
python-package.yml on KoushikEng/console_animation
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
console_animation-0.2.4.tar.gz -
Subject digest:
4d2267b43254b3526c7114c751d52bf7fc6b87de0f58f8e50efadbbb0b86f164 - Sigstore transparency entry: 990589087
- Sigstore integration time:
-
Permalink:
KoushikEng/console_animation@fd210aa1516e27c90d2abb36208fc69e8236cae0 -
Branch / Tag:
refs/tags/v0.2.4 - Owner: https://github.com/KoushikEng
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-package.yml@fd210aa1516e27c90d2abb36208fc69e8236cae0 -
Trigger Event:
push
-
Statement type:
File details
Details for the file console_animation-0.2.4-py3-none-any.whl.
File metadata
- Download URL: console_animation-0.2.4-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
50ab6054c1c9eff0ac92bb682bfa56bf81c77ca11f34b7c7d63e7b8132ecb7cf
|
|
| MD5 |
c8353ee31ceb894d5ffd544efcff7c71
|
|
| BLAKE2b-256 |
d0e45a2666d2f615189d9de072e9b5b85736eb1f8cbc90f2025a85aa257f81bf
|
Provenance
The following attestation bundles were made for console_animation-0.2.4-py3-none-any.whl:
Publisher:
python-package.yml on KoushikEng/console_animation
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
console_animation-0.2.4-py3-none-any.whl -
Subject digest:
50ab6054c1c9eff0ac92bb682bfa56bf81c77ca11f34b7c7d63e7b8132ecb7cf - Sigstore transparency entry: 990589089
- Sigstore integration time:
-
Permalink:
KoushikEng/console_animation@fd210aa1516e27c90d2abb36208fc69e8236cae0 -
Branch / Tag:
refs/tags/v0.2.4 - Owner: https://github.com/KoushikEng
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-package.yml@fd210aa1516e27c90d2abb36208fc69e8236cae0 -
Trigger Event:
push
-
Statement type: