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

Uploaded Python 3

File details

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

File metadata

  • Download URL: console_animation-0.2.7.tar.gz
  • Upload date:
  • Size: 7.2 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.7.tar.gz
Algorithm Hash digest
SHA256 bd4c4a14f27068ce169ecf67d98b6aedcbe14c371b1e6d5ea05e0a18ac36888e
MD5 ac2ae70b8c5d8914013e3f75f00da3f5
BLAKE2b-256 c6b64bcbf09fdc92ca143e3295c113e9f726a0682fb91400d8635d5c2dc6676d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for console_animation-0.2.7-py3-none-any.whl
Algorithm Hash digest
SHA256 e693e1e363a0e6ab99e6a47ee7f4a204383c62cbdc48a527f515e4f37f4f01fc
MD5 1c288d101f6c8c6eb6c522cf66383e11
BLAKE2b-256 dc17cfb183341c6713a8e2655d71210d57a21e6471e8ae69a842a24b3efa98ca

See more details on using hashes here.

Provenance

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