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 (defaulthttp://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 thefakeoperatorANONYMIZER_ENCRYPT_SECRET: required secret when using theencryptoperator (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(detailedprompt, detects indirect identity clues),BEST_SPEED(default),BEST_COST, andREGEX_ONLY(use_llm=False, offline). - Hybrid detection & checksums: RE2 patterns via
id-extract(universal + 38 countries,filter_regex_patterns), 26 check-digit validators (TYPE_LIKEvs. 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, andEntityProfile.HIPAA_SAFE_HARBOR. - Tables & Word:
anonymize_tabular_file(.csv/.xlsx, plus optionaltable_privacy$k$-anonymity reporting) andanonymize_docx_file(.docx). - Verification & hygiene:
verify_anonymized_text,apply_residuals,assess_linkage_risk,configure_cache(off by default), andpurge_local_artifacts.
Documentation
- SDK & API Usage — Full programmatic signatures and table/Word workflows.
- API Reference (auto) — Module-level docstring reference.
- Recipes & Workflows — End-to-end CLI and SDK patterns.
- Architecture & Mapping Security — Pipeline and cryptographic design notes.
- Anonymization Handbook — Theory, threat models, file-format leakage, and benchmarks.
Metadata
Release files for pdf-anonymizer-core 0.33.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 |
|---|---|---|---|---|
| pdf_anonymizer_core-0.33.0.tar.gz | 71.0 kB | With provenance | Details for pdf_anonymizer_core-0.33.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pdf_anonymizer_core-0.33.0-py3-none-any.whl | Python 3 | none | any | Details for pdf_anonymizer_core-0.33.0-py3-none-any.whl |
Total release size: 152.0 kB
Release files / pdf_anonymizer_core-0.33.0.tar.gz
| Download URL | pdf_anonymizer_core-0.33.0.tar.gz |
|---|---|
| Size | 71.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
798bb5f334e736afe9c8c4504421443f118ce4b814c53a03df7256ecb7e39f8e
|
|
BLAKE2b-256 checksum How to use checksums |
e43b361064b53f7734b0ed33e70e704ef3cff81553379fe57ea41c558fef8c48
|
| 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 Nov 23, 2026.
Transparency logRelease files / pdf_anonymizer_core-0.33.0-py3-none-any.whl
| Download URL | pdf_anonymizer_core-0.33.0-py3-none-any.whl |
|---|---|
| Size | 81.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e895240bac72d36914a087debbabe995d57b6fc94dc159f99a4a92650e32373d
|
|
BLAKE2b-256 checksum How to use checksums |
a57a8450897a46fa74d57e6df893fe4ed32e13f66f43080b776bae72a0e8e8b9
|
| 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 Nov 23, 2026.
Transparency logSecurity for pdf-anonymizer-core 0.33.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
Both files in this release have been uploaded with provenance metadata.
Attestation for pdf_anonymizer_core-0.33.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 Nov 23, 2026.
Transparency logA 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.