An Asynchronous Python API Wrapper for AI Enlarger
aienlarge-py
is an unofficial, reverse-engineered Python library that provides an asynchronous interface to the AI Enlarger image enhancement service.
It enables programmatic access to AI Enlarger's functionality β including image upload, AI-powered enhancement or enlargement, processing status checks, and result retrieval β all through an asynchronous API built with httpx
and asyncio
for efficient non-blocking I/O.
This library was developed by analyzing the behavior of the official mobile app client and is not based on any proprietary or internal source code.
- Asynchronous API: Built with
httpx
andasyncio
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.
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. All trademarks and copyrights related to AI Enlarger are the property of their respective owners.
This project is intended for educational and interoperability purposes only.
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
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.
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 (supportsscale_radio
)1
: Sharpen2
: Enhancer Mode (Photo color and contrast)3
: Retouch Mode (Deblur)13
: Anime Images Upscaler (supportsscale_radio
)
scale_radio
: Optional scale (only for types0
and13
). 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.
Returns the current processing status and download URLs (if available).
status
:"pending"
,"processing"
,"done"
,"error"
, orNone
download_urls
: List of URLs when status is"done"
Downloads a processed image to the specified directory.
Exception classes include:
ImgLargerError
(Base)ImgLargerUploadError
ImgLargerStatusError
ImgLargerDownloadError
ImgLargerInvalidProcessTypeError
ImgLargerInvalidScaleRadioError
ImgLargerAPIResponseError
ImgLargerConfigFileError
These help you implement granular and predictable error handling.
- 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.
httpx
: For async HTTP operations.
Licensed under the MIT License. See the LICENSE file for full details.
Contributions are welcome! Feel free to submit issues or pull requests.
SSL-ACTX π§ [email protected] π https://github.com/SSL-ACTX