Remove password protection from PDF files you own, given the correct password.
Project description
pdfunlock
A small command-line tool that removes password protection from PDF files you own, when you supply the correct password.
What it is not: pdfunlock does not crack, guess, brute-force, or bypass passwords. If you don't know the password, this tool cannot (and will not) help.
Installation
pip install pdfunlock-cli
Or with pipx for an isolated install:
pipx install pdfunlock-cli
Either way you get the pdfunlock command and the pdfunlock Python module.
Requires Python 3.10 or newer.
Usage
pdfunlock PDF_FILE [OPTIONS]
Options:
-o, --output PATH Output path for the decrypted PDF.
Defaults to <name>_unlocked.pdf next to the input.
-p, --password TEXT Password for the PDF. If omitted, you are prompted
securely (input is never echoed).
--in-place Overwrite the original file instead of writing a copy.
-V, --version Show the version and exit.
--help Show this message and exit.
Examples
Decrypt a PDF, prompting securely for the password:
$ pdfunlock protected.pdf
Password for protected.pdf:
Success: decrypted PDF saved to 'protected_unlocked.pdf'.
Choose where the decrypted copy is written:
$ pdfunlock protected.pdf --output unlocked.pdf
Password for protected.pdf:
Success: decrypted PDF saved to 'unlocked.pdf'.
Pass the password on the command line (note: visible in shell history — prefer the prompt):
$ pdfunlock protected.pdf --password mypassword
Success: decrypted PDF saved to 'protected_unlocked.pdf'.
Overwrite the original file:
$ pdfunlock protected.pdf --in-place
Password for protected.pdf:
Success: decrypted PDF saved to 'protected.pdf'.
Wrong password? You get a clear error and a non-zero exit code:
$ pdfunlock protected.pdf --password oops
Incorrect password for 'protected.pdf'.
Already-unprotected files are handled gracefully too:
$ pdfunlock plain.pdf --password anything
'plain.pdf' is not password-protected. Nothing to do.
Python API
The same functionality is available as a library:
from pdfunlock import unlock_pdf, InvalidPasswordError
try:
out = unlock_pdf("protected.pdf", "mypassword")
print(f"Saved to {out}")
except InvalidPasswordError:
print("Wrong password")
Development
git clone https://github.com/akurathisasidhar/pdfunlock
cd pdfunlock
# Create a virtual environment
python -m venv .venv
.venv\Scripts\activate # Windows
source .venv/bin/activate # macOS / Linux
# Editable install with dev tools
pip install -e ".[dev]"
# Run the test suite
pytest
# With coverage
pytest --cov=pdfunlock
Project layout:
pdfunlock/
├── pyproject.toml
├── LICENSE
├── README.md
├── src/
│ └── pdfunlock/
│ ├── __init__.py # public API + version
│ ├── cli.py # Typer CLI entry point
│ ├── core.py # decryption logic
│ ├── exceptions.py # error types
│ └── py.typed # PEP 561 marker
└── tests/
├── conftest.py # generates test PDFs on the fly
├── test_core.py
└── test_cli.py
Publishing
Build the source distribution and wheel:
python -m build
Test the wheel locally before uploading:
pip install dist/pdfunlock_cli-1.0.0-py3-none-any.whl
pdfunlock --version
Upload to TestPyPI first (recommended):
twine upload --repository testpypi dist/*
pip install --index-url https://test.pypi.org/simple/ pdfunlock-cli
Then publish to PyPI:
twine upload dist/*
To release a new version: bump __version__ in src/pdfunlock/__init__.py, rebuild, and re-upload.
License
Project details
Release history Release notifications | RSS feed
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 pdfunlock_cli-1.0.0.tar.gz.
File metadata
- Download URL: pdfunlock_cli-1.0.0.tar.gz
- Upload date:
- Size: 7.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
563e18659eee4cc374647ce5d34e24e690950594deee04786d5c377056d87eb7
|
|
| MD5 |
e3e798bba9c9a740eb15a2927fed5e16
|
|
| BLAKE2b-256 |
99282a3eb59545e78b42596bac38fe00865bde04fb2abc70642d949104207a81
|
File details
Details for the file pdfunlock_cli-1.0.0-py3-none-any.whl.
File metadata
- Download URL: pdfunlock_cli-1.0.0-py3-none-any.whl
- Upload date:
- Size: 8.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
123cc9cf5fd52a5bde387aff5cba84e9216014b973fd05495cc4aa3f140ca14f
|
|
| MD5 |
f47b7d6b35f2a3f95eaf8454c867e3dc
|
|
| BLAKE2b-256 |
390e8cff4005034fd5bcee2869ff0c852c313def9d6b3639103d5be7f94ef903
|