Skip to content

Commit cf8781b

Browse files
committed
Docs: Merge pypi.md with README.md
1 parent 2d54270 commit cf8781b

File tree

3 files changed

+121
-149
lines changed

3 files changed

+121
-149
lines changed

README.md

Lines changed: 119 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,133 @@
77

88
# Tinify API client for Python
99

10-
Python client for the Tinify API, used for [TinyPNG](https://tinypng.com) and [TinyJPG](https://tinyjpg.com). Tinify compresses your images intelligently. Read more at [http://tinify.com](http://tinify.com).
10+
**Tinify** is the official Python client for the [TinyPNG](https://tinypng.com) and [TinyJPG](https://tinyjpg.com/) image compression API, enabling developers to intelligently compress, resize, convert and optimize PNG, APNG, JPEG, WebP and AVIF images programmatically. Read more at [https://tinify.com](https://tinify.com/developers).
1111

12-
## Documentation
1312

14-
[Go to the documentation for the Python client](https://tinypng.com/developers/reference/python).
13+
[Go to the full documentation for the Python client](https://tinypng.com/developers/reference/python).
14+
15+
## Features
16+
17+
- Compress and optimize images, reducing file size by 50-80% while preserving visual quality
18+
- Resize and crop images with smart compression
19+
- Convert between PNG, JPEG, WebP and AVIF formats
20+
- Preserve metadata (optional)
21+
- Upload to storage providers like Amazon S3, Google cloud storage.
22+
- Apply visual transformations with the Tinify API
23+
- Comprehensive error handling
24+
25+
26+
27+
## Requirements
28+
29+
- Python 2.7+
30+
- Requests library
1531

1632
## Installation
1733

18-
Install the API client:
34+
Install the API client with pip:
1935

20-
```
36+
```bash
2137
pip install tinify
2238
```
2339

24-
## Usage
40+
## Quick start
41+
2542

2643
```python
2744
import tinify
28-
tinify.key = 'YOUR_API_KEY'
2945

30-
tinify.from_file('unoptimized.png').to_file('optimized.png')
46+
# Set your API key (get one for free at https://tinypng.com/developers)
47+
tinify.key = "YOUR_API_KEY"
48+
49+
# Compress an image from a file
50+
tinify.from_file("unoptimized.png").to_file("optimized.png")
51+
52+
# Compress from URL
53+
tinify.from_url("https://example.com/image.jpg").to_file("optimized.jpg")
54+
55+
# Compress from buffer
56+
source_data = b"<image data>"
57+
tinify.from_buffer(source_data).to_file("optimized.jpg")
58+
```
59+
60+
## Advanced Usage
61+
62+
### Resizing
63+
64+
```python
65+
# Scale image to fit within 300x200px while preserving aspect ratio
66+
tinify.from_file("original.jpg").resize(
67+
method="scale",
68+
width=300,
69+
height=200
70+
).to_file("resized.jpg")
71+
72+
# Fit image to exact 300x200px dimensions
73+
tinify.from_file("original.jpg").resize(
74+
method="fit",
75+
width=300,
76+
height=200
77+
).to_file("resized.jpg")
78+
79+
# Cover 300x200px area while preserving aspect ratio
80+
tinify.from_file("original.jpg").resize(
81+
method="cover",
82+
width=300,
83+
height=200
84+
).to_file("resized.jpg")
85+
```
86+
87+
### Format Conversion
88+
89+
```python
90+
# Convert to WebP format
91+
tinify.from_file("image.png").convert(
92+
type=["image/webp"]
93+
).to_file("image.webp")
94+
```
95+
96+
```python
97+
# Convert to smallest format
98+
converted = tinify.from_file("image.png").convert(
99+
type=["image/webp", "image/webp"]
100+
)
101+
extension = converted.result().extension
102+
converted.to_file("image." + extension)
103+
```
104+
105+
### Compression Count Monitoring
106+
107+
```python
108+
# Check the number of compressions made this month
109+
compression_count = tinify.compression_count
110+
print(f"You have made {compression_count} compressions this month")
111+
```
112+
113+
## Error Handling
114+
115+
```python
116+
import tinify
117+
118+
tinify.key = "YOUR_API_KEY"
119+
120+
try:
121+
tinify.from_file("unoptimized.png").to_file("optimized.png")
122+
except tinify.AccountError as e:
123+
# Verify or update API key
124+
print(f"Account error: {e.message}")
125+
except tinify.ClientError as e:
126+
# Handle client errors (e.g., invalid image)
127+
print(f"Client error: {e.message}")
128+
except tinify.ServerError as e:
129+
# Handle server errors
130+
print(f"Server error: {e.message}")
131+
except tinify.ConnectionError as e:
132+
# Handle network connectivity issues
133+
print(f"Connection error: {e.message}")
134+
except Exception as e:
135+
# Handle general errors
136+
print(f"Error: {str(e)}")
31137
```
32138

33139
## Running tests
@@ -54,4 +160,8 @@ TINIFY_KEY=$YOUR_API_KEY py.test test/integration.py
54160

55161
## License
56162

57-
This software is licensed under the MIT License. [View the license](LICENSE).
163+
This software is licensed under the MIT License. See [LICENSE](https://github.com/tinify/tinify-python/blob/master/LICENSE) for details.
164+
165+
## Support
166+
167+
For issues and feature requests, please use our [GitHub Issues](https://github.com/tinify/tinify-python/issues) page or contact us at [support@tinify.com](mailto:support@tinify.com)

pypi.md

Lines changed: 0 additions & 137 deletions
This file was deleted.

setup.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@
1717
if sys.version_info.major > 2:
1818
tests_require.append("mypy")
1919

20-
with io.open("pypi.md", encoding="utf-8") as f:
20+
with io.open("README.md", encoding="utf-8") as f:
2121
long_description = f.read()
2222

23-
2423
setup(
2524
name="tinify",
2625
version=__version__,
@@ -33,7 +32,7 @@
3332
url="https://tinify.com/developers",
3433
packages=["tinify"],
3534
package_data={
36-
"": ["LICENSE", "README.md", "pypi.md"],
35+
"": ["LICENSE", "README.md"],
3736
"tinify": ["data/cacert.pem", "py.typed"],
3837
},
3938
install_requires=install_require,

0 commit comments

Comments
 (0)