piiscope 1.1.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.
Files changed (54) hide show
  1. piiscope-1.1.0/.gitignore +78 -0
  2. piiscope-1.1.0/LICENSE +202 -0
  3. piiscope-1.1.0/PKG-INFO +297 -0
  4. piiscope-1.1.0/README.md +238 -0
  5. piiscope-1.1.0/piiscope/__init__.py +43 -0
  6. piiscope-1.1.0/piiscope/cli.py +649 -0
  7. piiscope-1.1.0/piiscope/detection/__init__.py +27 -0
  8. piiscope-1.1.0/piiscope/detection/classifier.py +324 -0
  9. piiscope-1.1.0/piiscope/detection/data/README.md +33 -0
  10. piiscope-1.1.0/piiscope/detection/data/drug_names.txt +9920 -0
  11. piiscope-1.1.0/piiscope/detection/data/given_names.txt +9785 -0
  12. piiscope-1.1.0/piiscope/detection/data/hospital_keywords.txt +22 -0
  13. piiscope-1.1.0/piiscope/detection/data/medical_terms.txt +146 -0
  14. piiscope-1.1.0/piiscope/detection/data/surnames.txt +24975 -0
  15. piiscope-1.1.0/piiscope/detection/dictionaries.py +70 -0
  16. piiscope-1.1.0/piiscope/detection/engine.py +761 -0
  17. piiscope-1.1.0/piiscope/detection/jurisdictions/__init__.py +100 -0
  18. piiscope-1.1.0/piiscope/detection/jurisdictions/ccpa.py +370 -0
  19. piiscope-1.1.0/piiscope/detection/jurisdictions/gdpr.py +382 -0
  20. piiscope-1.1.0/piiscope/detection/jurisdictions/kvkk.py +402 -0
  21. piiscope-1.1.0/piiscope/detection/jurisdictions/lgpd.py +407 -0
  22. piiscope-1.1.0/piiscope/detection/regex_patterns.py +387 -0
  23. piiscope-1.1.0/piiscope/detection/validators.py +388 -0
  24. piiscope-1.1.0/piiscope/errors.py +23 -0
  25. piiscope-1.1.0/piiscope/io/__init__.py +17 -0
  26. piiscope-1.1.0/piiscope/io/readers.py +234 -0
  27. piiscope-1.1.0/piiscope/metrics/__init__.py +31 -0
  28. piiscope-1.1.0/piiscope/metrics/metrics.py +563 -0
  29. piiscope-1.1.0/piiscope/metrics/risk_scorer.py +334 -0
  30. piiscope-1.1.0/piiscope/remediation/__init__.py +29 -0
  31. piiscope-1.1.0/piiscope/remediation/masking.py +74 -0
  32. piiscope-1.1.0/piiscope/remediation/strategies.py +243 -0
  33. piiscope-1.1.0/piiscope/report/__init__.py +5 -0
  34. piiscope-1.1.0/piiscope/report/renderers.py +193 -0
  35. piiscope-1.1.0/piiscope/scan.py +478 -0
  36. piiscope-1.1.0/pyproject.toml +103 -0
  37. piiscope-1.1.0/samples/customers.csv +41 -0
  38. piiscope-1.1.0/samples/medical_notes.csv +5 -0
  39. piiscope-1.1.0/samples/support_tickets.jsonl +15 -0
  40. piiscope-1.1.0/tests/__init__.py +1 -0
  41. piiscope-1.1.0/tests/sample_scan_script.py +115 -0
  42. piiscope-1.1.0/tests/test_cli.py +294 -0
  43. piiscope-1.1.0/tests/test_detection.py +643 -0
  44. piiscope-1.1.0/tests/test_dictionaries.py +110 -0
  45. piiscope-1.1.0/tests/test_dictionary_quality.py +363 -0
  46. piiscope-1.1.0/tests/test_dominance.py +19 -0
  47. piiscope-1.1.0/tests/test_io.py +152 -0
  48. piiscope-1.1.0/tests/test_jurisdiction_coverage.py +30 -0
  49. piiscope-1.1.0/tests/test_jurisdictions.py +112 -0
  50. piiscope-1.1.0/tests/test_metrics.py +46 -0
  51. piiscope-1.1.0/tests/test_precision_guard.py +17 -0
  52. piiscope-1.1.0/tests/test_remediation_roundtrip.py +141 -0
  53. piiscope-1.1.0/tests/test_server_startup.py +122 -0
  54. piiscope-1.1.0/tests/test_validators.py +38 -0
