Skip to main content

PDF Compressor

CI crates.io PyPI PyPI Downloads

Command line PDF compression powered by the free iLovePDF API.

Why? iLovePDF delivers the best PDF compression I've seen but their web UI doesn't support automation and can be cumbersome when dealing with many files.

Installation

A single self-contained binary, installable either way:

pip install pdf-compressor  # prebuilt wheels, no Rust toolchain needed
cargo install pdf-compressor

Usage

First, tell pdf-compressor your iLovePDF API key (if you haven't yet, get one by signing up at https://developer.ilovepdf.com/signup):

pdf-compressor --set-api-key project_public_7c854a9db0...

This saves the key to ~/.config/pdf-compressor/api-key ($XDG_CONFIG_HOME is respected, %APPDATA% on Windows). Alternatively, set the ILOVEPDF_PUBLIC_KEY environment variable, which takes precedence.

Then start compressing!

pdf-compressor **/*.pdf           # writes foo-compressed.pdf next to each foo.pdf
pdf-compressor docs/ -o out/ -s "" # all PDFs under docs/ into out/ with original names
pdf-compressor -i report.pdf      # replace original (moved to the system trash)

All inputs are validated (output paths, stats file type, file existence) before anything is uploaded, so typos don't cost API quota. Uploads stream from disk, up to 4 at a time, with a progress line when run in a terminal.

Options

Flags Default Description
-i/--inplace off Replace originals with compressed PDFs. Originals go to the system trash (macOS Trash, Windows Recycle Bin, freedesktop trash on Linux). Conflicts with --suffix and --outdir.
-s/--suffix -compressed Appended to compressed file names. May be empty together with --outdir.
-o/--outdir next to input Directory to write compressed PDFs into (created if missing).
--cl/--compression-level recommended One of low, recommended, extreme. extreme noticeably degrades embedded bitmap images.
--min-red/--min-size-reduction 10 with -i, else 0 Only keep compressed files that are more than this many percent smaller.
--password Password for protected PDFs. All inputs share it; PDFs with different passwords must be compressed separately.
--set-api-key Save the iLovePDF public key. Can't be combined with other flags.
--report-quota Print the number of remaining files in the current billing cycle.
--write-stats-path Write per-file original vs compressed sizes and actions taken to a .csv file.
-v/--version Print the version.

Set ILOVEPDF_API_URL to point at a different API endpoint (default https://api.ilovepdf.com).

Migrating from v0.4 (Python)

v0.5 is a Rust rewrite. The CLI keeps its flags with these exceptions:

  • The Python API (from pdf_compressor import compress, Compress) is gone. Call the CLI via subprocess.
  • --verbose, --on-no-files and --on-bad-files were removed: finding no PDFs exits 0 silently, passing a non-PDF file is an error, and results always show paths as given.
  • --set-api-key writes to the user config dir instead of a .env file inside the installed package. Re-run it once after upgrading, or set ILOVEPDF_PUBLIC_KEY.
  • --debug was removed.
  • --outdir now actually places the compressed PDFs there (it previously only changed where the download was staged).
  • --write-stats-path writes CSV only (no more JSON/Excel/HTML or pandas dependency), and other extensions are an error instead of silently writing nothing.
  • .pdfa/.pdfx extensions are no longer picked up; only .pdf (any case).
  • Errors exit with code 1 and a one-line message instead of a Python traceback.
  • Local file paths are no longer sent to iLovePDF; uploads are named 0.pdf, 1.pdf, ...

Metadata

Release files for pdf-compressor 0.5.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 pdf-compressor 0.5.0
File Size Uploaded Provenance Actions
pdf_compressor-0.5.0.tar.gz 27.0 kB Without provenance Details for pdf_compressor-0.5.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for pdf-compressor 0.5.0
File Actions
pdf_compressor-0.5.0-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details for pdf_compressor-0.5.0-py3-none-win_amd64.whl
pdf_compressor-0.5.0-py3-none-musllinux_1_2_x86_64.whl Python 3 none Linux musl 1.2+ x86-64 Details for pdf_compressor-0.5.0-py3-none-musllinux_1_2_x86_64.whl
pdf_compressor-0.5.0-py3-none-musllinux_1_2_aarch64.whl Python 3 none Linux musl 1.2+ ARM64 Details for pdf_compressor-0.5.0-py3-none-musllinux_1_2_aarch64.whl
pdf_compressor-0.5.0-py3-none-manylinux_2_28_aarch64.whl Python 3 none Linux glibc 2.28+ ARM64 Details for pdf_compressor-0.5.0-py3-none-manylinux_2_28_aarch64.whl
pdf_compressor-0.5.0-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl Python 3 none Linux glibc 2.17+ x86-64 Details for pdf_compressor-0.5.0-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
pdf_compressor-0.5.0-py3-none-macosx_11_0_arm64.whl Python 3 none macOS 11.0+ ARM64 Details for pdf_compressor-0.5.0-py3-none-macosx_11_0_arm64.whl
pdf_compressor-0.5.0-py3-none-macosx_10_12_x86_64.whl Python 3 none macOS 10.12+ x86-64 Details for pdf_compressor-0.5.0-py3-none-macosx_10_12_x86_64.whl

Total release size: 10.5 MB

Release files / pdf_compressor-0.5.0.tar.gz

Download URL pdf_compressor-0.5.0.tar.gz
Size 27.0 kB
Tags Source
SHA-256 checksum
How to use checksums
14b2fe47c63833ad94c61b08b51861f3b33f807232392db2e369f03c1051804b
BLAKE2b-256 checksum
How to use checksums
b368dd19055ab54944dc6b1cc3e690ce8546c473db99d3e5128bc783a9c1b8b0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / pdf_compressor-0.5.0-py3-none-win_amd64.whl

Download URL pdf_compressor-0.5.0-py3-none-win_amd64.whl
Size 1.5 MB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
69039c49433ed4e2ed914db4bf0008a59f122f9071f74338d790360e85b1cc88
BLAKE2b-256 checksum
How to use checksums
42781b208f62d9e0ef772d7aefb83375f3929f60e4f6e437e89b54dc5d89e15f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / pdf_compressor-0.5.0-py3-none-musllinux_1_2_x86_64.whl

Download URL pdf_compressor-0.5.0-py3-none-musllinux_1_2_x86_64.whl
Size 1.6 MB
Tags Linux musl 1.2+ x86-64 Python 3
SHA-256 checksum
How to use checksums
a7222f713b031bdd89c528585aabc946e8dc37e0bcb6860399253fa85ced2a32
BLAKE2b-256 checksum
How to use checksums
3ba1b3f4b4ae2890220eefc637dddaf851f8223acd7b2c129c9474751e6da16e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / pdf_compressor-0.5.0-py3-none-musllinux_1_2_aarch64.whl

Download URL pdf_compressor-0.5.0-py3-none-musllinux_1_2_aarch64.whl
Size 1.6 MB
Tags Linux musl 1.2+ ARM64 Python 3
SHA-256 checksum
How to use checksums
4d496fa6457114a62a0127c93ea72fc6b16679259232ee7d4f80ca587fd62286
BLAKE2b-256 checksum
How to use checksums
b009cc6ad0ab5af647ba3257e42dd7bca4fc132ef0ebf447a26c99f0f1a4c358
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / pdf_compressor-0.5.0-py3-none-manylinux_2_28_aarch64.whl

Download URL pdf_compressor-0.5.0-py3-none-manylinux_2_28_aarch64.whl
Size 1.5 MB
Tags Linux glibc 2.28+ ARM64 Python 3
SHA-256 checksum
How to use checksums
1359a8885355ebd1c8d9654c43c340b8e24417751492512b72c353a107b7789d
BLAKE2b-256 checksum
How to use checksums
8f63c1cf2242a5f0d0821a8d2031d34f97fb8470f91a1e9eb3f4942f486ac8fc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / pdf_compressor-0.5.0-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL pdf_compressor-0.5.0-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 1.6 MB
Tags Linux glibc 2.17+ x86-64 Python 3
SHA-256 checksum
How to use checksums
9eb04e3ded256b1023a1d1dfaa1fe12a584ad01406766645740e474429a2cd1d
BLAKE2b-256 checksum
How to use checksums
0b3b249b7d22a4350352da13a8c23b7d29112d08e848e6527e045f88b137801b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / pdf_compressor-0.5.0-py3-none-macosx_11_0_arm64.whl

Download URL pdf_compressor-0.5.0-py3-none-macosx_11_0_arm64.whl
Size 1.4 MB
Tags Python 3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
e81aec0b525d8dfcb19b8a183a86b7d959baa5d12b27f7190a06d883650ede97
BLAKE2b-256 checksum
How to use checksums
5d19f13ab165dcfc5a01414d422bda4a45f6413edf8ad67bffc30b1b656cce53
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / pdf_compressor-0.5.0-py3-none-macosx_10_12_x86_64.whl

Download URL pdf_compressor-0.5.0-py3-none-macosx_10_12_x86_64.whl
Size 1.4 MB
Tags Python 3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
996227f80de10382e11c0fa3ace568198ea71dcab6744994766825ce9b857d76
BLAKE2b-256 checksum
How to use checksums
368bf46bb73077b1e969e5b93601c2b58550d234e205ef349c61d8f227f002be
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for pdf-compressor 0.5.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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