Skip to main content

pdfmasker

PyPI - Python Version PyPI PyPI - Downloads CodSpeed Badge

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 PikepdfBackend edits content streams directly in Python.
  • Detector (optional) — what to mask. Pass literal patterns, or configure detectors such as RegexDetector to discover targets from the document text.
  • Editor — how each match is rendered: FixedCharEditor (default X), FixedStringEditor, PseudonymizeEditor, or KeyedPseudonymizeEditor.
  • 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)

Source distribution for pdfmasker 0.1.0
File Size Uploaded
pdfmasker-0.1.0.tar.gz 18.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pdfmasker 0.1.0
File Interpreter ABI Platform
pdfmasker-0.1.0-py3-none-any.whl Python 3 none any Details

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}

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

0.0.3

6 release files

0.0.2

6 release files

0.0.1

6 release files

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