Skip to main content

PDF Anonymizer Core

Core Python SDK for reversible, context-aware document and table pseudonymization across PDF, Markdown, plain text, Word (.docx), CSV, and Excel (.xlsx). Used by pdf-anonymizer-cli and pdf-anonymizer-api.

It is a reversible pseudonymizer, not a legal compliance certificate. Full guides and the companion Anonymization Handbook live at leo-gan.github.io/anonymizer/.

Installation

# Base library (RE2 structured detection via id-extract; CSV supported)
pip install pdf-anonymizer-core

# Provider and format extras (combine as needed)
pip install "pdf-anonymizer-core[google]"
pip install "pdf-anonymizer-core[ollama]"
pip install "pdf-anonymizer-core[openai,anthropic]"
pip install "pdf-anonymizer-core[huggingface,openrouter]"
pip install "pdf-anonymizer-core[excel,docx,ner]"

Scanned PDF OCR requires the system tesseract binary on PATH (not a pip extra).

Environment Variables

The core library does not automatically load .env files; set variables in your process environment (or load them with python-dotenv):

  • Provider keys (only for remote models you invoke): GOOGLE_API_KEY, OPENAI_API_KEY, ANTHROPIC_API_KEY, HUGGING_FACE_TOKEN, OPENROUTER_API_KEY
  • OLLAMA_HOST: optional local Ollama URL (default http://localhost:11434)
  • ANONYMIZER_MAPPING_KEY: optional passphrase to encrypt mappings as *.mapping.json.enc (Argon2id + AES-256-GCM + source-hash AAD)
  • ANONYMIZER_FAKE_SECRET: required seed when using the fake operator
  • ANONYMIZER_ENCRYPT_SECRET: required secret when using the encrypt operator (ENC1_… tokens)

Quick Start

from pdf_anonymizer_core.conf import ConfigProfile, get_config_for_profile
from pdf_anonymizer_core.core import anonymize_file
from pdf_anonymizer_core.prompts import detailed
from pdf_anonymizer_core.utils import deanonymize_file, save_results

cfg = get_config_for_profile(ConfigProfile.BEST_SPEED, countries=["US", "GB"])

anonymized_text, mapping = anonymize_file(
    file_path="data/contract.pdf",
    characters_to_anonymize=cfg.chunk_size,
    prompt_template=detailed.prompt_template,
    model_name=cfg.model_name,
    chunk_overlap=cfg.chunk_overlap,
    regex_patterns=cfg.regex_patterns,
)

# Persist with atomic 0600 mapping permissions (optional mapping_passphrase / ephemeral_mapping)
anon_path, map_path = save_results(
    anonymized_text,
    {v: k for k, v in mapping.items()},
    "data/contract.pdf",
)

restored_path, stats_path = deanonymize_file(anon_path, map_path)

Key Capabilities

  • Profiles (ConfigProfile): BEST_QUALITY (detailed prompt, detects indirect identity clues), BEST_SPEED (default), BEST_COST, and REGEX_ONLY (use_llm=False, offline).
  • Hybrid detection & checksums: RE2 patterns via id-extract (universal + 38 countries, filter_regex_patterns), 26 check-digit validators (TYPE_LIKE vs. strict drop), optional local GLiNER (use_ner=True), and multi-provider LLMs.
  • Span replacement & operators: Character-interval longest-span replacement with per-type operators (replace, mask, hash, generalize, shift, fake, encrypt), keep_list/deny_list, seed_mapping, min_confidence, and EntityProfile.HIPAA_SAFE_HARBOR.
  • Tables & Word: anonymize_tabular_file (.csv/.xlsx, plus optional table_privacy $k$-anonymity reporting) and anonymize_docx_file (.docx).
  • Verification & hygiene: verify_anonymized_text, apply_residuals, assess_linkage_risk, configure_cache (off by default), and purge_local_artifacts.

Documentation

Metadata

Release files for pdf-anonymizer-core 0.37.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-anonymizer-core 0.37.0
File Size Uploaded Provenance Actions
pdf_anonymizer_core-0.37.0.tar.gz 103.9 kB With provenance Details for pdf_anonymizer_core-0.37.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for pdf-anonymizer-core 0.37.0
File Actions
pdf_anonymizer_core-0.37.0-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details for pdf_anonymizer_core-0.37.0-cp310-abi3-win_amd64.whl
pdf_anonymizer_core-0.37.0-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.10 abi3 Linux glibc 2.17+ x86-64 Details for pdf_anonymizer_core-0.37.0-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
pdf_anonymizer_core-0.37.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.10 abi3 Linux glibc 2.17+ ARM64 Details for pdf_anonymizer_core-0.37.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
pdf_anonymizer_core-0.37.0-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details for pdf_anonymizer_core-0.37.0-cp310-abi3-macosx_11_0_arm64.whl
pdf_anonymizer_core-0.37.0-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details for pdf_anonymizer_core-0.37.0-cp310-abi3-macosx_10_12_x86_64.whl

Total release size: 3.6 MB

Release files / pdf_anonymizer_core-0.37.0.tar.gz

Download URL pdf_anonymizer_core-0.37.0.tar.gz
Size 103.9 kB
Tags Source
SHA-256 checksum
How to use checksums
4aaca5199f185ef482f44c3ee9b589fa264d598b5e91a34aae92f1a50b324fe9
BLAKE2b-256 checksum
How to use checksums
c17d08bc648f8fd3a66c0ce1c2e0c59c2ee47dbb43b08b81162183f2c3b791e7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 2, 2026.

Transparency log

Release files / pdf_anonymizer_core-0.37.0-cp310-abi3-win_amd64.whl

Download URL pdf_anonymizer_core-0.37.0-cp310-abi3-win_amd64.whl
Size 593.4 kB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
06130e00292d2145267b695185c01108a5c580499b05ef00d0fe24d8fa938bb7
BLAKE2b-256 checksum
How to use checksums
b2e3d087f094e46721b734f55ca6a52c93c68f192981c5ffe353d282fc237db7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 2, 2026.

Transparency log

Release files / pdf_anonymizer_core-0.37.0-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL pdf_anonymizer_core-0.37.0-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 793.7 kB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
da1b155039bfb7c09a3b88fdf2412ea6d1720d72d60b4e3019500330c336fbad
BLAKE2b-256 checksum
How to use checksums
8bd2cafea2eabe4f9ce2301efcbf480d337fe64330af7109d9b5fd22efd73eb6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 2, 2026.

Transparency log

Release files / pdf_anonymizer_core-0.37.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL pdf_anonymizer_core-0.37.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 715.9 kB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
65cdf7871ff3d40ac99b69ef870a8e41ac9aeeccdf1b13a7b3d674825b5a82b6
BLAKE2b-256 checksum
How to use checksums
1afec4ad44b33377a3c052a348c635c8ee8ab0a3ba3e53f3233aadbdd3278f94
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 2, 2026.

Transparency log

Release files / pdf_anonymizer_core-0.37.0-cp310-abi3-macosx_11_0_arm64.whl

Download URL pdf_anonymizer_core-0.37.0-cp310-abi3-macosx_11_0_arm64.whl
Size 659.7 kB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
f2ddbba52a04c2e22b09513f6cb90f8f4a1f6a8c2d6b13f8e0896a5aa6af5bbb
BLAKE2b-256 checksum
How to use checksums
bb1293d29158f6a72639de2078cf955d220a651e484101a4a494810273eb6069
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 2, 2026.

Transparency log

Release files / pdf_anonymizer_core-0.37.0-cp310-abi3-macosx_10_12_x86_64.whl

Download URL pdf_anonymizer_core-0.37.0-cp310-abi3-macosx_10_12_x86_64.whl
Size 720.9 kB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
31bdcb47c9fd6be2edd4bd29da3247eae90116c6334f50cb7cf458d782cbc5b6
BLAKE2b-256 checksum
How to use checksums
ab923e31ae279648dad5b5db3f8dd9552274bb397e689b6cceb97b5311d6d598
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 2, 2026.

Transparency log

Security for pdf-anonymizer-core 0.37.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.

Full provenance

All 6 files in this release have been uploaded with provenance metadata.

Select from 6 files

Attestation for pdf_anonymizer_core-0.37.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 2, 2026.

Transparency log

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