Metadata-Version: 2.5
Name: zyppcli
Version: 0.4.2
Summary: Internal CLI for Zypp
Requires-Python: >=3.12
Requires-Dist: azure-identity>=1.17.0
Requires-Dist: azure-keyvault-secrets>=4.8.0
Requires-Dist: azure-mgmt-keyvault>=10.0.0
Requires-Dist: certifi>=2026.10.18
Requires-Dist: faker>=40.63.0
Requires-Dist: openpyxl>=3.1.5
Requires-Dist: pandas>=3.1.1
Requires-Dist: pillow>=13.0.0
Requires-Dist: presidio-analyzer<3,>=2.2.360
Requires-Dist: presidio-anonymizer<3,>=2.2.360
Requires-Dist: presidio-image-redactor>=0.0.62
Requires-Dist: pymupdf<2,>=1.26.0
Requires-Dist: spacy<3.9,>=3.8
Requires-Dist: tldextract>=5.4.0
Description-Content-Type: text/markdown

# Zypp CLI

Internal CLI for Zypp: load secrets from Azure Key Vault and anonymize client files locally with Microsoft Presidio.

## Installation

```bash
uv tool install zyppcli
```

To upgrade to the latest version:

```bash
uv tool install zyppcli --upgrade
```

## Key Vault prerequisites

You need to be authenticated with Azure:

```bash
az login
```

## Usage

### Anonymize PDF, Excel or text files

Install Zypp CLI normally, then download both local spaCy models once:

```bash
uv tool install zyppcli
zypp anonymize --setup
```

To install from this checkout, use `uv tool install .` instead. To upgrade an
existing installation, use `uv tool install zyppcli --upgrade`. Setup installs the
Dutch and English models into the CLI's own environment, using uv when available
or pip otherwise. It can be run again safely. Downloading models requires network
access; anonymizing client files does not download anything.

Scanned PDFs and PDF pages with images or annotations also need local Tesseract
OCR and its Dutch (`nld`) and English (`eng`) language packs:

```bash
# macOS
brew install tesseract tesseract-lang

# Ubuntu/Debian
sudo apt-get install tesseract-ocr tesseract-ocr-nld tesseract-ocr-eng

# Check which language packs are available
tesseract --list-langs
```

```bash
zypp anonymize report.pdf
# -> report.anonymized.pdf

zypp anonymize customers.xlsx
# -> customers.anonymized.xlsx

zypp anonymize ./client-files
# -> ./client-files.anonymized/ (recursive, with relative file paths preserved)

zypp anonymize report.pdf --language en
zypp anonymize ./client-files --output ./review-copy
```

Dutch is the default. Processing uses local Presidio/spaCy/Tesseract engines;
client files are not sent to cloud services. By default, detected values are
replaced with synthetic data: fake names, example-domain emails, generated bank
accounts and other values of the detected type. The same entity type and exact
value receive the same replacement within one run; the in-memory mapping is not
saved. Different runs generate new data.

```bash
# Default: fill detected fields with bogus data
zypp anonymize report.pdf

# Previous behavior: black PDF boxes and entity-label replacements in text/Excel
zypp anonymize report.pdf --redact
```

PDF originals are removed before replacement text is drawn, including text in
images. Unaffected native text stays selectable. Native replacements preserve the original
font size and baseline, using a built-in font with matching family/weight/style.
Scanned replacements estimate the size from OCR glyph bounds. Long fake values
are abbreviated with `...` to fit the original field; they are never shrunk. No original text is left hidden
under the replacement. If a field cannot fit even one replacement character at
the original size, that field gets a black redaction and processing continues.
The CLI reports the number of such fields. A synthetic PDF field is not an editable
form widget.

Detection is broad by default: organization names and locations are included,
as well as personal identifiers. Dates are now excluded by default, including
birth dates; ordinary dates and durations are usually useful business content.
To include dates, explicitly select `DATE_TIME` alongside the other entity types
you need. Recognized durations such as `8 maanden` or `8 months` stay unchanged
even with `DATE_TIME` selected. For business documents where you want to keep
those categories, opt into the narrower personal profile:

```bash
zypp anonymize report.pdf --profile personal
```

This profile targets people, email addresses, phone numbers, Dutch BSNs, IBANs and
credit cards. It leaves organization names, locations and dates alone, including
birth dates. It reduces false positives on ordinary Dutch business terms that the
language model mistakes for organizations or places. It does not prevent all
incorrect detections of person names.

For more specific tuning:

