PIGS-1096 - Add Optimize API benchmark sample - #14
Open
SudNitro23 wants to merge 3 commits into
Open
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.Changes
api/platform_api.py— async job support: submit withPrefer: respond-async, follow the SSE status stream, download the result (Accept: application/octet-stream). Addsoptimize()andJobFailedError. 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.Verification
minimal-file-size— 41.8% / 43.0% / 89.5% smaller, 56.5% overall (4.07 MB → 1.77 MB)🤖 Generated with Claude Code