loading2


Nameloading2 JSON
Version 0.0.2 PyPI version JSON
download
home_pageNone
SummaryA simple and elegant Python library for adding loading animations to your functions with a decorator
upload_time2025-08-24 14:46:33
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseMIT
keywords animation decorator loading progress spinner
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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

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

# Or download the loading2.py file directly
```

## Quick Start

```python
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

```python
from loading2 import loading

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

### Custom Messages

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

### Real-world Example

```python
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

```python
@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

```python
@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

```python
@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]

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "loading2",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": "r1cardohj <houjun447@gmail.com>",
    "keywords": "animation, decorator, loading, progress, spinner",
    "author": null,
    "author_email": "r1cardohj <houjun447@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/4f/67/3d32a0aa0d848ec583952966baa43206c49c7fb82201a4d3c9b3e57fbd1d/loading2-0.0.2.tar.gz",
    "platform": null,
    "description": "# Loading2 \ud83d\udd04\n\nA simple and elegant Python library for adding loading animations to your functions with a decorator.\n\n## Features\n\n- \u2728 Easy-to-use decorator pattern\n- \ud83c\udfa8 Customizable loading messages\n- \u26a1 Lightweight with no external dependencies\n- \ud83d\udd04 Smooth spinning animation\n- \ud83d\udce6 Thread-safe implementation\n\n## Installation\n\n```bash\n# Clone the repository\ngit clone https://github.com/r1cardohj/loading2.git\ncd loading2\n\n# Or download the loading2.py file directly\n```\n\n## Quick Start\n\n```python\nfrom loading2 import loading\nimport time\n\n@loading()\ndef long_running_task():\n    time.sleep(3)  # Simulate some work\n    return \"Task completed!\"\n\n# Run the function - you'll see a spinning animation\nresult = long_running_task()\n# you will see this in your command line\n# \\ Loading...\n# when long_running_task function return, you will see\n# OK\n```\n\n## Usage\n\n### Basic Usage\n\n```python\nfrom loading2 import loading\n\n@loading()\ndef my_function():\n    # Your code here\n    pass\n```\n\n### Custom Messages\n\n```python\n@loading(\n    msg=\"Processing data...\",\n    ok=\"\u2705 Data processed successfully!\",\n    err=\"\u274c Processing failed:\"\n)\ndef process_data():\n    # Your processing logic\n    pass\n```\n\n### Real-world Example\n\n```python\nimport requests\nfrom loading2 import loading\n\n@loading(\n    msg=\"Fetching data from API...\",\n    ok=\"\u2705 API request completed!\",\n    err=\"\u274c API request failed:\"\n)\ndef fetch_user_data(user_id):\n    response = requests.get(f\"https://api.example.com/users/{user_id}\")\n    return response.json()\n\n# Usage\nuser_data = fetch_user_data(123)\n```\n\n## Parameters\n\n| Parameter | Type | Default | Description |\n|-----------|------|---------|-------------|\n| `msg` | `str` | `\"Loading...\"` | Message displayed during loading |\n| `ok` | `str` | `\"OK\"` | Message displayed on success |\n| `err` | `str` | `\"Failed\"` | Message displayed on error |\n\n## How It Works\n\nThe 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.\n\n## Requirements\n\n- Python 3.10+\n- No external dependencies\n\n## Examples\n\n### CPU-intensive Task\n\n```python\n@loading(msg=\"Calculating...\", ok=\"\ud83c\udf89 Calculation done!\")\ndef cpu_bound_task():\n    return sum(i * i for i in range(100_000_000))\n\nresult = cpu_bound_task()\n```\n\n### File Operations\n\n```python\n@loading(msg=\"Reading large file...\", ok=\"\ud83d\udcc1 File loaded!\")\ndef read_large_file(filename):\n    with open(filename, 'r') as f:\n        return f.read()\n\ncontent = read_large_file('big_data.txt')\n```\n\n### Database Operations\n\n```python\n@loading(msg=\"Querying database...\", ok=\"\ud83d\uddc4\ufe0f Query completed!\")\ndef fetch_records():\n    # Database query logic here\n    pass\n```\n\n## Inspiration\n\nThe spinning animation implementation is inspired by the examples in \"Fluent Python\" by Luciano Ramalho.\n\n## Support\n\nIf you find this library helpful, please consider giving it a \u2b50 on GitHub!\n\n---\n\nMade with \u2764\ufe0f by [r1cardohj]\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A simple and elegant Python library for adding loading animations to your functions with a decorator",
    "version": "0.0.2",
    "project_urls": {
        "Documentation": "https://github.com/r1cardohj/loading2#readme",
        "Homepage": "https://github.com/r1cardohj/loading2",
        "Issues": "https://github.com/r1cardohj/loading2/issues",
        "Repository": "https://github.com/r1cardohj/loading2"
    },
    "split_keywords": [
        "animation",
        " decorator",
        " loading",
        " progress",
        " spinner"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "5ef068008c277fa9262b68c0d9686f5c1b0dae03b70ffab3458f065da6138788",
                "md5": "e3135154dff40faea37c602dca76c331",
                "sha256": "5a64235ce8d9fab1979597f6a6dc7b633f3857e7f95e5de65e5a1f3693eef1ff"
            },
            "downloads": -1,
            "filename": "loading2-0.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e3135154dff40faea37c602dca76c331",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 3203,
            "upload_time": "2025-08-24T14:46:32",
            "upload_time_iso_8601": "2025-08-24T14:46:32.360060Z",
            "url": "https://files.pythonhosted.org/packages/5e/f0/68008c277fa9262b68c0d9686f5c1b0dae03b70ffab3458f065da6138788/loading2-0.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "4f673d32a0aa0d848ec583952966baa43206c49c7fb82201a4d3c9b3e57fbd1d",
                "md5": "47dc962c3c207b1cbc6afcf99c366615",
                "sha256": "febde26a7ba21d3215884764bd9d9a3a7fc876a7543ba6b8497181562f8fe012"
            },
            "downloads": -1,
            "filename": "loading2-0.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "47dc962c3c207b1cbc6afcf99c366615",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 19109,
            "upload_time": "2025-08-24T14:46:33",
            "upload_time_iso_8601": "2025-08-24T14:46:33.815489Z",
            "url": "https://files.pythonhosted.org/packages/4f/67/3d32a0aa0d848ec583952966baa43206c49c7fb82201a4d3c9b3e57fbd1d/loading2-0.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-24 14:46:33",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "r1cardohj",
    "github_project": "loading2#readme",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "loading2"
}
        
Elapsed time: 1.19172s