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

Uploaded Python 3

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

Hashes for console_animation-0.2.4.tar.gz
Algorithm Hash digest
SHA256 4d2267b43254b3526c7114c751d52bf7fc6b87de0f58f8e50efadbbb0b86f164
MD5 23a027990329d1bdc1858ae664807d20
BLAKE2b-256 f8a3de7c18f90d7296f6bade1304d61a29a5c266802c6b9a93caab1c4e004615

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for console_animation-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 50ab6054c1c9eff0ac92bb682bfa56bf81c77ca11f34b7c7d63e7b8132ecb7cf
MD5 c8353ee31ceb894d5ffd544efcff7c71
BLAKE2b-256 d0e45a2666d2f615189d9de072e9b5b85736eb1f8cbc90f2025a85aa257f81bf

See more details on using hashes here.

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

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