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.2.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.2-py3-none-any.whl (3.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: loading2-0.0.2.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.2.tar.gz
Algorithm Hash digest
SHA256 febde26a7ba21d3215884764bd9d9a3a7fc876a7543ba6b8497181562f8fe012
MD5 47dc962c3c207b1cbc6afcf99c366615
BLAKE2b-256 4f673d32a0aa0d848ec583952966baa43206c49c7fb82201a4d3c9b3e57fbd1d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: loading2-0.0.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5a64235ce8d9fab1979597f6a6dc7b633f3857e7f95e5de65e5a1f3693eef1ff
MD5 e3135154dff40faea37c602dca76c331
BLAKE2b-256 5ef068008c277fa9262b68c0d9686f5c1b0dae03b70ffab3458f065da6138788

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