Skip to main content

aienlarge-py

An Asynchronous Python API Wrapper for AI Enlarger

License: MIT Python Versions

aienlarge-py is an unofficial Python library that provides an asynchronous interface to the AI Enlarger image enhancement service. It allows you to programmatically upload images, enhance or enlarge them using AI-powered processes, monitor processing status, and download enhanced results. It leverages httpx for efficient non-blocking I/O via asyncio.


🚀 Features

  • Asynchronous API: Built with httpx and asyncio for efficient concurrency.
  • Image Upload: Send images for processing with specified enhancement types and scaling.
  • Status Monitoring: Check the status of your image processing tasks.
  • Image Downloading: Retrieve processed images when ready.
  • Robust Error Handling: Custom exceptions for granular error management.
  • Automatic Configuration: Generates and persists a username locally for API usage.
  • Retry Logic: Auto-retries failed requests with exponential backoff.
  • Integrated Logging: Uses Python’s logging module for traceability.

⚠️ Disclaimer

This library is unofficial and not affiliated with or endorsed by AI Enlarger or its developers. Use at your own discretion and comply with any terms of service or usage limits set by AI Enlarger.


📦 Installation

Install via GitHub:

pip install git+https://github.com/SSL-ACTX/aienlarger-py.git#egg=aienlarge-py

Or install from PyPI:

pip install aienlarge-py

🧪 Usage Example

import asyncio
import aienlarge
import os

async def main():
    api = aienlarge.ImgLargerAPI()

    image_path = "path/to/your/image.jpg"
    output_dir = "output_images"

    os.makedirs(output_dir, exist_ok=True)

    try:
        # Upload image for 2x enhancement using Default Image Upscaler
        process_code = await api.upload_image(image_path, process_type=0, scale_radio=2)

        if process_code:
            print(f"Upload successful. Process code: {process_code}")

            while True:
                status, download_urls = await api.check_status(process_code)
                print(f"Status: {status}")

                if status == "done" and download_urls:
                    print("Processing complete. Downloading images...")
                    for i, url in enumerate(download_urls):
                        await api.download_image(url, output_dir)
                        print(f"Downloaded image {i+1}/{len(download_urls)}")
                    break
                elif status == "error":
                    print("An error occurred during processing.")
                    break
                else:
                    await asyncio.sleep(5)  # Retry after 5 seconds

    except aienlarge.ImgLargerError as e:
        print(f"API Error: {e}")
    except FileNotFoundError:
        print(f"File not found: {image_path}")
    except ValueError as e:
        print(f"Validation Error: {e}")

if __name__ == "__main__":
    asyncio.run(main())

✅ Note: Replace "path/to/your/image.jpg" with your actual file path.


🧰 API Reference

ImgLargerAPI Class

__init__(base_url="https://photoai.imglarger.com/api/PhoAi", username=None)

  • base_url: Base URL for the API (default: official endpoint).
  • username: Optional. Will be loaded from config or generated if not provided.

async upload_image(image_path: str, process_type: int, scale_radio: Optional[int] = None) -> Optional[str]

Uploads an image to be processed.

  • process_type:
    • 0: Default Image Upscaler (supports scale_radio)
    • 1: Sharpen
    • 2: Enhancer Mode (Photo color and contrast)
    • 3: Retouch Mode (Deblur)
    • 13: Anime Images Upscaler (supports scale_radio)
  • scale_radio: Optional scale (only for types 0 and 13). Valid values: 2, 4, 8.

⚠️ Note: scale_radio with a value of 8 is usually for PRO users only, but using it directly in the API may bypass that.

async check_status(process_code: str) -> Tuple[Optional[str], Optional[List[str]]]

Returns the current processing status and download URLs (if available).

  • status: "pending", "processing", "done", "error", or None
  • download_urls: List of URLs when status is "done"

async download_image(download_url: str, output_path_dir: str)

Downloads a processed image to the specified directory.


❗ Error Handling

Exception classes include:

  • ImgLargerError (Base)
  • ImgLargerUploadError
  • ImgLargerStatusError
  • ImgLargerDownloadError
  • ImgLargerInvalidProcessTypeError
  • ImgLargerInvalidScaleRadioError
  • ImgLargerAPIResponseError
  • ImgLargerConfigFileError

These help you implement granular and predictable error handling.


⚙️ Configuration

  • The library stores a username in .aienlarge_config.json (created in your working directory).
  • If no username is provided, one is generated and saved automatically.

📚 Dependencies

  • httpx: For async HTTP operations.

📄 License

Licensed under the MIT License. See the LICENSE file for full details.


🤝 Contributing

Contributions are welcome! Feel free to submit issues or pull requests.


👤 Author

SSL-ACTX 📧 seuriin@gmail.com 🔗 https://github.com/SSL-ACTX

Metadata

Release files for aienlarge-py 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aienlarge-py 0.1.2
File Size Uploaded
aienlarge_py-0.1.2.tar.gz 10.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for aienlarge-py 0.1.2
File Interpreter ABI Platform
aienlarge_py-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 20.0 kB

Release files / aienlarge_py-0.1.2.tar.gz

Download URL aienlarge_py-0.1.2.tar.gz
Size 10.7 kB
Tags Source
SHA-256 checksum
How to use checksums
a7fe67f19c2d491fd9488b1238eb005123fbc6be0b6899a317fa1287fa09af36
BLAKE2b-256 checksum
How to use checksums
50fa9e70564c211515a98fecc9ea635e8a4953729b7ef06f7380a6a0b292f95b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.3

Release files / aienlarge_py-0.1.2-py3-none-any.whl

Download URL aienlarge_py-0.1.2-py3-none-any.whl
Size 9.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
85e19df79427e071142f4f8f6a2ed5eb032c7843ce65cf1b780bfd6d11f60564
BLAKE2b-256 checksum
How to use checksums
e88db1f1727ecfe61ddca33dee57a7c8080a081cad0f54de5833ec99104437c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page