Skip to main content

An easy to use decorator to show a console spinner during function execution.

Project description

⏳ console-animation

PyPI version Build GitHub issues License

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 animation
  • loaded or end – message shown after successful run
  • error – message shown if exception occurs

🎯 Custom animation and Speed

@animate(spinner="⠋⠙⠚⠞⠖⠦⠴⠲⠳⠓", interval=0.05)
def fancy_task():
    time.sleep(3)
  • spinner: any iterable of characters
  • interval: 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:

  1. Fork the repo
  2. Create a new branch (feature/your-feature)
  3. Commit your changes
  4. 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

console_animation-0.2.6.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

console_animation-0.2.6-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file console_animation-0.2.6.tar.gz.

File metadata

  • Download URL: console_animation-0.2.6.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for console_animation-0.2.6.tar.gz
Algorithm Hash digest
SHA256 9c5d1b23849ac45bdc46330a1d977744aeb3a0a62030584844e81a3780663004
MD5 4fd8316330e3dc700863c4f1d5ac627e
BLAKE2b-256 948a268273baff814e1cc62798997185232b6e32c1b2900c5a2465d2bd0b1452

See more details on using hashes here.

Provenance

The following attestation bundles were made for console_animation-0.2.6.tar.gz:

Publisher: python-package.yml on KoushikEng/console_animation

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file console_animation-0.2.6-py3-none-any.whl.

File metadata

File hashes

Hashes for console_animation-0.2.6-py3-none-any.whl
Algorithm Hash digest
SHA256 473246ec431c03f1d3329373c175bb0f6b243bc1d7939443499a535b1fe68c74
MD5 c9bb9ecfebf7933a06d8af3a60ab9278
BLAKE2b-256 782307b03423c7348cfb73199e3be4f6c3143067fa6ad4fbd1da7b7cf8c3df34

See more details on using hashes here.

Provenance

The following attestation bundles were made for console_animation-0.2.6-py3-none-any.whl:

Publisher: python-package.yml on KoushikEng/console_animation

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page