Deflato — compress images & documents, generate and edit AI images
Project description
Deflato Python SDK
Compress images, documents, and generate AI images with one line of code. Powered by deflato.com.
Install
pip install deflato
Quick Start
from deflato import Deflato
client = Deflato("your-api-key")
# Compress an image
result = client.compress("photo.jpg", format="WEBP", quality=75)
print(f"Saved {result.savings_percent}% -> {result.output_path}")
# Compress a PDF document
doc = client.compress_document("report.pdf", quality=70)
print(f"PDF: {doc.savings_percent}% smaller")
# Generate an AI image
img = client.generate("A sunset over mountains", model="fast")
print(f"Generated -> {img.output_path}")
# Edit an image with AI
edited = client.edit("Add sunglasses to the person", input_path="portrait.jpg")
print(f"Edited -> {edited.output_path}")
# Get alt-text for an image
desc = client.describe(input_path="photo.jpg")
print(desc.description)
API
Deflato(api_key, base_url="https://deflato.com")
client.compress(input_path, output=None, quality=80, max_dimension=0, format="JPEG", strip_exif=True)
Compress an image file.
Returns CompressResult:
success: boolinput_size: int(bytes)output_size: int(bytes)savings_percent: intoutput_path: stroutput_format: str
client.info(input_path, quality=80, format="JPEG")
Get compression info without saving the file. Returns CompressResult.
client.compress_batch(input_paths, output_dir=None, quality=80, format="JPEG")
Compress multiple files. Returns list of CompressResult.
client.compress_document(input_path, output=None, quality=75, max_dimension=1920)
Compress images inside PDF, DOCX, PPTX, or XLSX documents. Returns CompressResult.
client.convert_format(input_path, output_format, output=None)
Convert an image to a different format (JPEG, PNG, WEBP, AVIF). Returns CompressResult.
client.generate(prompt, output=None, model="photo", aspect_ratio="1:1", style="any", resolution="1K", format="png")
Generate an image from a text prompt using AI.
| Param | Default | Description |
|---|---|---|
| model | photo | fast, photo, design, or icon |
| aspect_ratio | 1:1 | Aspect ratio |
| style | any | Style for design/icon models |
| resolution | 1K | 1K, 2K, or 4K (photo only) |
| format | png | png or jpg |
Returns GenerateResult: success, output_path, output_size, model, prompt
client.edit(prompt, input_path=None, image_url=None, output=None, model="fast", format="png")
Edit an existing image using AI instructions (img2img).
| Param | Default | Description |
|---|---|---|
| input_path | — | Path to local image file |
| image_url | — | URL of the image (alternative) |
| model | fast | fast (~10s) or precise (~30s) |
| format | png | png or jpg |
Returns EditResult: success, output_path, output_size, model, prompt
client.describe(input_path=None, image_url=None)
Generate AI alt-text / caption for an image. Free — no rate limit.
Returns DescribeResult: success, description
Supported Formats
Image input: JPEG, PNG, WEBP, HEIC, TIFF, BMP, GIF, RAW (20+ formats)
Image output: JPEG, PNG, WEBP, AVIF
Document input: PDF, DOCX, PPTX, XLSX
Get API Key
- Sign up at deflato.com
- Go to Account -> Generate API Key
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file deflato-1.3.0.tar.gz.
File metadata
- Download URL: deflato-1.3.0.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
da43e2a1a66f3cdd59f3259ef54de9488d74eea97c062e70a6b8eec48467f3eb
|
|
| MD5 |
d69cf098faaa62ee9f358790eed6d2ff
|
|
| BLAKE2b-256 |
b2259bfed6a571a05545592fd909df9887d41ed92b3a145beafa550761a9f6ff
|
File details
Details for the file deflato-1.3.0-py3-none-any.whl.
File metadata
- Download URL: deflato-1.3.0-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d4498afbd439d643972afcecb23e41881cc4ee47b2a3779ec9405b26de15d547
|
|
| MD5 |
ef4fac90a0295bb717285e4f3eea8756
|
|
| BLAKE2b-256 |
84f2f2d85418b921106797fefd99adddc7c0dbb6529ad9a04abb04be88cb18ae
|