Skip to content

Installation & Setup

This guide details how to set up PDF Anonymizer for development or programmatic usage.


Development Installation (Monorepo)

The repository uses uv, a fast Python package installer and resolver. Ensure you have uv installed. If not, follow the official Astral installation instructions.

Steps

  1. Clone the repository:

    git clone https://github.com/leo-gan/anonymizer.git
    cd anonymizer
    

  2. Sync the workspace: Run uv sync to create a virtual environment and install all development tools alongside workspace members:

    uv sync --group dev
    
    This sync command will install the CLI, core library, the Excel extra (openpyxl), the Word extra (python-docx), and the dependencies for all supported LLM providers (google, ollama, huggingface, openrouter, openai, anthropic).

  3. Activate the virtual environment:

    source .venv/bin/activate
    


Installing as a Library Dependency

If you are using id-extract, pdf-anonymizer-core, or pdf-anonymizer-cli in a separate external project, you can install them via pip or uv.

id-extract is the RE2 detector. It returns placements and does not replace text. pip install id-extract ships every bundled country. Narrow the set at call time with extract(..., countries=["CA", "FR", "GB"]) or the CLI --countries flag. Standalone guide: id-extract.

pip install id-extract

To keep the installation footprint small, the core package uses PEP 508 Extras for specific LLM providers. Install only the providers you plan to use:

# Base package only (no provider dependencies; CSV works here)
pip install pdf-anonymizer-core

# Install specific provider support
pip install "pdf-anonymizer-core[google]"
pip install "pdf-anonymizer-core[ollama]"
pip install "pdf-anonymizer-core[openai,anthropic]"

# Excel (.xlsx) input
pip install "pdf-anonymizer-core[excel]"

# Word (.docx) input
pip install "pdf-anonymizer-core[docx]"

# Local HTTP service (separate package; depends on core only)
pip install pdf-anonymizer-api

Available Extras

  • [google]: Installs the Google GenAI SDK (google-genai).
  • [ollama]: Installs the Ollama integration library.
  • [huggingface]: Installs libraries to connect to Hugging Face Hub models.
  • [openrouter]: Installs client tools to query OpenRouter.
  • [openai]: Installs the official OpenAI API SDK.
  • [anthropic]: Installs the official Anthropic API SDK.
  • [excel]: Installs openpyxl for .xlsx input. CSV uses the stdlib and needs no extra.
  • [docx]: Installs python-docx for .docx input. Legacy .doc and macro-enabled .docm are rejected.
  • [ner]: Installs gliner for local span NER (names and organizations). Pulls PyTorch. Off until you install it; best-speed then skips the cloud language model.
  • HTTP service is a separate package, pdf-anonymizer-api. It depends on core only, not the CLI. See HTTP service and Docker.

Scanned PDFs need the Tesseract binary on PATH and the --ocr flag. That is a system package, not a pip extra. See OCR a scanned PDF.


Environment Variables Configuration

To run the anonymizer with cloud providers, you must supply API credentials. The CLI automatically loads a .env file from the directory where the command is executed or any parent directory.

Create a .env file at the root of the repository:

# Google GenAI (Gemini Models)
GOOGLE_API_KEY="AIzaSy..."

# OpenAI
OPENAI_API_KEY="sk-proj-..."

# Anthropic (Claude Models)
ANTHROPIC_API_KEY="sk-ant-..."

# Hugging Face Hub
HUGGING_FACE_TOKEN="hf_..."

# OpenRouter
OPENROUTER_API_KEY="sk-or-v1-..."

# Ollama Local Host (Optional, defaults to localhost:11434)
OLLAMA_HOST="http://localhost:11434"

# Optional: lock mapping files as *.mapping.json.enc (AES-256-GCM + Argon2id)
ANONYMIZER_MAPPING_KEY="a long secret"

# Optional: seed for --operator TYPE=fake (same person → same fake)
ANONYMIZER_FAKE_SECRET="another long secret"

ANONYMIZER_MAPPING_KEY is optional. Without it, maps stay plaintext JSON. ANONYMIZER_FAKE_SECRET is required when an operator is fake. There is no built-in seed.


Verifying the Setup

To verify that the installation succeeded and all package internal references are valid, run the automated test suite:

uv run pytest

If the tests pass, you are ready to use the CLI tool!


See Also