Skip to main content

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.

PyPI version Python License: MIT


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"..."])

Async (FastAPI, etc.)

from comprestack import AsyncComprestack

async with AsyncComprestack(api_key=os.environ["COMPRESTACK_API_KEY"]) as client:
    job = await client.convert(["photo.jpg"], format="webp")
    data = await client.download(job)

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.



License

MIT © Comprestack

Metadata

Release files for comprestack 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for comprestack 0.1.1
File Size Uploaded Provenance Actions
comprestack-0.1.1.tar.gz 10.3 kB Without provenance Details for comprestack-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for comprestack 0.1.1
File Interpreter ABI Platform Actions
comprestack-0.1.1-py3-none-any.whl Python 3 none any Details for comprestack-0.1.1-py3-none-any.whl

Total release size: 22.6 kB

Release files / comprestack-0.1.1.tar.gz

Download URL comprestack-0.1.1.tar.gz
Size 10.3 kB
Tags Source
SHA-256 checksum
How to use checksums
0840a893c7154ebdd2d52e1e0426001c30642cc1251b591f119d5b871aa1d9e0
BLAKE2b-256 checksum
How to use checksums
46d220c71da7c66301470897ecd0e96d4a7ce1e29dfe9ed3b1b2c4348a9ab6cf
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.1-py3-none-any.whl

Download URL comprestack-0.1.1-py3-none-any.whl
Size 12.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2d14066d054c361474faffa543bf2fae8229aff922a022d443da03f3e2c87ba3
BLAKE2b-256 checksum
How to use checksums
60be38b3bc831f47c24826eb8abb3255ee232aca21688ea51d008363e77d09fe
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.1

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.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page