Metadata-Version: 2.5
Name: zyppcli
Version: 0.3.0
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: 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. Detected text is replaced with labels
such as `<PERSON>`, `<EMAIL_ADDRESS>` and `<NL_BSN>`. PDF detections are masked
with opaque black pixels.

| 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. 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 entity-label replacements. |
| `.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 and existing destinations are refused. Symbolic links
are not followed. For folders, unsupported files are skipped and failed files
have no final output; 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.

**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.
