zyppcli 0.2.1__tar.gz → 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- zyppcli-0.3.0/.github/workflows/ci.yaml +42 -0
- zyppcli-0.3.0/PKG-INFO +175 -0
- zyppcli-0.3.0/README.md +155 -0
- zyppcli-0.3.0/plans/anonymize-plan.md +267 -0
- zyppcli-0.3.0/pyproject.toml +44 -0
- zyppcli-0.3.0/tests/conftest.py +32 -0
- zyppcli-0.3.0/tests/test_anonymize.py +200 -0
- zyppcli-0.3.0/tests/test_integration.py +129 -0
- zyppcli-0.3.0/tests/test_pdf.py +157 -0
- zyppcli-0.3.0/tests/test_tabular.py +87 -0
- zyppcli-0.3.0/uv.lock +2523 -0
- {zyppcli-0.2.1 → zyppcli-0.3.0}/zyppcli/__main__.py +4 -1
- zyppcli-0.3.0/zyppcli/anonymization/__init__.py +5 -0
- zyppcli-0.3.0/zyppcli/anonymization/pdf.py +137 -0
- zyppcli-0.3.0/zyppcli/anonymization/tabular.py +69 -0
- zyppcli-0.3.0/zyppcli/anonymization/text.py +174 -0
- zyppcli-0.3.0/zyppcli/commands/anonymize.py +123 -0
- zyppcli-0.2.1/.github/workflows/ci.yaml +0 -19
- zyppcli-0.2.1/PKG-INFO +0 -72
- zyppcli-0.2.1/README.md +0 -62
- zyppcli-0.2.1/pyproject.toml +0 -24
- zyppcli-0.2.1/uv.lock +0 -368
- {zyppcli-0.2.1 → zyppcli-0.3.0}/.github/workflows/publish.yaml +0 -0
- {zyppcli-0.2.1 → zyppcli-0.3.0}/.gitignore +0 -0
- {zyppcli-0.2.1 → zyppcli-0.3.0}/.pre-commit-config.yaml +0 -0
- {zyppcli-0.2.1 → zyppcli-0.3.0}/plans/zyppcli-plan.md +0 -0
- {zyppcli-0.2.1 → zyppcli-0.3.0}/zyppcli/__init__.py +0 -0
- {zyppcli-0.2.1 → zyppcli-0.3.0}/zyppcli/commands/__init__.py +0 -0
- {zyppcli-0.2.1 → zyppcli-0.3.0}/zyppcli/commands/keyvault.py +0 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches-ignore:
|
|
6
|
+
- "master"
|
|
7
|
+
- "main"
|
|
8
|
+
- "staging"
|
|
9
|
+
- "development"
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
build:
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v6
|
|
17
|
+
|
|
18
|
+
- name: Run prek pre-commit checks
|
|
19
|
+
uses: j178/prek-action@v1
|
|
20
|
+
|
|
21
|
+
tests:
|
|
22
|
+
runs-on: ubuntu-latest
|
|
23
|
+
steps:
|
|
24
|
+
- uses: actions/checkout@v6
|
|
25
|
+
- uses: astral-sh/setup-uv@v7
|
|
26
|
+
with:
|
|
27
|
+
python-version: "3.12"
|
|
28
|
+
- run: uv sync --locked
|
|
29
|
+
- run: uv run --no-sync pytest
|
|
30
|
+
|
|
31
|
+
integration:
|
|
32
|
+
runs-on: ubuntu-latest
|
|
33
|
+
steps:
|
|
34
|
+
- uses: actions/checkout@v6
|
|
35
|
+
- uses: astral-sh/setup-uv@v7
|
|
36
|
+
with:
|
|
37
|
+
python-version: "3.12"
|
|
38
|
+
- run: sudo apt-get update && sudo apt-get install -y tesseract-ocr tesseract-ocr-nld tesseract-ocr-eng
|
|
39
|
+
- run: uv sync --locked
|
|
40
|
+
- name: Install local language models
|
|
41
|
+
run: uv run --no-sync zypp anonymize --setup
|
|
42
|
+
- run: uv run --no-sync pytest -m integration
|
zyppcli-0.3.0/PKG-INFO
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: zyppcli
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: Internal CLI for Zypp
|
|
5
|
+
Requires-Python: >=3.12
|
|
6
|
+
Requires-Dist: azure-identity>=1.17.0
|
|
7
|
+
Requires-Dist: azure-keyvault-secrets>=4.8.0
|
|
8
|
+
Requires-Dist: azure-mgmt-keyvault>=10.0.0
|
|
9
|
+
Requires-Dist: certifi>=2026.10.18
|
|
10
|
+
Requires-Dist: openpyxl>=3.1.5
|
|
11
|
+
Requires-Dist: pandas>=3.1.1
|
|
12
|
+
Requires-Dist: pillow>=13.0.0
|
|
13
|
+
Requires-Dist: presidio-analyzer<3,>=2.2.360
|
|
14
|
+
Requires-Dist: presidio-anonymizer<3,>=2.2.360
|
|
15
|
+
Requires-Dist: presidio-image-redactor>=0.0.62
|
|
16
|
+
Requires-Dist: pymupdf<2,>=1.26.0
|
|
17
|
+
Requires-Dist: spacy<3.9,>=3.8
|
|
18
|
+
Requires-Dist: tldextract>=5.4.0
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
|
|
21
|
+
# Zypp CLI
|
|
22
|
+
|
|
23
|
+
Internal CLI for Zypp: load secrets from Azure Key Vault and anonymize client files locally with Microsoft Presidio.
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
uv tool install zyppcli
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
To upgrade to the latest version:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
uv tool install zyppcli --upgrade
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Key Vault prerequisites
|
|
38
|
+
|
|
39
|
+
You need to be authenticated with Azure:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
az login
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Usage
|
|
46
|
+
|
|
47
|
+
### Anonymize PDF, Excel or text files
|
|
48
|
+
|
|
49
|
+
Install Zypp CLI normally, then download both local spaCy models once:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
uv tool install zyppcli
|
|
53
|
+
zypp anonymize --setup
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
To install from this checkout, use `uv tool install .` instead. To upgrade an
|
|
57
|
+
existing installation, use `uv tool install zyppcli --upgrade`. Setup installs the
|
|
58
|
+
Dutch and English models into the CLI's own environment, using uv when available
|
|
59
|
+
or pip otherwise. It can be run again safely. Downloading models requires network
|
|
60
|
+
access; anonymizing client files does not download anything.
|
|
61
|
+
|
|
62
|
+
Scanned PDFs and PDF pages with images or annotations also need local Tesseract
|
|
63
|
+
OCR and its Dutch (`nld`) and English (`eng`) language packs:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
# macOS
|
|
67
|
+
brew install tesseract tesseract-lang
|
|
68
|
+
|
|
69
|
+
# Ubuntu/Debian
|
|
70
|
+
sudo apt-get install tesseract-ocr tesseract-ocr-nld tesseract-ocr-eng
|
|
71
|
+
|
|
72
|
+
# Check which language packs are available
|
|
73
|
+
tesseract --list-langs
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
zypp anonymize report.pdf
|
|
78
|
+
# -> report.anonymized.pdf
|
|
79
|
+
|
|
80
|
+
zypp anonymize customers.xlsx
|
|
81
|
+
# -> customers.anonymized.xlsx
|
|
82
|
+
|
|
83
|
+
zypp anonymize ./client-files
|
|
84
|
+
# -> ./client-files.anonymized/ (recursive, with relative file paths preserved)
|
|
85
|
+
|
|
86
|
+
zypp anonymize report.pdf --language en
|
|
87
|
+
zypp anonymize ./client-files --output ./review-copy
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Dutch is the default. Processing uses local Presidio/spaCy/Tesseract engines;
|
|
91
|
+
client files are not sent to cloud services. Detected text is replaced with labels
|
|
92
|
+
such as `<PERSON>`, `<EMAIL_ADDRESS>` and `<NL_BSN>`. PDF detections are masked
|
|
93
|
+
with opaque black pixels.
|
|
94
|
+
|
|
95
|
+
| Format | Result |
|
|
96
|
+
| --- | --- |
|
|
97
|
+
| `.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. |
|
|
98
|
+
| `.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. |
|
|
99
|
+
| `.csv`, `.tsv` | Properly quoted UTF-8 data with cell-level replacements. CSV uses commas; TSV uses tabs. |
|
|
100
|
+
| `.txt`, `.md`, `.log` | UTF-8 text with entity-label replacements. |
|
|
101
|
+
| `.json`, `.jsonl` | Valid JSON with processed keys and values. Colliding or duplicate keys are rejected. |
|
|
102
|
+
|
|
103
|
+
Excel formulas use the results saved by Excel. If a formula has no saved result,
|
|
104
|
+
the workbook fails with an instruction to recalculate and save it in Excel.
|
|
105
|
+
Numeric identifiers are scanned too; matched numbers become replacement strings.
|
|
106
|
+
Unmatched values retain their types, and text leading zeroes are preserved.
|
|
107
|
+
Custom Excel display formats such as `000000000` are not retained. Excel drawings
|
|
108
|
+
and embedded objects are omitted with a warning, rather than processed as images.
|
|
109
|
+
|
|
110
|
+
Originals are preserved and existing destinations are refused. Symbolic links
|
|
111
|
+
are not followed. For folders, unsupported files are skipped and failed files
|
|
112
|
+
have no final output; completed files are retained. A skipped or failed file makes
|
|
113
|
+
the command exit with status `1` and report a partial run. Temporary files and new
|
|
114
|
+
output use owner-only permissions where supported.
|
|
115
|
+
|
|
116
|
+
**Review output before sharing.** Detection and OCR can miss personal data or
|
|
117
|
+
replace harmless text. Faces, signatures, indirect identifiers and every kind of
|
|
118
|
+
address or sensitive fact are not comprehensively detected. Filesystem names
|
|
119
|
+
remain unchanged and may themselves identify people. Legacy `.xls`, macro-enabled
|
|
120
|
+
Office files and password-protected PDFs are not supported.
|
|
121
|
+
|
|
122
|
+
For implementation details, see [the anonymize plan](plans/anonymize-plan.md).
|
|
123
|
+
|
|
124
|
+
### List Key Vaults
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
zypp keyvault list --subscription <subscription-id>
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Lists all accessible Key Vaults in the given Azure subscription.
|
|
131
|
+
|
|
132
|
+
To filter by name (case-insensitive substring match):
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
zypp keyvault list --subscription <subscription-id> --name dev
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### Load secrets from Azure Key Vault
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
eval $(zypp keyvault load --vault <vault-name>)
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
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`).
|
|
145
|
+
|
|
146
|
+
Without `eval`, the command only prints the export statements without setting them:
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
zypp keyvault load --vault <vault-name>
|
|
150
|
+
# Output:
|
|
151
|
+
# export DB_PASSWORD='...'
|
|
152
|
+
# export SQL_DB='...'
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Version
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
zypp --version
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## Development and checks
|
|
162
|
+
|
|
163
|
+
```bash
|
|
164
|
+
uv sync
|
|
165
|
+
uv run --no-sync zypp anonymize --setup
|
|
166
|
+
uv run --no-sync pytest
|
|
167
|
+
uv run --no-sync pytest -m integration
|
|
168
|
+
uvx prek run --all-files
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
The default suite tests file handling and document adapters without spaCy models
|
|
172
|
+
or Tesseract. Integration tests require both language models, Tesseract and its
|
|
173
|
+
`nld`/`eng` packs; they exercise real detection, scans, mixed PDFs and the CLI.
|
|
174
|
+
Use `--no-sync` after setup: an exact `uv sync` removes model packages that
|
|
175
|
+
are not in the project lockfile. Run setup again if needed. CI runs both suites.
|
zyppcli-0.3.0/README.md
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
# Zypp CLI
|
|
2
|
+
|
|
3
|
+
Internal CLI for Zypp: load secrets from Azure Key Vault and anonymize client files locally with Microsoft Presidio.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
uv tool install zyppcli
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
To upgrade to the latest version:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
uv tool install zyppcli --upgrade
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Key Vault prerequisites
|
|
18
|
+
|
|
19
|
+
You need to be authenticated with Azure:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
az login
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
### Anonymize PDF, Excel or text files
|
|
28
|
+
|
|
29
|
+
Install Zypp CLI normally, then download both local spaCy models once:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
uv tool install zyppcli
|
|
33
|
+
zypp anonymize --setup
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
To install from this checkout, use `uv tool install .` instead. To upgrade an
|
|
37
|
+
existing installation, use `uv tool install zyppcli --upgrade`. Setup installs the
|
|
38
|
+
Dutch and English models into the CLI's own environment, using uv when available
|
|
39
|
+
or pip otherwise. It can be run again safely. Downloading models requires network
|
|
40
|
+
access; anonymizing client files does not download anything.
|
|
41
|
+
|
|
42
|
+
Scanned PDFs and PDF pages with images or annotations also need local Tesseract
|
|
43
|
+
OCR and its Dutch (`nld`) and English (`eng`) language packs:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
# macOS
|
|
47
|
+
brew install tesseract tesseract-lang
|
|
48
|
+
|
|
49
|
+
# Ubuntu/Debian
|
|
50
|
+
sudo apt-get install tesseract-ocr tesseract-ocr-nld tesseract-ocr-eng
|
|
51
|
+
|
|
52
|
+
# Check which language packs are available
|
|
53
|
+
tesseract --list-langs
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
zypp anonymize report.pdf
|
|
58
|
+
# -> report.anonymized.pdf
|
|
59
|
+
|
|
60
|
+
zypp anonymize customers.xlsx
|
|
61
|
+
# -> customers.anonymized.xlsx
|
|
62
|
+
|
|
63
|
+
zypp anonymize ./client-files
|
|
64
|
+
# -> ./client-files.anonymized/ (recursive, with relative file paths preserved)
|
|
65
|
+
|
|
66
|
+
zypp anonymize report.pdf --language en
|
|
67
|
+
zypp anonymize ./client-files --output ./review-copy
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Dutch is the default. Processing uses local Presidio/spaCy/Tesseract engines;
|
|
71
|
+
client files are not sent to cloud services. Detected text is replaced with labels
|
|
72
|
+
such as `<PERSON>`, `<EMAIL_ADDRESS>` and `<NL_BSN>`. PDF detections are masked
|
|
73
|
+
with opaque black pixels.
|
|
74
|
+
|
|
75
|
+
| Format | Result |
|
|
76
|
+
| --- | --- |
|
|
77
|
+
| `.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. |
|
|
78
|
+
| `.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. |
|
|
79
|
+
| `.csv`, `.tsv` | Properly quoted UTF-8 data with cell-level replacements. CSV uses commas; TSV uses tabs. |
|
|
80
|
+
| `.txt`, `.md`, `.log` | UTF-8 text with entity-label replacements. |
|
|
81
|
+
| `.json`, `.jsonl` | Valid JSON with processed keys and values. Colliding or duplicate keys are rejected. |
|
|
82
|
+
|
|
83
|
+
Excel formulas use the results saved by Excel. If a formula has no saved result,
|
|
84
|
+
the workbook fails with an instruction to recalculate and save it in Excel.
|
|
85
|
+
Numeric identifiers are scanned too; matched numbers become replacement strings.
|
|
86
|
+
Unmatched values retain their types, and text leading zeroes are preserved.
|
|
87
|
+
Custom Excel display formats such as `000000000` are not retained. Excel drawings
|
|
88
|
+
and embedded objects are omitted with a warning, rather than processed as images.
|
|
89
|
+
|
|
90
|
+
Originals are preserved and existing destinations are refused. Symbolic links
|
|
91
|
+
are not followed. For folders, unsupported files are skipped and failed files
|
|
92
|
+
have no final output; completed files are retained. A skipped or failed file makes
|
|
93
|
+
the command exit with status `1` and report a partial run. Temporary files and new
|
|
94
|
+
output use owner-only permissions where supported.
|
|
95
|
+
|
|
96
|
+
**Review output before sharing.** Detection and OCR can miss personal data or
|
|
97
|
+
replace harmless text. Faces, signatures, indirect identifiers and every kind of
|
|
98
|
+
address or sensitive fact are not comprehensively detected. Filesystem names
|
|
99
|
+
remain unchanged and may themselves identify people. Legacy `.xls`, macro-enabled
|
|
100
|
+
Office files and password-protected PDFs are not supported.
|
|
101
|
+
|
|
102
|
+
For implementation details, see [the anonymize plan](plans/anonymize-plan.md).
|
|
103
|
+
|
|
104
|
+
### List Key Vaults
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
zypp keyvault list --subscription <subscription-id>
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Lists all accessible Key Vaults in the given Azure subscription.
|
|
111
|
+
|
|
112
|
+
To filter by name (case-insensitive substring match):
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
zypp keyvault list --subscription <subscription-id> --name dev
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Load secrets from Azure Key Vault
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
eval $(zypp keyvault load --vault <vault-name>)
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
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`).
|
|
125
|
+
|
|
126
|
+
Without `eval`, the command only prints the export statements without setting them:
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
zypp keyvault load --vault <vault-name>
|
|
130
|
+
# Output:
|
|
131
|
+
# export DB_PASSWORD='...'
|
|
132
|
+
# export SQL_DB='...'
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Version
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
zypp --version
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Development and checks
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
uv sync
|
|
145
|
+
uv run --no-sync zypp anonymize --setup
|
|
146
|
+
uv run --no-sync pytest
|
|
147
|
+
uv run --no-sync pytest -m integration
|
|
148
|
+
uvx prek run --all-files
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
The default suite tests file handling and document adapters without spaCy models
|
|
152
|
+
or Tesseract. Integration tests require both language models, Tesseract and its
|
|
153
|
+
`nld`/`eng` packs; they exercise real detection, scans, mixed PDFs and the CLI.
|
|
154
|
+
Use `--no-sync` after setup: an exact `uv sync` removes model packages that
|
|
155
|
+
are not in the project lockfile. Run setup again if needed. CI runs both suites.
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
# Presidio anonymize command — implementation plan
|
|
2
|
+
|
|
3
|
+
Status: implemented and locally verified, 25 November 2026.
|
|
4
|
+
|
|
5
|
+
## Goal and agreed scope
|
|
6
|
+
|
|
7
|
+
Add `zypp anonymize <file-or-folder>` as a small local wrapper around Microsoft
|
|
8
|
+
Presidio. Most client inputs are PDF and Excel, so these are first-class v1
|
|
9
|
+
formats. Cover common cases effectively; avoid building a separate detection
|
|
10
|
+
framework or document-conversion service.
|
|
11
|
+
|
|
12
|
+
Agreed decisions:
|
|
13
|
+
|
|
14
|
+
- Accept files and recursively process folders; write separate anonymized copies.
|
|
15
|
+
- Support PDFs containing text, scanned pages and embedded images in v1.
|
|
16
|
+
- Excel output is values only. Preserving formulas is outside v1.
|
|
17
|
+
- Dutch by default, with explicit English support.
|
|
18
|
+
- Reuse Presidio's analyzer, anonymizer, batch and image engines.
|
|
19
|
+
- Work locally, without sending client files to an external OCR or AI service.
|
|
20
|
+
- Include anonymization dependencies in the normal installation. Use
|
|
21
|
+
`zypp anonymize --setup` once to install both language models. Keep imports lazy
|
|
22
|
+
so ordinary CLI help does not initialize Presidio.
|
|
23
|
+
|
|
24
|
+
The security context is data minimization for development, debugging and AI use.
|
|
25
|
+
Automated de-identification
|
|
26
|
+
can miss personal data; generated files still need review before sharing.
|
|
27
|
+
|
|
28
|
+
## Research and reuse decisions
|
|
29
|
+
|
|
30
|
+
1. [Presidio PDF annotation sample](https://presidio.dataprivacystack.org/samples/python/example_pdf_annotation/)
|
|
31
|
+
demonstrates extracting paragraphs and character coordinates with pdfminer.six,
|
|
32
|
+
analyzing their text, and mapping detections to page rectangles. It produces
|
|
33
|
+
highlight annotations, not content removal. Reuse the detection/location
|
|
34
|
+
approach, not its highlight output or its assumption that annotations belong on
|
|
35
|
+
the first page.
|
|
36
|
+
2. [DICOM image sample](https://presidio.dataprivacystack.org/samples/python/example_dicom_image_redactor/)
|
|
37
|
+
demonstrates pixel redaction and directory handling for medical images. Ordinary
|
|
38
|
+
PDF pages should use the generic
|
|
39
|
+
[ImageRedactorEngine](https://presidio.dataprivacystack.org/image-redactor/),
|
|
40
|
+
not DicomImageRedactorEngine. Presidio handles OCR, text recognition, mapping
|
|
41
|
+
detections to pixels and masking. Tesseract is a local prerequisite. The image
|
|
42
|
+
package is documented as beta; exercise it on synthetic representative pages.
|
|
43
|
+
3. [Presidio batch processing](https://presidio.dataprivacystack.org/samples/python/batch_processing/)
|
|
44
|
+
already supports DataFrame-to-dictionary analysis and anonymization through
|
|
45
|
+
BatchAnalyzerEngine and BatchAnonymizerEngine. Use these for Excel/CSV cells.
|
|
46
|
+
[Presidio Structured](https://presidio.dataprivacystack.org/structured/) instead
|
|
47
|
+
infers column/key entity mappings; defer column-wide inference because client
|
|
48
|
+
workbooks can contain mixed free text, titles and irregular tables.
|
|
49
|
+
4. [The old Zypp anonymizer](https://github.com/zypp-io/anonymizer/blob/main/anonymizer/converter.py)
|
|
50
|
+
copies a DataFrame and replaces unique values in explicitly mapped columns
|
|
51
|
+
using Faker. Its README, converter and tests contain no Excel reader/writer.
|
|
52
|
+
Retain the non-destructive approach; do not depend on the package or port its
|
|
53
|
+
Faker mappings/generalization features. Consistent fake identities can be a
|
|
54
|
+
later feature if a real use case needs them.
|
|
55
|
+
5. Follow [Zypp's Python/uv conventions](https://github.com/zypp-io/zypp-knowledge-base/blob/main/concepts/tech-stack-overview.md).
|
|
56
|
+
The [credential-hygiene guidance](https://github.com/zypp-io/zypp-knowledge-base/blob/main/concepts/credential-hygiene.md)
|
|
57
|
+
provides existing CLI context, but is not a personal-data detection standard.
|
|
58
|
+
|
|
59
|
+
## CLI contract
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
zypp anonymize report.pdf
|
|
63
|
+
# -> report.anonymized.pdf
|
|
64
|
+
|
|
65
|
+
zypp anonymize customers.xlsx
|
|
66
|
+
# -> customers.anonymized.xlsx
|
|
67
|
+
|
|
68
|
+
zypp anonymize ./client-files
|
|
69
|
+
# -> ./client-files.anonymized/ with relative file paths preserved
|
|
70
|
+
|
|
71
|
+
zypp anonymize ./client-files --output ./review-copy --language nl
|
|
72
|
+
zypp anonymize report.pdf --language en
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
- Positional `path`; optional `-o/--output`; `--language {nl,en}`, default `nl`.
|
|
76
|
+
- Initially support `.pdf`, `.xlsx`, `.csv`, `.tsv`, `.txt`, `.md`, `.log`,
|
|
77
|
+
`.json` and `.jsonl`. Do not add separate image/DICOM commands in v1.
|
|
78
|
+
- Refuse an existing destination, source/destination overlap and symbolic links.
|
|
79
|
+
Do not follow directory symlinks. Do not allow output inside the source tree.
|
|
80
|
+
- For a folder, process supported regular files sequentially. Report unsupported
|
|
81
|
+
files as skipped, without copying their originals. Return nonzero if any file
|
|
82
|
+
was skipped or failed; retain completed outputs and identify the run as partial.
|
|
83
|
+
- Publish each output only after that file is complete. Remove that file's
|
|
84
|
+
temporary output on failure; never leave a half-written final file.
|
|
85
|
+
- Show file counts and safe error categories, not cell text, OCR results or entity
|
|
86
|
+
values. File paths may themselves identify people; avoid unnecessary logging.
|
|
87
|
+
- Filesystem names remain unchanged except for the output suffix. Tell users to
|
|
88
|
+
review names before sharing. Use neutral `Sheet1`, `Sheet2`, etc. for Excel
|
|
89
|
+
output tabs so original tab names cannot carry personal data into the copy.
|
|
90
|
+
- Use owner-only permissions for newly created temporary/output files and folders
|
|
91
|
+
where supported. Clean up temporary material on success and ordinary failure.
|
|
92
|
+
|
|
93
|
+
## Shared Presidio setup
|
|
94
|
+
|
|
95
|
+
Construct one AnalyzerEngine per invocation, using an explicitly installed spaCy
|
|
96
|
+
model: `nl_core_news_lg` for Dutch or `en_core_web_lg` for English. Reuse it in the
|
|
97
|
+
text, batch and image engines. Check dependencies and selected model before
|
|
98
|
+
processing; report installation instructions instead of triggering model downloads
|
|
99
|
+
while handling client data. There is no language auto-detection in v1.
|
|
100
|
+
|
|
101
|
+
Use Presidio's default entity-label replacement, such as `<PERSON>` or
|
|
102
|
+
`<EMAIL_ADDRESS>`, for text/tabular values and opaque black fills for PDF pixels.
|
|
103
|
+
No Faker, reversible mapping, custom operator framework or remote recognizers.
|
|
104
|
+
Use the bundled public-suffix snapshot for email validation rather than fetching
|
|
105
|
+
suffix lists during anonymization.
|
|
106
|
+
|
|
107
|
+
Check the installed version's actual Dutch recognizer registrations. Enable the
|
|
108
|
+
existing generic email, IBAN, credit-card and phone recognizers for Dutch as needed;
|
|
109
|
+
include Dutch national phone-number handling. Verify BSN support: if absent, add
|
|
110
|
+
one small PatternRecognizer with a nine-digit pattern and eleven-test checksum.
|
|
111
|
+
Test that addition independently. Do not claim arbitrary addresses, health facts,
|
|
112
|
+
faces, signatures or indirect identifiers are comprehensively detected.
|
|
113
|
+
|
|
114
|
+
## Excel and CSV adapter
|
|
115
|
+
|
|
116
|
+
Keep this as workbook I/O plus Presidio batch calls, not a spreadsheet editor.
|
|
117
|
+
|
|
118
|
+
1. Read `.xlsx` cell values with openpyxl `data_only=True`, including every
|
|
119
|
+
worksheet and hidden row/column. Use a second read with `data_only=False` only
|
|
120
|
+
to detect formulas without cached results. Do not calculate formulas. If a
|
|
121
|
+
formula has no saved result, fail that workbook with an instruction to open,
|
|
122
|
+
recalculate and save it in Excel; do not silently turn it into a blank.
|
|
123
|
+
2. Represent each sheet as a pandas DataFrame with positional integer columns.
|
|
124
|
+
Treat all rows as data (`header=None`), including titles and column headings.
|
|
125
|
+
This avoids duplicate-header loss and scans identifying information in headers.
|
|
126
|
+
3. Feed column lists through BatchAnalyzerEngine / BatchAnonymizerEngine. Supply
|
|
127
|
+
a normal header as optional context only when available; do not require a schema.
|
|
128
|
+
Adapt nulls and scalar types explicitly. Scan textual representations of numeric
|
|
129
|
+
identifiers too; preserve original number/bool/date values when no match occurs.
|
|
130
|
+
Matched numeric identifiers become replacement strings. Preserve text leading
|
|
131
|
+
zeroes; custom Excel display formats such as `000000000` are not preserved in v1.
|
|
132
|
+
4. Build a new workbook using openpyxl. Write only processed scalar values at
|
|
133
|
+
their original row/column positions, with neutral sequential tab names and all
|
|
134
|
+
sheets visible for review. Force string values to remain literal strings,
|
|
135
|
+
including values beginning with `=`, so output does not introduce formulas.
|
|
136
|
+
5. Do not copy formulas, original properties, comments, hyperlinks, defined names,
|
|
137
|
+
drawings, embedded objects, charts or workbook relationships. Do not promise
|
|
138
|
+
original formatting, merged cells or a functioning calculation model.
|
|
139
|
+
6. If the source contains Excel drawings/embedded objects, include an explicit
|
|
140
|
+
warning that these are omitted, not anonymized. Image handling inside Excel is
|
|
141
|
+
outside v1; the output remains a values-only copy.
|
|
142
|
+
7. CSV/TSV use the same batch processing with fixed comma/tab delimiters. Preserve
|
|
143
|
+
row order and cells as strings to avoid unwanted inference or leading-zero loss.
|
|
144
|
+
Write properly quoted UTF-8 output. Regional semicolon CSV can be added later.
|
|
145
|
+
|
|
146
|
+
The cached-value limitation follows
|
|
147
|
+
[openpyxl's data_only behavior](https://openpyxl.readthedocs.io/en/stable/api/openpyxl.reader.excel.html).
|
|
148
|
+
|
|
149
|
+
## PDF adapter, including scans and images
|
|
150
|
+
|
|
151
|
+
**Output decision, revised after user feedback:** preserve unaffected selectable
|
|
152
|
+
native text, including text on pages which also contain images. Scanned pages
|
|
153
|
+
remain scans. Detection of image content still uses Presidio OCR; it does not
|
|
154
|
+
require converting every output page into an image-only PDF.
|
|
155
|
+
|
|
156
|
+
Use PyMuPDF for native character coordinates, page rendering and applied PDF
|
|
157
|
+
redactions, and Pillow for passing rendered pages to Presidio. Presidio remains
|
|
158
|
+
responsible for detection. pdfminer.six and pypdfium2 are independent test tools.
|
|
159
|
+
|
|
160
|
+
1. Reject encrypted or empty PDFs. Bake visible annotations/widgets into page
|
|
161
|
+
content, then scrub attachments, scripts, hidden OCR text, links and metadata.
|
|
162
|
+
2. Extract native characters and coordinates from each page's raw text dictionary.
|
|
163
|
+
Build analyzed text and its coordinate map together, including line-break
|
|
164
|
+
placeholders. Group matched character boxes per line.
|
|
165
|
+
3. For pages containing images or no usable native text, render the visible page
|
|
166
|
+
at 300 DPI and run ImageRedactorEngine with the shared AnalyzerEngine. Use
|
|
167
|
+
`language="nl"` / `"en"` for detection and `ocr_kwargs={"lang": "nld+eng"}` /
|
|
168
|
+
`{"lang": "eng"}` for Tesseract. Check OCR prerequisites before use.
|
|
169
|
+
4. Convert OCR pixel boxes back to unrotated page coordinates, accounting for
|
|
170
|
+
crop/rotation. Combine them with native-text detections.
|
|
171
|
+
5. Add redaction annotations and immediately apply them with character deletion
|
|
172
|
+
and overlapping image-pixel blanking. Preserve unaffected native text and vector
|
|
173
|
+
content. Merely drawing rectangles or leaving unapplied annotations is insufficient.
|
|
174
|
+
6. Copy processed pages into a fresh PDF without links, annotations or widgets.
|
|
175
|
+
Save non-incrementally with cleanup, compression and full garbage collection,
|
|
176
|
+
discarding obsolete text/image streams. Do not copy source document metadata.
|
|
177
|
+
7. Verify extraction retains harmless native text and omits detected values.
|
|
178
|
+
Inspect rendered pages and extracted image objects to verify masked pixels and
|
|
179
|
+
ensure obsolete, unredacted images are not retained.
|
|
180
|
+
|
|
181
|
+
No new OCR text layer is generated for scans. Searchable OCR-only output may be a
|
|
182
|
+
later option. An OCR engine returning no text does not prove that a page contains
|
|
183
|
+
no identifying information; warn that such pages require review.
|
|
184
|
+
|
|
185
|
+
## Text and JSON adapters
|
|
186
|
+
|
|
187
|
+
- Read plain text as UTF-8 (allow a UTF-8 BOM), then call the shared text engines.
|
|
188
|
+
- Parse JSON/JSONL before processing, reuse the batch dictionary APIs where they
|
|
189
|
+
fit, and serialize valid output. JSON keys need a separate text pass because
|
|
190
|
+
dictionary keys are otherwise used as context rather than anonymized. Reject
|
|
191
|
+
collisions caused by key replacement instead of silently dropping data.
|
|
192
|
+
- Preserve nonmatched primitives, arrays and nesting; reject invalid encoding,
|
|
193
|
+
invalid JSON and NUL-containing binary content.
|
|
194
|
+
|
|
195
|
+
## Dependencies and code changes
|
|
196
|
+
|
|
197
|
+
Include Presidio analyzer, anonymizer and image-redactor, pandas, openpyxl,
|
|
198
|
+
PyMuPDF and Pillow in the normal dependencies. Pin spaCy to the 3.8 series used by
|
|
199
|
+
the model wheels. Keep pdfminer.six, pypdfium2 and reportlab as test dependencies.
|
|
200
|
+
Do not add presidio-structured or Faker. Keep imports lazy.
|
|
201
|
+
|
|
202
|
+
PyPI does not accept external-wheel URL dependencies. Instead, provide
|
|
203
|
+
`zypp anonymize --setup` to install both official spaCy 3.8.0 model wheels into the
|
|
204
|
+
CLI environment, using uv or pip with `--no-deps`. It skips already installed
|
|
205
|
+
models and reports download failures. File processing never downloads models; a
|
|
206
|
+
missing model produces a setup hint before reading file contents. Tesseract and
|
|
207
|
+
its language packs remain system prerequisites, with installation instructions.
|
|
208
|
+
|
|
209
|
+
Keep the implementation in a command module plus a small format-helper package:
|
|
210
|
+
|
|
211
|
+
```text
|
|
212
|
+
zyppcli/commands/anonymize.py # argparse, traversal, dispatch, output/errors
|
|
213
|
+
zyppcli/anonymization/text.py # shared Presidio initialization and text/JSON
|
|
214
|
+
zyppcli/anonymization/tabular.py # Excel/CSV file I/O and batch calls
|
|
215
|
+
zyppcli/anonymization/pdf.py # native coordinates, page rendering and image engine
|
|
216
|
+
tests/ # synthetic fixtures and focused behavior tests
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
Register the command in `zyppcli/__main__.py`, update README installation/usage and
|
|
220
|
+
limitations, and add the tests to CI. Do not introduce an adapter/plugin framework,
|
|
221
|
+
background service, parallel workers or config file for v1.
|
|
222
|
+
|
|
223
|
+
## Implementation sequence and acceptance checks
|
|
224
|
+
|
|
225
|
+
1. Reconcile the existing untested draft command and optional dependencies with
|
|
226
|
+
this plan. Preserve the existing Key Vault behavior. Add command registration,
|
|
227
|
+
traversal, no-overwrite rules and per-file temporary output handling.
|
|
228
|
+
2. Implement shared Dutch/English engines and the Excel/CSV adapter. Verify two
|
|
229
|
+
sheets, headers, hidden data, mixed text, numeric identifiers, blanks, leading
|
|
230
|
+
zeroes, cached formulas, missing caches and literal formula-like strings. Reopen
|
|
231
|
+
the output and assert no formula cells, comments, hyperlinks or copied metadata.
|
|
232
|
+
3. Implement native PDF redaction while preserving unaffected selectable text. Then wire in
|
|
233
|
+
ImageRedactorEngine for scanned and mixed pages. Test multiple pages, repeated
|
|
234
|
+
entities, line breaks, rotation and crop boxes. Include a PDF with accurate
|
|
235
|
+
native text and an additional image containing a synthetic email address.
|
|
236
|
+
4. Add text/JSON handling through the same engines. Test JSON-key collisions and
|
|
237
|
+
malformed inputs. Test unsupported files, symlinks, repeated runs and partial
|
|
238
|
+
folder results. Inject a handler failure to verify final outputs stay complete.
|
|
239
|
+
5. Run pytest and the repository's formatting/pre-commit checks. Use test doubles
|
|
240
|
+
for routine I/O tests, plus real installed spaCy/Tesseract integration checks on
|
|
241
|
+
a small synthetic Dutch/English fixture set. Add a dedicated CI integration job
|
|
242
|
+
with the models and OCR packs; distinguish it from lightweight unit tests.
|
|
243
|
+
6. Render final PDF fixtures and inspect their appearance. Extract text and inspect
|
|
244
|
+
objects to verify detected text and obsolete image data were removed, while
|
|
245
|
+
harmless native text remains selectable and attachments/metadata are absent. Re-OCR known redacted regions and check the expected synthetic values
|
|
246
|
+
are absent; an empty text extraction alone cannot validate pixel redaction.
|
|
247
|
+
7. Check a single PDF, a single workbook and a mixed folder through the actual CLI.
|
|
248
|
+
Original hashes must remain unchanged; existing output must never be replaced;
|
|
249
|
+
failed files must have no final output; partial runs must return nonzero.
|
|
250
|
+
8. Document the setup and practical losses explicitly: values-only workbooks,
|
|
251
|
+
native-text preservation and scanned-page OCR, detection misses, unchanged filesystem names and required
|
|
252
|
+
human review. Leave unrelated security policies and KB pages unchanged.
|
|
253
|
+
|
|
254
|
+
## Outside v1
|
|
255
|
+
|
|
256
|
+
Legacy `.xls`, `.xlsb`, macro-enabled Office files, Word/PowerPoint, Parquet,
|
|
257
|
+
standalone images/DICOM, cloud OCR, automatic language detection, face/signature
|
|
258
|
+
recognition, formula recalculation, consistent fake identities, reversible
|
|
259
|
+
pseudonyms, and perfect visual/structural preservation of every document variant.
|
|
260
|
+
|
|
261
|
+
## Verification result
|
|
262
|
+
|
|
263
|
+
Implemented following user approval. Local checks passed: 42 focused tests and
|
|
264
|
+
10 real Dutch/English integration tests, Ruff and pre-commit checks, lockfile
|
|
265
|
+
validation, and source/wheel builds. Visually inspected native, scanned and mixed
|
|
266
|
+
PDF outputs. Rotation/crop, formula-cache, hidden-cell, failure-cleanup and
|
|
267
|
+
no-overwrite cases are covered. CI jobs have been added but have not run remotely.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "zyppcli"
|
|
7
|
+
version = "0.3.0"
|
|
8
|
+
description = "Internal CLI for Zypp"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.12"
|
|
11
|
+
dependencies = [
|
|
12
|
+
"azure-identity>=1.17.0",
|
|
13
|
+
"azure-keyvault-secrets>=4.8.0",
|
|
14
|
+
"azure-mgmt-keyvault>=10.0.0",
|
|
15
|
+
"certifi>=2026.10.18",
|
|
16
|
+
"openpyxl>=3.1.5",
|
|
17
|
+
"pandas>=3.1.1",
|
|
18
|
+
"pillow>=13.0.0",
|
|
19
|
+
"presidio-analyzer>=2.2.360,<3",
|
|
20
|
+
"presidio-anonymizer>=2.2.360,<3",
|
|
21
|
+
"presidio-image-redactor>=0.0.62",
|
|
22
|
+
"pymupdf>=1.26.0,<2",
|
|
23
|
+
"spacy>=3.8,<3.9",
|
|
24
|
+
"tldextract>=5.4.0",
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
[project.scripts]
|
|
28
|
+
zypp = "zyppcli.__main__:main"
|
|
29
|
+
|
|
30
|
+
[dependency-groups]
|
|
31
|
+
dev = [
|
|
32
|
+
"pdfminer-six>=20260107",
|
|
33
|
+
"pypdfium2>=5.15.2",
|
|
34
|
+
"pytest>=9.2.0",
|
|
35
|
+
"reportlab>=5.1.1",
|
|
36
|
+
"ruff>=0.17.6",
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
[tool.ruff]
|
|
40
|
+
line-length = 120
|
|
41
|
+
|
|
42
|
+
[tool.pytest.ini_options]
|
|
43
|
+
addopts = "-m 'not integration'"
|
|
44
|
+
markers = ["integration: real local spaCy and Tesseract checks (requires installed language models)"]
|