Official Python SDK for the Resize Relay API — resize images to exact KB file sizes and exact dimensions (passport, exam, and marketplace specs).
Project description
Resize Relay — Python SDK
Official Python client for the Resize Relay API: resize images to exact KB file sizes and exact pixel dimensions — the specs that passport portals, government exam forms, and marketplaces actually enforce.
- Exact-size engine — binary-searches encoder quality to hit a KB ceiling (and a floor, for "20–50 KB" style bands), reducing resolution only when unavoidable.
- Exact-dimension crops —
fit="cover"produces exactlywidth×heightwith a centered, saliency-aware crop (no stretching). - Free tier — 500 resizes/month per key. Create a key →
Install
pip install resizerelay
Quickstart
import os
from resizerelay import ResizeRelay
client = ResizeRelay(os.environ["RESIZERELAY_API_KEY"])
# Job-portal photo: exactly 600×600, under 100 KB
client.resize_to_file(
"photo.jpg", "photo-600.jpg",
target_kb=100, width=600, height=600, fit="cover",
)
# Exam signature: 350×200 JPEG between 10 and 20 KB
result = client.resize(
"signature.png",
target_kb=20, min_kb=10, width=350, height=200,
fit="cover", format="jpeg",
)
print(result.content_type, len(result.content), "bytes")
print("quota:", result.quota_used, "/", result.quota_limit)
Input can be a file path, bytes, or a binary file-like object. ResizeResult.content holds the resized image; quota headers are parsed for you.
Options
| Option | Type | Description |
|---|---|---|
target_kb |
float |
Max output size in KB. |
target_mb |
float |
Max output size in MB (overrides target_kb). |
min_kb |
float |
Min output size in KB (compliance bands). |
width |
int |
Output width in px. |
height |
int |
Output height in px. |
fit |
"cover" | "inside" |
cover = exact width×height via centered crop; inside = fit within, keep aspect (default). |
format |
"jpeg" | "png" | "webp" |
Output format (default jpeg). |
quality |
float |
Encoder quality 0–1 (default 0.92). |
Error handling
All non-2xx responses raise ResizeRelayError with status, request_id, and (for rate limits) retry_after:
from resizerelay import ResizeRelay, ResizeRelayError
try:
client.resize("photo.jpg", target_kb=50)
except ResizeRelayError as err:
print(err.status, err, "request:", err.request_id)
if err.status == 429 and err.retry_after:
... # burst limit — back off err.retry_after seconds
| Status | Meaning |
|---|---|
400 |
Bad input (missing file, unreachable target). |
401 |
Missing, invalid, or revoked API key. |
413 |
Image larger than 25 MB. |
429 |
Burst rate limit (120 req/min) or monthly quota reached. |
Links
- API documentation
- Get an API key
- Resize Relay — the free in-browser tools
- Node.js SDK
License
Project details
Release history Release notifications | RSS feed
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 resizerelay-0.1.0.tar.gz.
File metadata
- Download URL: resizerelay-0.1.0.tar.gz
- Upload date:
- Size: 6.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
823364a8ec629551feba93cbb72a5072588bdab3f9fce9ef1175bdeb97750df3
|
|
| MD5 |
407c091b5266dcdfe20cbe25925fc177
|
|
| BLAKE2b-256 |
cbbe9a5e35f4473e576a2ec15c27cbc35905141b983676655d11d96e1bb6f1d1
|
File details
Details for the file resizerelay-0.1.0-py3-none-any.whl.
File metadata
- Download URL: resizerelay-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f0bc7f04d4e8ecd359e1cf4782c48a4b87c12cbbe9ed9404bb3d6354f3c0836b
|
|
| MD5 |
849161f3db1a524e024233d3d9015c07
|
|
| BLAKE2b-256 |
cc2e7615e84591afa2f20294eecf935e2f838fdf5fea7e685de357b187e9034e
|