From 19309d9c94ac82ab5f4f1d143e9761cc41826d99 Mon Sep 17 00:00:00 2001 From: Thijs de Zoete Date: Fri, 28 Mar 2025 10:28:44 +0100 Subject: [PATCH] Update pypi descriptions with more elaborate text --- pypi.md | 127 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ setup.py | 5 ++- 2 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 pypi.md diff --git a/pypi.md b/pypi.md new file mode 100644 index 0000000..af3a96d --- /dev/null +++ b/pypi.md @@ -0,0 +1,127 @@ +# Tinify + +**Tinify** is the official Python client for the [TinyPNG](https://tinypng.com) and [TinyJPG](https://tinyjpg.com) image compression API, enabling developers to optimize PNG, JPEG, and WebP images programmatically. + +[![PyPI version](https://badge.fury.io/py/tinify.svg)](https://badge.fury.io/py/tinify) +[![Build Status](https://github.com/tinify/tinify-python/actions/workflows/ci-cd.yml/badge.svg)](https://github.com/tinify/tinify-python/) +## Features + +- Compress images, reducing file size by 50-80% while preserving visual quality +- Resize and crop images with smart compression +- Convert between PNG, JPEG, and WebP formats +- Preserve metadata (optional) +- Apply visual transformations with the Tinify API +- Supports asynchronous operations +- Comprehensive error handling + +## Installation + +```python +pip install tinify +``` + +## Quick Start + +```python +import tinify + +# Set your API key (get one for free at https://tinypng.com/developers) +tinify.key = "YOUR_API_KEY" + +# Compress an image from a file +tinify.from_file("unoptimized.png").to_file("optimized.png") + +# Compress from URL +tinify.from_url("https://example.com/image.jpg").to_file("optimized.jpg") + +# Compress from buffer +source_data = b"" +tinify.from_buffer(source_data).to_file("optimized.jpg") +``` + +## Advanced Usage + +### Resizing + +```python +# Scale image to fit within 300x200px while preserving aspect ratio +tinify.from_file("original.jpg").resize( + method="scale", + width=300, + height=200 +).to_file("resized.jpg") + +# Fit image to exact 300x200px dimensions +tinify.from_file("original.jpg").resize( + method="fit", + width=300, + height=200 +).to_file("resized.jpg") + +# Cover 300x200px area while preserving aspect ratio +tinify.from_file("original.jpg").resize( + method="cover", + width=300, + height=200 +).to_file("resized.jpg") +``` + +### Format Conversion + +```python +# Convert to WebP format +tinify.from_file("image.png").convert( + type=["image/webp"] +).to_file("image.webp") +``` + +### Compression Count Monitoring + +```python +# Check the number of compressions made this month +compression_count = tinify.compression_count +print(f"You have made {compression_count} compressions this month") +``` + +## Error Handling + +```python +import tinify + +tinify.key = "YOUR_API_KEY" + +try: + tinify.from_file("unoptimized.png").to_file("optimized.png") +except tinify.AccountError as e: + # Verify or update API key + print(f"Account error: {e.message}") +except tinify.ClientError as e: + # Handle client errors (e.g., invalid image) + print(f"Client error: {e.message}") +except tinify.ServerError as e: + # Handle server errors + print(f"Server error: {e.message}") +except tinify.ConnectionError as e: + # Handle network connectivity issues + print(f"Connection error: {e.message}") +except Exception as e: + # Handle general errors + print(f"Error: {str(e)}") +``` + +## Requirements + +- Python 3.6+ +- Requests library + +## Documentation + +For comprehensive documentation, visit [https://tinypng.com/developers/reference/python](https://tinypng.com/developers/reference/python). + +## License + +This software is licensed under the MIT License. See [LICENSE](https://github.com/tinify/tinify-python/blob/master/LICENSE) for details. + +## Support + +For issues and feature requests, please use our [GitHub Issues](https://github.com/tinify/tinify-python/issues) page. diff --git a/setup.py b/setup.py index c4a6cd7..7a20a6a 100644 --- a/setup.py +++ b/setup.py @@ -16,6 +16,9 @@ if sys.version_info.major > 2: tests_require.append("mypy") +with open("pypi.md", "r", encoding="utf-8") as fh: + long_description = fh.read() + setup( name="tinify", version=__version__, @@ -23,7 +26,7 @@ author="Jacob Middag", author_email="info@tinify.com", license="MIT", - long_description="Python client for the Tinify API. Tinify compresses your images intelligently. Read more at https://tinify.com.", + long_description=long_description, long_description_content_type="text/markdown", url="https://tinify.com/developers", packages=["tinify"],