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]
Metadata
Release files for loading2 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| loading2-0.0.2.tar.gz | 19.1 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| loading2-0.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 22.3 kB
Release files / loading2-0.0.2.tar.gz
| Download URL | loading2-0.0.2.tar.gz |
|---|---|
| Size | 19.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
febde26a7ba21d3215884764bd9d9a3a7fc876a7543ba6b8497181562f8fe012
|
|
BLAKE2b-256 checksum How to use checksums |
4f673d32a0aa0d848ec583952966baa43206c49c7fb82201a4d3c9b3e57fbd1d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.1
|
Release files / loading2-0.0.2-py3-none-any.whl
| Download URL | loading2-0.0.2-py3-none-any.whl |
|---|---|
| Size | 3.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5a64235ce8d9fab1979597f6a6dc7b633f3857e7f95e5de65e5a1f3693eef1ff
|
|
BLAKE2b-256 checksum How to use checksums |
5ef068008c277fa9262b68c0d9686f5c1b0dae03b70ffab3458f065da6138788
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.1
|
Security for loading2 0.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.