TinyComp
TinyComp is a Python package that helps you compress images using the TinyPNG API. It provides both a command-line interface and a Python API for easy integration into your projects.
Features
- Automatic API key management and rotation
- Automatic API key acquisition when needed
- Batch image compression
- Batch image scaling (no API needed)
- Support for multiple image formats (PNG, JPG, JPEG, GIF, BMP, WebP)
- Progress bar for tracking compression/scaling status
- Multi-threaded processing for better performance
- Automatic handling of API usage limits
- Automatic API key update through web automation
- Fixed-size normalization with crop or pad mode
Installation
pip install tinycomp-amadeus
Usage
Command Line Interface
Compressing Images
# Basic compression
tinycomp compress --source ./images --target ./compressed
# With custom API key
tinycomp compress --source ./images --target ./compressed --api-key YOUR_API_KEY
# Set number of threads
tinycomp compress --source ./images --target ./compressed --threads 4
# Enable automatic API key updates when needed
tinycomp compress --source ./images --target ./compressed --auto-update-key
Managing API Keys
# Update API key (checks current key first)
tinycomp update-key
# Force update API key even if current one is valid
tinycomp update-key --force
Scaling Images
# Scale all images in a directory (proportional, no API needed)
tinycomp scale --source ./images --target ./scaled -sc 0.5
# Scale by width (keeps aspect ratio)
tinycomp scale --source ./images --target ./scaled -w 800
# Scale by height (keeps aspect ratio)
tinycomp scale --source ./images --target ./scaled -he 600
# Normalize all images to a fixed size (1024x1024, center-crop to fit)
tinycomp scale --source ./images --target ./scaled --size 1024x1024
# Normalize with white padding (image fits inside, empty space filled white)
tinycomp scale --source ./images --target ./scaled --size 512x512 --fit pad
# Specify resampling algorithm (default: lanczos)
tinycomp scale --source ./images --target ./scaled -w 800 --method bicubic
# Preserve original bit depth (8-bit P→palette, L→grayscale; default behavior)
tinycomp scale --source ./images --target ./scaled --size 1024x1024
# Disable bit-depth preservation (force RGB 24-bit output)
tinycomp scale --source ./images --target ./scaled --size 1024x1024 --keep-depth false
Python API
from tinycomp import TinyCompressor
# Initialize compressor
compressor = TinyCompressor(api_key="YOUR_API_KEY") # API key is optional
# Enable automatic API key updates
compressor = TinyCompressor(auto_update_key=True)
# Compress a single image
compressor.compress_image("input.png", "output.png")
# Compress multiple images
compressor.compress_directory("./images", "./compressed")
# Update API key programmatically
from tinycomp.api_manager import APIKeyManager
api_manager = APIKeyManager()
new_key = api_manager.get_new_api_key()
Image Scaling
from tinycomp import TinyScaler
scaler = TinyScaler()
# Proportional scaling
scaler.scale_image("input.png", "output.png", scale=0.5)
scaler.scale_image("input.png", "output.png", width=800)
scaler.scale_image("input.png", "output.png", height=600)
# Fixed size normalization
scaler.scale_image("input.png", "output.png", size=(1024, 1024), fit="crop")
scaler.scale_image("input.png", "output.png", size=(512, 512), fit="pad")
# Specify resampling algorithm (choices: nearest, bilinear, bicubic, lanczos, box, hamming; default: lanczos)
scaler.scale_image("input.png", "output.png", width=800, method="bicubic")
# Preserve original bit depth (P→8-bit palette, L→8-bit grayscale; default: True)
scaler.scale_image("input.png", "output.png", size=(1024, 1024))
# Disable bit-depth preservation (force RGB 24-bit)
scaler.scale_image("input.png", "output.png", size=(1024, 1024), keep_depth=False)
# Batch scale with method set globally at init
scaler = TinyScaler(method="lanczos")
scaler.scale_directory("./images", "./scaled", size=(1024, 1024))
Configuration
You can configure TinyComp using environment variables:
TINYCOMP_API_KEY: Your TinyPNG API keyTINYCOMP_MAX_THREADS: Maximum number of compression threads (default: 4)
Requirements
- Python 3.6 or higher
- Chrome/Chromium browser (for automatic API key updates)
- ChromeDriver matching your Chrome version
API Key Management
TinyComp includes an automatic API key management system that:
- Automatically rotates between multiple API keys
- Monitors remaining API usage
- Can automatically obtain new API keys when needed
- Saves API keys for future use
The package offers two modes for handling API key depletion:
- Default mode: Stops compression and notifies when the API key runs out
- Auto-update mode: Automatically obtains new API keys when needed (use
--auto-update-keyflag)
The automatic key update feature requires:
- Chrome/Chromium browser installed
- ChromeDriver in your system PATH or in the working directory
- Internet connection for accessing TinyPNG website
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Metadata
Release files for tinycomp-amadeus 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tinycomp_amadeus-0.2.0.tar.gz | 24.5 kB | Without provenance | Details for tinycomp_amadeus-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tinycomp_amadeus-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for tinycomp_amadeus-0.2.0-py3-none-any.whl |
Total release size: 50.4 kB
Release files / tinycomp_amadeus-0.2.0.tar.gz
| Download URL | tinycomp_amadeus-0.2.0.tar.gz |
|---|---|
| Size | 24.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
95b04d6ee37b468c74b83270dbf524bc5e4c708b5593913f9ddcb7bee313b37e
|
|
BLAKE2b-256 checksum How to use checksums |
3c9718e454eab06bf36bcbceb4f011a00e58aa6e1c09a0dad4b244539ce8c1c4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.7
|
Release files / tinycomp_amadeus-0.2.0-py3-none-any.whl
| Download URL | tinycomp_amadeus-0.2.0-py3-none-any.whl |
|---|---|
| Size | 25.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0d0c284bb805a8399bd6355d7fe3b6cc9a6eecf64cbd1e9046a4c739eddebd2e
|
|
BLAKE2b-256 checksum How to use checksums |
bd3b47b4bdc06b39ed84188c60e02682e8fe32fc22d26a546a2e738e3f053286
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.7
|
Security for tinycomp-amadeus 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.