comprestack
Official Python SDK for the Comprestack image optimization API.
Compress or convert images from scripts, Django, FastAPI, and workers with a small typed client. Same REST surface as the API docs and OpenAPI.
Install
pip install comprestack
Requirements: Python 3.9+ (uses httpx).
Create an API key in the dashboard, then set:
export COMPRESTACK_API_KEY=csk_live_…
Security
API keys must stay on the server. Do not put them in browsers, mobile apps, or public repositories.
Quick start
import os
from pathlib import Path
from comprestack import Comprestack
client = Comprestack(api_key=os.environ["COMPRESTACK_API_KEY"])
job = client.convert(
["photo.jpg"],
format="webp",
quality="balanced",
maxWidth=1600,
)
Path("photo.webp").write_bytes(client.download(job))
print(f"Saved {job['files'][0]['saved_percent']}% · {job['usage']['remaining']} left")
Compress without changing format:
job = client.compress(["hero.png"], quality="high")
Use as a context manager to close the HTTP client:
with Comprestack(api_key=os.environ["COMPRESTACK_API_KEY"]) as client:
job = client.compress([b"..."])
What you can do
| Goal | Method |
|---|---|
| Shrink, keep format | compress(files, …) |
| Change format + shrink | convert(files, format=…, …) |
| Re-fetch job metadata | get_job(id) |
| Download ZIP / result | download(job) or download(download_url) |
| Download one file in a batch | download_file(job_id, index) |
| Check quota | usage() |
| White-label billing report | room_report(room_id) |
Jobs finish in the same request. Results expire after about one hour.
Inputs
| Input | Example |
|---|---|
| File path | "photo.jpg" or Path("photo.jpg") |
| Bytes | b"…", bytearray, memoryview |
| File object | open("photo.jpg", "rb") |
| Named bytes | ("hero.png", data) or {"data": data, "filename": "hero.png"} |
Options
Available on both compress and convert:
| Option | Description |
|---|---|
quality |
"balanced" (default), "high", "smallest", or 1–100 on Pro/Business |
format |
convert only — webp, avif, jpeg, png, gif, tiff, bmp, ico |
maxWidth / maxHeight |
Downscale to fit (never enlarges) |
target_kb |
Aim for a max file size (Pro/Business) |
lossless |
Pixel-perfect where the codec allows (Pro/Business) |
keep_metadata |
Keep EXIF / color profile (default strips metadata, including GPS) |
Client configuration
client = Comprestack(
api_key=os.environ["COMPRESTACK_API_KEY"],
# base_url="https://api.comprestack.com/api/v1",
# timeout=300,
# max_retries=2, # extra tries on 429 / 503 (honours Retry-After)
# on_progress=lambda e: print(e["phase"], e["path"], e["attempt"]),
# headers={"X-Request-Id": "order-4417"},
)
Errors
Failed requests raise ComprestackError:
from comprestack import Comprestack, ComprestackError
try:
client.compress(["huge.tiff"])
except ComprestackError as err:
print(err.status, err.code, err.message)
# err.retry_after — seconds, when the API sent Retry-After
raise
Common codes: unauthorized, limit_reached, file_too_large, rate_limited, busy, plan_required.
Links
License
MIT © Comprestack
Metadata
Release files for comprestack 0.1.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 |
|---|---|---|---|---|
| comprestack-0.1.0.tar.gz | 9.5 kB | Without provenance | Details for comprestack-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| comprestack-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for comprestack-0.1.0-py3-none-any.whl |
Total release size: 19.0 kB
Release files / comprestack-0.1.0.tar.gz
| Download URL | comprestack-0.1.0.tar.gz |
|---|---|
| Size | 9.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
94950e3a10dbc626e2211ba0a0a380c1ea2362de31cbff14d57431210a125fea
|
|
BLAKE2b-256 checksum How to use checksums |
a0b5606a42e8022dce3528101b4a12213665fd4cada05ae2bfb1570239fc0ad6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.9
|
Release files / comprestack-0.1.0-py3-none-any.whl
| Download URL | comprestack-0.1.0-py3-none-any.whl |
|---|---|
| Size | 9.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8412acd5e4513f9422bceb6149c42e87ae4f1c6d9e2c0c63afe11d4f7c16ac74
|
|
BLAKE2b-256 checksum How to use checksums |
510aa133ad664d3e49e7118286db279a68713d6175c76ea9935e9f6f355a2198
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.9
|
Security for comprestack 0.1.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.