```bash
# Choose exactly which Presidio entity types to detect (overrides the profile)
zypp anonymize report.pdf --entities PERSON EMAIL_ADDRESS PHONE_NUMBER NL_BSN IBAN_CODE

# Explicitly include calendar dates (entity selection overrides the profile)
zypp anonymize report.pdf --entities PERSON EMAIL_ADDRESS PHONE_NUMBER NL_BSN IBAN_CODE DATE_TIME

# Discard detections below a Presidio score of 0.7
zypp anonymize report.pdf --profile personal --score-threshold 0.7

# Keep an exact detected phrase; repeat the option for more phrases
zypp anonymize report.pdf --allow-list Vakantiebijslag --allow-list Onregelmatigheids-
```

Settings apply to native PDF text, OCR, Excel, CSV and text/JSON alike. Allow-list
matches are exact and case-sensitive. The default score threshold remains `0`,
keeping broad detection within the selected categories. Raising it is not a universal fix: spaCy
name/location/organization detections commonly share the same fixed score, so a
high threshold can discard real names as well as false positives. Start by choosing
the categories your use case needs; use an allow-list for known-safe exact phrases.

| Format | Result |
| --- | --- |
| `.pdf` | Preserves unaffected selectable text on native and mixed pages. Scans use OCR for detection and remain image content. Detected characters are deleted and matching image pixels are blanked before synthetic text is inserted; `--redact` uses black fills. Interactive forms, annotations, links and original document metadata are removed. |
| `.xlsx` | Fresh values-only workbook. All worksheets and hidden cells are processed; output tabs are named `Sheet1`, `Sheet2`, etc. Formulas, formatting, comments, links, drawings and original metadata are omitted. |
| `.csv`, `.tsv` | Properly quoted UTF-8 data with cell-level replacements. CSV uses commas; TSV uses tabs. |
| `.txt`, `.md`, `.log` | UTF-8 text with synthetic values, or entity labels with `--redact`. |
| `.json`, `.jsonl` | Valid JSON with processed keys and values. Colliding or duplicate keys are rejected. |

Excel formulas use the results saved by Excel. If a formula has no saved result,
the workbook fails with an instruction to recalculate and save it in Excel.
Numeric identifiers are scanned too; matched numbers become replacement strings.
Unmatched values retain their types, and text leading zeroes are preserved.
Custom Excel display formats such as `000000000` are not retained. Excel drawings
and embedded objects are omitted with a warning, rather than processed as images.

Originals are preserved. Rerunning replaces matching output files automatically;
you do not need to delete earlier output first. Replacement is atomic: a failed
rerun keeps the previous completed output. Folder reruns keep unrelated existing
files. Source/output overlap and symbolic links are refused.

For folders, unsupported files are skipped. Failed new files have no final output,
and completed files are retained. A skipped or failed file makes the command exit
with status `1` and report a partial run. Temporary files and new output use
owner-only permissions where supported.

Dutch invoice coverage includes an IBAN-field fallback for OCR spacing/character
confusion and a targeted name recognizer for initials and a
surname after `T.a.v.` or `Ter attentie van`, plus Dutch VAT ID format detection
(`NL_VAT`) in broad mode. The personal profile includes the name recognizer but
omits VAT IDs unless explicitly selected through `--entities`. These focused rules
help with invoice fields; arbitrary names and addresses can still be missed.

**Review output before sharing.** Detection and OCR can miss personal data or
replace harmless text. Faces, signatures, indirect identifiers and every kind of
address or sensitive fact are not comprehensively detected. Filesystem names
remain unchanged and may themselves identify people. Legacy `.xls`, macro-enabled
Office files and password-protected PDFs are not supported.

For implementation details, see [the anonymize plan](plans/anonymize-plan.md).

### List Key Vaults

```bash
zypp keyvault list --subscription <subscription-id>
```

Lists all accessible Key Vaults in the given Azure subscription.

To filter by name (case-insensitive substring match):

```bash
zypp keyvault list --subscription <subscription-id> --name dev
```

### Load secrets from Azure Key Vault

```bash
eval $(zypp keyvault load --vault <vault-name>)
```

This fetches all enabled secrets from the specified vault and exports them as environment variables. Secret names are transformed: hyphens become underscores and the name is uppercased (e.g. `db-password` becomes `DB_PASSWORD`).

Without `eval`, the command only prints the export statements without setting them:

```bash
zypp keyvault load --vault <vault-name>
# Output:
# export DB_PASSWORD='...'
# export SQL_DB='...'
```

### Version

```bash
zypp --version
```

## Development and checks

```bash
uv sync
uv run --no-sync zypp anonymize --setup
uv run --no-sync pytest
uv run --no-sync pytest -m integration
uvx prek run --all-files
```

The default suite tests file handling and document adapters without spaCy models
or Tesseract. Integration tests require both language models, Tesseract and its
`nld`/`eng` packs; they exercise real detection, scans, mixed PDFs and the CLI.
Use `--no-sync` after setup: an exact `uv sync` removes model packages that
are not in the project lockfile. Run setup again if needed. CI runs both suites.
