Skip to main content

A simple and elegant Python library for adding loading animations to your functions with a decorator

Project description

Loading2 🔄

A simple and elegant Python library for adding loading animations to your functions with a decorator.

Features

  • ✨ Easy-to-use decorator pattern
  • 🎨 Customizable loading messages
  • ⚡ Lightweight with no external dependencies
  • 🔄 Smooth spinning animation
  • 📦 Thread-safe implementation

Installation

# Clone the repository
git clone https://github.com/r1cardohj/loading2.git
cd loading2

# Or download the loading2.py file directly

Quick Start

from loading2 import loading
import time

@loading()
def long_running_task():
    time.sleep(3)  # Simulate some work
    return "Task completed!"

# Run the function - you'll see a spinning animation
result = long_running_task()
# you will see this in your command line
# \ Loading...
# when long_running_task function return, you will see
# OK

Usage

Basic Usage

from loading2 import loading

@loading()
def my_function():
    # Your code here
    pass

Custom Messages

@loading(
    msg="Processing data...",
    ok="✅ Data processed successfully!",
    err="❌ Processing failed:"
)
def process_data():
    # Your processing logic
    pass

Real-world Example

import requests
from loading2 import loading

@loading(
    msg="Fetching data from API...",
    ok="✅ API request completed!",
    err="❌ API request failed:"
)
def fetch_user_data(user_id):
    response = requests.get(f"https://api.example.com/users/{user_id}")
    return response.json()

# Usage
user_data = fetch_user_data(123)

Parameters

Parameter Type Default Description
msg str "Loading..." Message displayed during loading
ok str "OK" Message displayed on success
err str "Failed" Message displayed on error

How It Works

The library uses Python's threading module to run a spinning animation in a separate thread while your function executes. The animation automatically stops when your function completes or raises an exception.

Requirements

  • Python 3.10+
  • No external dependencies

Examples

CPU-intensive Task

@loading(msg="Calculating...", ok="🎉 Calculation done!")
def cpu_bound_task():
    return sum(i * i for i in range(100_000_000))

result = cpu_bound_task()

File Operations

@loading(msg="Reading large file...", ok="📁 File loaded!")
def read_large_file(filename):
    with open(filename, 'r') as f:
        return f.read()

content = read_large_file('big_data.txt')

Database Operations

@loading(msg="Querying database...", ok="🗄️ Query completed!")
def fetch_records():
    # Database query logic here
    pass

Inspiration

The spinning animation implementation is inspired by the examples in "Fluent Python" by Luciano Ramalho.

Support

If you find this library helpful, please consider giving it a ⭐ on GitHub!


Made with ❤️ by [r1cardohj]

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

loading2-0.0.1.tar.gz (19.1 kB view details)

Uploaded Source

Built Distribution

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

loading2-0.0.1-py3-none-any.whl (3.2 kB view details)

Uploaded Python 3

File details

Details for the file loading2-0.0.1.tar.gz.

File metadata

  • Download URL: loading2-0.0.1.tar.gz
  • Upload date:
  • Size: 19.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.1

File hashes

Hashes for loading2-0.0.1.tar.gz
Algorithm Hash digest
SHA256 c9efcc32e0826c5b393ba39da1f7de864e11d732e19d2d027dfa32fde8b59806
MD5 8059402d859394efb7fef415b3d12005
BLAKE2b-256 17ed5aff66932481e80332f35ead592657655334f303e86fdd17146a8374ce7d

See more details on using hashes here.

File details

Details for the file loading2-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: loading2-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 3.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.1

File hashes

Hashes for loading2-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 97e2ff8f6cad626a26cf14a5629563d63cadbfa088001e6ab5a58eff92008af8
MD5 670ce4376f85fa8c8dbce2bb5f6f41b6
BLAKE2b-256 196b861ab3d5440a80e1c3b511e936f7265a34c273a138a3df70b172c07b557a

See more details on using hashes here.

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