@@ -0,0 +1,78 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.so
6
+ *.egg
7
+ *.egg-info/
8
+ dist/
9
+ build/
10
+ .eggs/
11
+ .Python
12
+ .venv/
13
+ venv/
14
+ env/
15
+ ENV/
16
+ pip-log.txt
17
+ pip-delete-this-directory.txt
18
+ .tox/
19
+ .cache
20
+ .pytest_cache/
21
+ .mypy_cache/
22
+ .ruff_cache/
23
+ htmlcov/
24
+ .coverage
25
+ .coverage.*
26
+ coverage.xml
27
+ *.cover
28
+ nosetests.xml
29
+
30
+ # Virtual environments
31
+ .env
32
+ .env.*
33
+ !.env.example
34
+
35
+ # Secrets / credentials
36
+ *.pem
37
+ *.key
38
+ *.p12
39
+ service_account*.json
40
+
41
+ # Database files
42
+ *.db
43
+ *.sqlite
44
+ *.sqlite3
45
+
46
+ # Uploads / exports / reports (runtime data)
47
+ api/uploads/
48
+ api/exports/
49
+ api/reports/
50
+
51
+ # Node / frontend
52
+ node_modules/
53
+ app/node_modules/
54
+ npm-debug.log*
55
+ yarn-debug.log*
56
+ yarn-error.log*
57
+ .pnp/
58
+ .pnp.js
59
+ .npm/
60
+ dist/
61
+ build/
62
+
63
+ # IDE / editor
64
+ .idea/
65
+ .vscode/
66
+ *.swp
67
+ *.swo
68
+ *~
69
+ .DS_Store
70
+ Thumbs.db
71
+
72
+ # Celery
73
+ celerybeat-schedule
74
+ celerybeat.pid
75
+
76
+ # Logs
77
+ *.log
78
+ logs/
piiscope-1.1.0/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
202
+
@@ -0,0 +1,297 @@
1
+ Metadata-Version: 2.5
2
+ Name: piiscope
3
+ Version: 1.1.0
4
+ Summary: Find, score and remediate personal data in your files and databases.
5
+ Project-URL: Homepage, https://github.com/barissozudogru/piiscope
6
+ Project-URL: Repository, https://github.com/barissozudogru/piiscope
7
+ Project-URL: Issues, https://github.com/barissozudogru/piiscope/issues
8
+ Author: Baris Sozudogru
9
+ License: Apache-2.0
10
+ License-File: LICENSE
11
+ Keywords: ccpa,data-protection,dpia,gdpr,k-anonymity,kvkk,lgpd,pii,privacy
12
+ Classifier: Development Status :: 5 - Production/Stable
13
+ Classifier: Environment :: Console
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Intended Audience :: Information Technology
16
+ Classifier: License :: OSI Approved :: Apache Software License
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Programming Language :: Python :: 3.13
23
+ Classifier: Topic :: Database
24
+ Classifier: Topic :: Security
25
+ Classifier: Typing :: Typed
26
+ Requires-Python: >=3.10
27
+ Requires-Dist: numpy>=1.24
28
+ Requires-Dist: pandas>=2.0
29
+ Requires-Dist: python-dateutil>=2.8
30
+ Requires-Dist: rich>=13.0
31
+ Requires-Dist: typer>=0.12
32
+ Provides-Extra: dev
33
+ Requires-Dist: pyarrow>=17; extra == 'dev'
34
+ Requires-Dist: pytest-cov>=5.0; extra == 'dev'
35
+ Requires-Dist: pytest>=8.0; extra == 'dev'
36
+ Requires-Dist: ruff>=0.5; extra == 'dev'
37
+ Provides-Extra: nlp
38
+ Requires-Dist: spacy>=3.7; extra == 'nlp'
39
+ Provides-Extra: parquet
40
+ Requires-Dist: pyarrow>=17; extra == 'parquet'
41
+ Provides-Extra: server
42
+ Requires-Dist: bcrypt>=4.0; extra == 'server'
43
+ Requires-Dist: celery>=5.3; extra == 'server'
44
+ Requires-Dist: cryptography>=44; extra == 'server'
45
+ Requires-Dist: email-validator>=2.0; extra == 'server'
46
+ Requires-Dist: fastapi>=0.118; extra == 'server'
47
+ Requires-Dist: jinja2>=3.1.6; extra == 'server'
48
+ Requires-Dist: psycopg2-binary>=2.9; extra == 'server'
49
+ Requires-Dist: pydantic-settings>=2.2; extra == 'server'
50
+ Requires-Dist: pydantic>=2.6; extra == 'server'
51
+ Requires-Dist: python-jose[cryptography]>=3.4; extra == 'server'
52
+ Requires-Dist: python-multipart>=0.0.31; extra == 'server'
53
+ Requires-Dist: redis>=5.0; extra == 'server'
54
+ Requires-Dist: spacy>=3.7; extra == 'server'
55
+ Requires-Dist: sqlalchemy>=2.0; extra == 'server'
56
+ Requires-Dist: uvicorn[standard]>=0.29; extra == 'server'
57
+ Requires-Dist: weasyprint>=62; extra == 'server'
58
+ Description-Content-Type: text/markdown
59
+
60
+ # piiscope
61
+ Find, score and remediate personal data in your files and databases.
62
+
63
+ [![CI](https://github.com/barissozudogru/piiscope/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/barissozudogru/piiscope/actions/workflows/ci.yml)
64
+ ![PyPI Version](https://img.shields.io/pypi/v/piiscope)
65
+ ![Python Versions](https://img.shields.io/pypi/pyversions/piiscope)
66
+ ![License](https://img.shields.io/badge/License-Apache--2.0-blue.svg)
67
+
68
+ ![piiscope demo](https://raw.githubusercontent.com/barissozudogru/piiscope/main/docs/assets/demo.gif)
69
+
70
+ ## What it does
71
+ piiscope finds personal data in your datasets and measures privacy risks across global jurisdictions. It scans tabular data or free text to locate direct identifiers and calculate k-anonymity, l-diversity and t-closeness on quasi-identifiers. It helps you remediate findings by applying strategies like hashing, generalisation or tokenisation directly to the target columns.
72
+
73
+ ## Install
74
+ ```bash
75
+ pip install piiscope
76
+ ```
77
+ For reading Parquet files:
78
+ ```bash
79
+ pip install "piiscope[parquet]"
80
+ ```
81
+ For spaCy-based natural language processing:
82
+ ```bash
83
+ pip install "piiscope[nlp]"
84
+ ```
85
+
86
+ ## Quickstart
87
+ Scan a file to identify privacy risks:
88
+ ```bash
89
+ piiscope scan samples/customers.csv
90
+ ```
91
+ ```text
92
+ ╭─ piiscope scan ──────────────────────────────────────────────────────────────────────────────────╮
93
+ │ Source samples/customers.csv │
94
+ │ Rows 40 │
95
+ │ Columns 13 │
96
+ │ Scan time 0.06s │
97
+ │ Jurisdictions gdpr, ccpa, kvkk, lgpd │
98
+ ╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
99
+ Findings
100
+ ┏━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┳━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓
101
+ ┃ Column ┃ Category ┃ Detector ┃ Hits ┃ Confidence ┃ Jurisdictions ┃
102
+ ┡━━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━╇━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━┩
103
+ │ ssn │ national_id │ us_ssn │ 10 │ 0.85 │ GDPR, CCPA, KVKK, LGPD │
104
+ │ tckn │ national_id │ tc_kimlik │ 10 │ 1.00 │ GDPR, KVKK │
105
+ │ notes │ health │ medical_condition │ 7 │ 0.70 │ GDPR, CCPA, KVKK, LGPD │
106
+ │ notes │ health │ drug_name │ 6 │ 0.70 │ GDPR, CCPA, KVKK, LGPD │
107
+ │ notes │ health │ hospital_name │ 4 │ 0.70 │ GDPR, CCPA, KVKK, LGPD │
108
+ │ credit_card │ financial │ credit_card │ 40 │ 1.00 │ GDPR, CCPA, KVKK, LGPD │
109
+ │ iban │ financial │ iban_tr │ 10 │ 1.00 │ GDPR, CCPA, KVKK, LGPD │
110
+ │ iban │ financial │ iban │ 40 │ 1.00 │ GDPR, CCPA, KVKK, LGPD │
111
+ │ phone │ contact │ tr_phone │ 24 │ 1.00 │ GDPR, KVKK, LGPD │
112
+ │ phone │ contact │ us_phone │ 16 │ 1.00 │ GDPR, CCPA, KVKK, LGPD │
113
+ │ phone │ contact │ eu_phone │ 2 │ 1.00 │ GDPR, CCPA, KVKK, LGPD │
114
+ │ email │ contact │ email │ 40 │ 1.00 │ GDPR, CCPA, KVKK, LGPD │
115
+ │ name │ name │ given_name │ 40 │ 0.84 │ GDPR, CCPA, KVKK, LGPD │
116
+ │ name │ name │ surname │ 40 │ 0.84 │ GDPR, CCPA, KVKK, LGPD │
117
+ │ notes │ name │ given_name │ 1 │ 0.60 │ GDPR, CCPA, KVKK, LGPD │
118
+ │ birth_date │ demographic │ date │ 40 │ 1.00 │ GDPR, CCPA, KVKK, LGPD │
119
+ └─────────────┴─────────────┴───────────────────┴──────┴────────────┴────────────────────────┘
120
+ ╭─ Privacy metrics ────────────────────────────────────────────────────────────────────────────────╮
121
+ │ Quasi identifiers birth_date, city, country │
122
+ │ Sensitive attribute notes │
123
+ │ k-anonymity 1 │
124
+ │ l-diversity 1 │
125
+ │ t-closeness 0.975 │
126
+ ╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
127
+ ╭─ Risk ───────────────────────────────────────────────────────────────────────────────────────────╮
128
+ │ Score 100/100 │
129
+ │ Level CRITICAL │
130
+ │ Driver 1 tckn: tc_kimlik (national_id, 10 values, confidence 1.00) │
131
+ │ Driver 2 ssn: us_ssn (national_id, 10 values, confidence 0.85) │
132
+ │ Driver 3 credit_card: credit_card (financial, 40 values, confidence 1.00) │
133
+ ╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
134
+ Next: piiscope remediate samples/customers.csv --out samples/customers_safe.csv --strategy hash
135
+ ```
136
+
137
+ Remediate the file, then prove the output is clean:
138
+ ```bash
139
+ piiscope remediate samples/customers.csv --out customers_safe.csv --strategy hash
140
+ piiscope scan customers_safe.csv
141
+ ```
142
+ ```text
143
+ Remediated samples/customers.csv -> customers_safe.csv (strategy: hash, rows: 40)
144
+ ┏━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┓
145
+ ┃ Column ┃ Values changed ┃
146
+ ┡━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━┩
147
+ │ ssn │ 10 │
148
+ │ tckn │ 10 │
149
+ │ notes │ 40 │
150
+ │ credit_card │ 40 │
151
+ │ iban │ 40 │
152
+ │ phone │ 40 │
153
+ │ email │ 40 │
154
+ │ name │ 40 │
155
+ │ birth_date │ 40 │
156
+ └─────────────┴────────────────┘
157
+ Verify with: piiscope scan customers_safe.csv
158
+ ╭─ piiscope scan ──────────────────────────────────────────────────────────────────────────────────╮
159
+ │ Source customers_safe.csv │
160
+ │ Rows 40 │
161
+ │ Columns 13 │
162
+ │ Scan time 0.02s │
163
+ │ Jurisdictions gdpr, ccpa, kvkk, lgpd │
164
+ ╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
165
+ No personal data detected.
166
+
167
+ ╭─ Privacy metrics ────────────────────────────────────────────────────────────────────────────────╮
168
+ │ Quasi identifiers birth_date, city, country │
169
+ │ k-anonymity 1 │
170
+ │ l-diversity - │
171
+ │ t-closeness - │
172
+ ╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
173
+ ╭─ Risk ───────────────────────────────────────────────────────────────────────────────────────────╮
174
+ │ Score 0/100 │
175
+ │ Level LOW │
176
+ ╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
177
+ Nothing to remediate.
178
+ ```
179
+ Scan a file and get the risk score in JSON:
180
+ ```bash
181
+ piiscope scan samples/customers.csv --format json | jq '.risk'
182
+ ```
183
+ ```json
184
+ {
185
+ "score": 100,
186
+ "level": "critical",
187
+ "drivers": [
188
+ "tckn: tc_kimlik (national_id, 10 values, confidence 1.00)",
189
+ "ssn: us_ssn (national_id, 10 values, confidence 0.85)",
190
+ "credit_card: credit_card (financial, 40 values, confidence 1.00)"
191
+ ]
192
+ }
193
+ ```
194
+ `make demo` runs the first scan from a fresh clone.
195
+
196
+ ## Use it as a CI gate
197
+ You can fail the build based on privacy risk levels (0=low, 1=medium, 2=high, 3=critical) using `--fail-on`. A level at or above the threshold produces an exit code of 2.
198
+
199
+ ```yaml
200
+ steps:
201
+ - run: pip install piiscope
202
+ - run: piiscope scan data/ --fail-on high
203
+ ```
204
+
205
+ ## Python API
206
+ Call the scan and remediate functions directly in Python:
207
+ ```python
208
+ from piiscope import ScanResult, remediate, scan
209
+
210
+ result: ScanResult = scan("samples/customers.csv", jurisdictions=["gdpr", "ccpa"])
211
+ print(f"Risk Score: {result.risk.score}")
212
+ for finding in result.findings:
213
+ print(f"Found {finding.category} in {finding.column}")
214
+
215
+ if result.metrics:
216
+ print(f"k-anonymity: {result.metrics.k_anonymity}")
217
+
218
+ print(result.to_markdown())
219
+
220
+ remediate("samples/customers.csv", "safe.csv", strategy="hash")
221
+ ```
222
+
223
+ ## What it detects
224
+ Built-in detectors, grouped by category (run `piiscope patterns` for the full table with descriptions):
225
+
226
+ | Category | Detectors |
227
+ | --- | --- |
228
+ | contact | email, us_phone, eu_phone, tr_phone, tr_phone_strict |
229
+ | national_id | us_ssn, tc_kimlik, passport, passport_de, passport_tr, passport_uk, national_id |
230
+ | financial | credit_card (Luhn-checked), iban, iban_tr, swift_bic, vat, vat_de, vat_tr |
231
+ | health | medical_condition, drug_name, hospital_name, medical_record |
232
+ | name | given_name, surname |
233
+ | demographic | date |
234
+ | network | ipv4_address, ipv6_address |
235
+ | other | url |
236
+
237
+ Name detection is deliberately conservative: in free text a token must be capitalised and outside a stoplist of common-word names (will, bill, may, summer, ...), columns that describe places or organisations (city, street, company, ...) never yield person names, and a cell such as "Maria Silva Santos" counts as one given name and one surname. Throughput on a laptop is about 7,000 rows per second on a 300,000-row CSV with free text; files stream in chunks so memory stays flat.
238
+
239
+ ### Dictionaries
240
+ Name and health detectors use built-in lists shipped with the package: given names from Wikidata (CC0) plus curated per-country top lists, surnames from the US Census 2010 file (public domain) plus curated top lists for Germany, Turkey, Brazil, Spain, France, Italy, the Netherlands and Poland, medicine names from the FDA Drugs@FDA product file (public domain), and a curated list of condition terms in English, German and Turkish. Provenance and regeneration steps are in `piiscope/detection/data/README.md` (`python scripts/build_dictionaries.py`). Extend any list at runtime:
241
+ ```bash
242
+ piiscope scan data.csv --dictionary given_name=custom_names.txt
243
+ ```
244
+
245
+ ### Jurisdictions
246
+ By default every finding is tagged with the regulations that govern it (`GDPR`, `CCPA`, `KVKK`, `LGPD`) and scored with that regulation's weighting, so health data and national identifiers count as special categories. Pass `--jurisdiction gdpr` (repeatable) to restrict the tags and the weighting to the regulations you answer to.
247
+
248
+ ## Privacy metrics and risk score
249
+ piiscope computes common privacy metrics automatically:
250
+ - **k-anonymity**: The minimum size of groups with identical quasi-identifiers.
251
+ - **l-diversity**: The variety of sensitive values inside those k-anonymous groups.
252
+ - **t-closeness**: How the distribution of sensitive values in a group compares to the whole dataset.
253
+
254
+ Quasi-identifiers (age, birth date, postal code, gender, city) are picked from column-name hints when you do not pass `--quasi-identifiers`; the sensitive attribute is the highest-severity finding column. The risk score is the highest-scoring single finding (detector severity, jurisdiction weighting, confidence and how many values matched) scaled to 0-100, with levels `low` (below 25), `medium` (25-49), `high` (50-74) and `critical` (75 and above). The three strongest findings are listed as drivers so you know what to fix first.
255
+
256
+ ## Remediation strategies
257
+ Transform findings with one of the following methods:
258
+ - `hash`: SHA-256 hex digest.
259
+ - `redact`: Keep the first and last characters and mask the middle.
260
+ - `null`: Empty string.
261
+ - `generalise`: Numbers become ranges, dates become years, everything else is redacted.
262
+ - `tokenise`: Salted hash pseudonym (reversible if you keep the salt).
263
+ - `date-shift`: Shift dates by a fixed number of days.
264
+
265
+ ## Reports
266
+ Generate compliance reports showing findings, metrics and a DPIA-style summary.
267
+ ```bash
268
+ piiscope report data.csv --out scan.html
269
+ piiscope report data.csv --out scan.md
270
+ piiscope report data.csv --out scan.json
271
+ ```
272
+ The HTML report provides a formatted summary showing the dataset risk, a breakdown of findings, k-anonymity metrics and actionable next steps.
273
+
274
+ ## Run the full platform
275
+ The piiscope platform provides a complete web platform including an API, worker, database and React dashboard for file uploads, RBAC, audit logs, webhooks and compliance reporting.
276
+
277
+ To run it locally:
278
+ ```bash
279
+ cp deploy/env.example .env
280
+ docker compose -f deploy/docker-compose.yml --env-file .env up --build -d
281
+ ```
282
+ Access the UI at `http://localhost:3000` and API docs at `http://localhost:8000/docs`. See [docs/architecture.md](docs/architecture.md) for details. You can also run `make up`.
283
+
284
+ ## Project layout
285
+ - `piiscope/`: Core Python package and detection engine.
286
+ - `api/`: FastAPI REST API service.
287
+ - `app/`: React UI dashboard.
288
+ - `deploy/`: Docker Compose and environment configurations.
289
+ - `docs/`: Architecture and platform documentation.
290
+ - `samples/`: Example datasets for testing.
291
+ - `tests/`: Pytest suite.
292
+
293
+ ## Contributing, Security and License
294
+ Contributions are welcome; see [CONTRIBUTING.md](CONTRIBUTING.md) for the development workflow and guidelines. For reporting vulnerabilities, check [SECURITY.md](SECURITY.md).
295
+ Licensed under the [Apache 2.0 License](LICENSE).
296
+
297
+ **Data handling:** All scans execute completely locally. No data is sent to external servers, and samples included in reports are partially redacted to prevent leakage.