Skip to main content

Deflato — compress images with one line of code

Project description

Deflato Python SDK

Compress 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 a single image
result = client.compress("photo.jpg", format="WEBP", quality=75)
print(f"Saved {result.savings_percent}% → {result.output_path}")

# Get info without saving
info = client.info("photo.jpg", format="AVIF")
print(f"{info.input_size:,}{info.output_size:,} bytes ({info.savings_percent}% savings)")

# Batch compress
results = client.compress_batch(
    ["img1.jpg", "img2.png", "img3.heic"],
    output_dir="./compressed",
    format="WEBP",
    quality=80,
)
for r in results:
    print(f"{r.output_path}: {r.savings_percent}%")

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)

Returns CompressResult:

  • success: bool
  • input_size: int (bytes)
  • output_size: int (bytes)
  • savings_percent: int
  • output_path: str
  • output_format: str

client.info(input_path, quality=80, format="JPEG")

Same as compress but doesn't save — returns size/dimension info.

client.compress_batch(input_paths, output_dir=None, quality=80, format="JPEG")

Compress multiple files. Returns list of CompressResult.

Supported Formats

Input: JPEG, PNG, WEBP, HEIC, TIFF, BMP, GIF, RAW (CR2, NEF, ARW, DNG)

Output: JPEG, PNG, WEBP, AVIF

Get API Key

  1. Sign up at deflato.com
  2. Activate Pro (or use promo code)
  3. 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

deflato-1.2.0.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

deflato-1.2.0-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file deflato-1.2.0.tar.gz.

File metadata

  • Download URL: deflato-1.2.0.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for deflato-1.2.0.tar.gz
Algorithm Hash digest
SHA256 d524ce23c833ab771b385fdc9520e6055e50365bfd20494b050f59f80cd0b4ab
MD5 fa1b77127e40ab9cdf9270855eddbfd7
BLAKE2b-256 08e19905a88e365f2e92b6cfd8fa2f61274cadf8b2b8238504d1802210c57982

See more details on using hashes here.

File details

Details for the file deflato-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: deflato-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for deflato-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c4a734d21f6d6fefa273800264336cb9889cbe70f48d3e0a6ce5de95097eb5af
MD5 c91c6714647162b902a2cf0e27848c6d
BLAKE2b-256 383db7f831ca81d3a76fb2e37515b220e5baa17a0a4d0d8362290af292b0edc8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page