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.5.tar.gz (5.8 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.5-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: console_animation-0.2.5.tar.gz
  • Upload date:
  • Size: 5.8 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.5.tar.gz
Algorithm Hash digest
SHA256 ff5816d38f59469977cbc9ea6e30d12f43eb4cfbea48ec2c1590800f35df6ee8
MD5 f651b77b1747fa92cc9abf5f3c0961ce
BLAKE2b-256 80d79ed177588614b1ed3ecf71710c5ac382eb45e32c375e4080dbbb15e073d6

See more details on using hashes here.

Provenance

The following attestation bundles were made for console_animation-0.2.5.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.5-py3-none-any.whl.

File metadata

File hashes

Hashes for console_animation-0.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 42e2a4c211eda269c7bf514838c1e5aea833ea9fe96789245631b5464b9faace
MD5 ee676bf8274507e81eb72a95e5900803
BLAKE2b-256 211509e20c2706a8f906deaac55408628998b93eb04f832ad81f4ef08a8fa0c6

See more details on using hashes here.

Provenance

The following attestation bundles were made for console_animation-0.2.5-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