Skip to content

PIGS-1096 - Add Optimize API benchmark sample - #14

Open
SudNitro23 wants to merge 3 commits into
mainfrom
pigs-1096-optimize-benchmark
Open

PIGS-1096 - Add Optimize API benchmark sample#14
SudNitro23 wants to merge 3 commits into
mainfrom
pigs-1096-optimize-benchmark

Conversation

@SudNitro23

Copy link
Copy Markdown

What

A new sample, optimize_benchmark.py, for prospects and customers evaluating the Optimize API on their own documents. It runs a folder of PDFs through one or more optimization profiles and reports per-file size reduction as CSVs plus a self-contained HTML report (headline numbers, size-reduction distribution chart, filterable per-file table) that opens in the browser when the run finishes.

uv run python optimize_benchmark.py ./pdfs ./output              # default: minimal-file-size
uv run python optimize_benchmark.py ./pdfs ./output -p minimal-file-size -p web
task optimize-benchmark INPUT_DIR=./pdfs OUTPUT_DIR=./output

Changes

  • api/platform_api.py — async job support: submit with Prefer: respond-async, follow the SSE status stream, download the result (Accept: application/octet-stream). Adds optimize() and JobFailedError. Large documents no longer time out on the synchronous request window.
  • benchmark/ — the operation runner (a result is only "success" when a valid PDF came back) and the report builder; the report's CSS/JS live as assets and are inlined at build time so the output stays one shareable file.
  • optimize_benchmark.py — typer CLI; auth/transport errors are recorded as failures instead of crashing, and a 401 from the token endpoint stops the run early with a hint.
  • test_files/optimize-benchmark/ — three sample PDFs (text-heavy, mixed, image-heavy) to try it on.
  • Taskfile task and README entries.

Verification

  • ruff check, ruff format and pyright (strict) all clean on the new/changed files
  • Tested against the live API: 3/3 sample PDFs optimized with minimal-file-size — 41.8% / 43.0% / 89.5% smaller, 56.5% overall (4.07 MB → 1.77 MB)

🤖 Generated with Claude Code

SudNitro23 and others added 3 commits September 7, 2026 17:25
Adds optimize_benchmark.py: runs a folder of PDFs through the Optimize
API and reports per-file size reduction as CSVs plus a self-contained
HTML report (headline numbers, distribution chart, filterable table).

- api/platform_api.py: async job support (Prefer: respond-async ->
  SSE status stream -> result download) and an optimize() method, so
  large documents no longer time out on the synchronous request window
- benchmark/: operation runner and report builder, with the report's
  CSS/JS kept as assets and inlined at build time
- test_files/optimize-benchmark/: three sample PDFs to try it on
- Taskfile task (optimize-benchmark) and README entries

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
An auth or transport error (e.g. a 401 from the token endpoint) is now
recorded as a per-file failure instead of crashing with a traceback,
which rich's locals rendering would have used to print the client
secret on screen. A 401 from /oauth/token also stops the run early
with a hint to check the .env credentials.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…load

The job result endpoint returns the job's JSON representation unless the
request asks for the file with Accept: application/octet-stream. Verified
against the live API: 3/3 sample PDFs optimized (56.5% overall reduction).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant