Skip to main content

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 to https://api.pictomancer.ai.
  • timeout — request timeout in seconds (default 30.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())

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 with lossless=True on convert.
  • Only for jpeg, webp and avif outputs; compress requires an explicit format.
  • Not supported inside pipeline operations.
  • 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

OpenAPI: https://api.pictomancer.ai/openapi.json

Metadata

Release files for pictomancer 0.4.0

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

Source distribution (sdist)

Source distribution for pictomancer 0.4.0
File Size Uploaded
pictomancer-0.4.0.tar.gz 15.8 kB Details

Built distribution (wheel)

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

Total release size: 21.5 kB

Release files / pictomancer-0.4.0.tar.gz

Download URL pictomancer-0.4.0.tar.gz
Size 15.8 kB
Tags Source
SHA-256 checksum
How to use checksums
64523a07866711bd7bae876a9afd9c4f066c21691711c46e8e7cd7da48e758c3
BLAKE2b-256 checksum
How to use checksums
2ec172d5fe460c382bcb03e92c59cfb0bec2878894f4345699acd7f602efc2bf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 2, 2026.

Transparency log

Release files / pictomancer-0.4.0-py3-none-any.whl

Download URL pictomancer-0.4.0-py3-none-any.whl
Size 5.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
80a396e8555680d0edad0526a23088dbad4a747e4d4f9e007e542c45cf7bc00d
BLAKE2b-256 checksum
How to use checksums
9eea33ff42fdd67591045aabcfa5529086fedd51942e3d2105554237b6ea02c7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 2, 2026.

Transparency log

Release history Release notifications | RSS feed

0.7.0

2 release files

0.6.0

2 release files

0.5.0

2 release files

This release

0.4.0 This release

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

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