pdfmasker
With this library you can mask sensitive text in PDFs or basically change any text in your PDF files.
Usage
from pdfmasker import mask_pdf
pdf_bytes = open("paystub.pdf", "rb").read()
result = mask_pdf(pdf_bytes, patterns=["Jane Doe", "123-45-6789"])
result.document_content # bytes — the masked PDF
result.entries # per-target log: target, replacement, kind, count
By default each match is replaced in place with a run of X. An editor chooses how matches are rendered — a
constant string, or consistent pseudonyms:
from pdfmasker import FixedStringEditor, mask_pdf
mask_pdf(pdf_bytes, patterns=["Jane Doe"], editor=FixedStringEditor("[REDACTED]"))
Pluggable parts
Masking is composed from four pluggable parts:
- Backend — how the PDF is read and rewritten. The default in-process
PikepdfBackendedits content streams directly in Python. - Detector (optional) — what to mask. Pass literal
patterns, or configure detectors such asRegexDetectorto discover targets from the document text. - Editor — how each match is rendered:
FixedCharEditor(defaultX),FixedStringEditor,PseudonymizeEditor, orKeyedPseudonymizeEditor. - SubstitutionStore — keeps pseudonyms consistent and collision-free. Share one across documents so the same value always masks to the same replacement.
from pdfmasker import InMemorySubstitutionStore, Masker, PseudonymizeEditor, RegexDetector
store = InMemorySubstitutionStore()
masker = Masker(
detectors=[RegexDetector(r"\d{3}-\d{2}-\d{4}", kind="ssn")],
editor=PseudonymizeEditor(store),
)
result = masker.mask(pdf_bytes, patterns=["Jane Doe"])
Contributing
The architecture, repository layout, setup, dev commands (make help), the build/cross-build model, and the release
flow all live in CONTRIBUTING.md.
Metadata
Release files for pdfmasker 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pdfmasker-0.1.0.tar.gz | 18.4 kB | Without provenance | Details for pdfmasker-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pdfmasker-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for pdfmasker-0.1.0-py3-none-any.whl |
Total release size: 45.5 kB
Release files / pdfmasker-0.1.0.tar.gz
| Download URL | pdfmasker-0.1.0.tar.gz |
|---|---|
| Size | 18.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d7383b799dc0505af14f28087fc0f6c8600138dca36019aeb94e12bacbd3a69e
|
|
BLAKE2b-256 checksum How to use checksums |
79937169fea7c02deccf33591a5e16b4313cb7e40355867cf218c9306a3e2c65
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / pdfmasker-0.1.0-py3-none-any.whl
| Download URL | pdfmasker-0.1.0-py3-none-any.whl |
|---|---|
| Size | 27.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9c698087a7b8bce8eb7dde1db5dfa2e5e54a654728a3ce809cb242e5c3869d1d
|
|
BLAKE2b-256 checksum How to use checksums |
a628f0d10854c0fe48a2900a24b10bd0ca7c6c371fe3a977e40d54b09bd58e02
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for pdfmasker 0.1.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.