pictomancer
Python SDK for Pictomancer.ai — a thin httpx wrapper around the REST API at https://api.pictomancer.ai.
Install
pip install .
From PyPI (when published):
pip install pictomancer
Sources
Every operation takes a source: an image URL, a base64 string, or a data: URI. For local files or in-memory bytes use the helpers:
from pictomancer import Client, source_from_bytes, source_from_path
with Client() as client:
out = client.compress(source_from_path("photo.jpg"), q=80)
with open("photo.jpg", "rb") as f:
out = client.compress(source_from_bytes(f.read()), q=80)
Configuration
api_key— optional Bearer token (Authorization: Bearer …).base_url— defaults tohttps://api.pictomancer.ai.timeout— request timeout in seconds (default30.0).
JSON helpers return dict; image operations return bytes (response body).
Synchronous client
from pictomancer import Client
with Client(api_key="your-api-key") as client:
info = client.info()
usage = client.usage()
meta = client.analyze("https://example.com/image.jpg")
out = client.resize("https://example.com/image.jpg", scale=0.5, format="webp")
out = client.compress("https://example.com/image.jpg", q=85, format="jpeg")
out = client.convert("https://example.com/image.jpg", "png", q=90)
out = client.crop("https://example.com/image.jpg", 0, 0, 100, 100, format="webp")
out = client.pipeline(
"https://example.com/image.jpg",
[
{"type": "resize", "params": {"scale": "0.5"}},
{"type": "convert", "params": {"format": "webp"}},
],
)
with open("out.webp", "wb") as f:
f.write(out)
Async client
import asyncio
from pictomancer import AsyncClient
async def main():
async with AsyncClient(api_key="your-api-key") as client:
info = await client.info()
usage = await client.usage()
meta = await client.analyze("https://example.com/image.jpg")
out = await client.resize("https://example.com/image.jpg", scale=0.5, format="webp")
return info, usage, meta, out
asyncio.run(main())
Geometry ops: smart crop, trim, fill, autorot
crop has three mutually exclusive modes:
with Client(api_key="your-api-key") as client:
# Manual: exact rectangle.
out = client.crop("https://example.com/image.jpg", 0, 0, 100, 100)
# Smart: gravity picks the window. One of 'attention', 'entropy', 'centre'.
out = client.crop("https://example.com/image.jpg", gravity="attention", width=200, height=200)
# Trim: removes a uniform background border. threshold defaults to 10.0 server-side.
out = client.crop("https://example.com/image.jpg", trim=True, threshold=5.0)
resize gains a fill mode: pass width + height (instead of scale/scale_x/scale_y) to
resize and smart-crop to exact dimensions in one call; gravity defaults to attention.
out = client.resize("https://example.com/image.jpg", width=200, height=150, gravity="entropy")
All four ops (resize, compress, convert, crop) accept autorot=True to apply EXIF
orientation before processing.
When a crop actually trims, the response carries X-Pictomancer-Trim-Left/-Top/-Width/-Height
headers (inspect them with your own httpx client or event hooks).
Enhance: denoise, auto-contrast, sharpen
All four ops (resize, compress, convert, crop) also accept denoise, equalize and
sharpen. Opt-in, base price - no surcharge.
with Client(api_key="your-api-key") as client:
out = client.convert("https://example.com/image.jpg", "webp", denoise=2, equalize=True)
out = client.resize("https://example.com/image.jpg", scale=0.5, sharpen=True)
denoise(int, 1-3) - median filter before the operation, window 3x3 to 7x7.equalize(bool) - auto-contrast, histogram equalisation of the value channel only; hue and saturation are preserved.sharpen(bool) - unsharp-mask sharpen after the operation (libvips defaults).
Applied in a fixed order: autorot -> denoise -> equalize -> operation -> sharpen. A compress
with any of these that comes out larger is still billed, unlike a plain compress with no gain.
Quality target (SSIM)
Instead of guessing a q value, ask for the smallest file that still scores at
least a given SSIM. Pass quality_target (float, 0 < v <= 1) to compress or
convert; the server binary-searches the encoder quality for you.
with Client(api_key="your-api-key") as client:
out = client.compress("https://example.com/image.jpg", format="webp", quality_target=0.95)
out = client.convert("https://example.com/image.jpg", "avif", quality_target=0.9)
Constraints (validated server-side, violations return 422):
- Mutually exclusive with
q, and withlossless=Trueonconvert. - Only for
jpeg,webpandavifoutputs;compressrequires an explicitformat. - Not supported inside
pipelineoperations. - Carries a flat surcharge for the extra encodes.
The search outcome is reported in response headers (the SDK returns the body only; inspect them with your own httpx client or event hooks if you need them):
X-Pictomancer-Quality-Target- the target you asked for.X-Pictomancer-Quality-Achieved- SSIM of the returned encode, e.g.0.9530.X-Pictomancer-Quality-Q-Final- encoder quality the search settled on.X-Pictomancer-Quality-Encodes- encode cycles spent.
Headers are absent when no search ran. X-Pig-Billed is 0 when the input came
back untouched (already within target at its current size).
Delivery: write the result somewhere else
By default an operation returns the optimized bytes. Pass a delivery target to
have Pictomancer write the result directly to your storage or endpoint instead —
the operation then returns a dict (etag, sha256, bytes written, ...). No cloud
credentials ever reach Pictomancer.
from pictomancer import Client, PutUrl, Callback
with Client(api_key="your-api-key") as client:
# Upload to a customer-signed presigned PUT URL (S3/R2/GCS/Azure).
res = client.resize(
"https://example.com/image.jpg",
scale=0.5,
delivery=PutUrl("https://bucket.s3.amazonaws.com/key?X-Amz-Signature=..."),
)
print(res["sha256"], res["bytes_written"])
# Or POST the bytes to your own callback endpoint (async/large jobs).
res = client.compress(
"https://example.com/image.jpg",
delivery=Callback("https://hooks.example.com/pig?token=secret"),
)
print(res["status"], res["sha256"])
PutUrl and Callback accept optional headers= (whitelisted storage headers,
e.g. Content-Type, Cache-Control, x-amz-*). The returned sha256 is the
digest of exactly the bytes delivered, so you can verify the stored object.
Authenticating a callback
Pass secret= to Callback to have the POST body signed. We send
X-Pig-Signature: sha256=<hex> (HMAC-SHA256 of the body, GitHub-webhook style).
The secret is used per request and never stored. Verify it on your endpoint:
res = client.resize(
"https://example.com/image.jpg",
scale=0.5,
delivery=Callback("https://hooks.example.com/pig", secret="shared-secret"),
)
# On your endpoint (any framework), recompute and constant-time compare:
import hashlib, hmac
expected = "sha256=" + hmac.new(b"shared-secret", request_body, hashlib.sha256).hexdigest()
assert hmac.compare_digest(expected, request.headers["X-Pig-Signature"])
Errors use httpx behavior: non-2xx responses raise httpx.HTTPStatusError after raise_for_status().
API documentation
Interactive docs: https://api.pictomancer.ai/docs
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 pictomancer-0.6.0.tar.gz.
File metadata
- Download URL: pictomancer-0.6.0.tar.gz
- Upload date:
- Size: 17.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
49644beb073461f12fd641c2a6aa098d2dc7d0f5d449c6e453c13337ab153b86
|
|
| MD5 |
b44fd3f2d0a4e92b4db3f6d8214e3884
|
|
| BLAKE2b-256 |
d1265fae9a9110f48372b7288452a1ed2d63445d667c00fc78e4ea7b23d72c12
|
Provenance
The following attestation bundles were made for pictomancer-0.6.0.tar.gz:
Publisher:
publish.yml on pictomancer/python-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pictomancer-0.6.0.tar.gz -
Subject digest:
49644beb073461f12fd641c2a6aa098d2dc7d0f5d449c6e453c13337ab153b86 - Sigstore transparency entry: 2498990465
- Sigstore integration time:
-
Permalink:
pictomancer/python-sdk@04b792ceeae559e2dff84dbd1a45b94f71531b08 -
Branch / Tag:
refs/tags/v0.6.0 - Owner: https://github.com/pictomancer
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@04b792ceeae559e2dff84dbd1a45b94f71531b08 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pictomancer-0.6.0-py3-none-any.whl.
File metadata
- Download URL: pictomancer-0.6.0-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ab9c9e3c2b07570745ad074211d5ebe05acb94d6e4f7cff37392cfddbcf5387c
|
|
| MD5 |
f40cb0053623df74f92661c6220fcfb7
|
|
| BLAKE2b-256 |
1f61dfd8d02ede670065b22f3d64000de983bc21904ad2c2270d2b577f080eb8
|
Provenance
The following attestation bundles were made for pictomancer-0.6.0-py3-none-any.whl:
Publisher:
publish.yml on pictomancer/python-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pictomancer-0.6.0-py3-none-any.whl -
Subject digest:
ab9c9e3c2b07570745ad074211d5ebe05acb94d6e4f7cff37392cfddbcf5387c - Sigstore transparency entry: 2498990468
- Sigstore integration time:
-
Permalink:
pictomancer/python-sdk@04b792ceeae559e2dff84dbd1a45b94f71531b08 -
Branch / Tag:
refs/tags/v0.6.0 - Owner: https://github.com/pictomancer
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@04b792ceeae559e2dff84dbd1a45b94f71531b08 -
Trigger Event:
push
-
Statement type: