privacy-scan-ml 0.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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Pranay Mahendrakar
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,162 @@
1
+ Metadata-Version: 2.5
2
+ Name: privacy-scan-ml
3
+ Version: 0.1.0
4
+ Summary: Find personal data in datasets before it leaks into models: emails, phones, Aadhaar, PAN, cards, IPs, addresses and more
5
+ Project-URL: Homepage, https://pypi.org/project/privacy-scan-ml/
6
+ Project-URL: Author, https://pypi.org/user/pranaymahendrakar/
7
+ Author: Pranay Mahendrakar
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Keywords: aadhaar,anonymization,data-masking,dpdp,gdpr,machine-learning,pandas,personal-data,pii,privacy
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Intended Audience :: Science/Research
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3 :: Only
17
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
18
+ Requires-Python: >=3.9
19
+ Requires-Dist: numpy>=1.23
20
+ Requires-Dist: pandas>=1.5
21
+ Provides-Extra: dev
22
+ Requires-Dist: pyarrow>=12; extra == 'dev'
23
+ Requires-Dist: pytest>=7; extra == 'dev'
24
+ Provides-Extra: parquet
25
+ Requires-Dist: pyarrow>=12; extra == 'parquet'
26
+ Description-Content-Type: text/markdown
27
+
28
+ # privacy-scan-ml
29
+
30
+ Find the personal data in a dataset before it leaks into a model: emails, phones, Aadhaar,
31
+ PAN, cards, IPs, addresses and more. Every identifier is checked, not just pattern-matched,
32
+ so an amount column is not reported as a phone number and a random 12-digit id is not
33
+ reported as an Aadhaar. Nothing the report prints is an unmasked value.
34
+
35
+ ## Install
36
+
37
+ ```bash
38
+ pip install privacy-scan-ml
39
+ ```
40
+
41
+ ## Quickstart
42
+
43
+ ```python
44
+ import pandas as pd
45
+ from privacy_scan_ml import scan, mask
46
+
47
+ df = pd.DataFrame({
48
+ "full_name": ["Asha Rao", "Vikram Nair"],
49
+ "email": ["asha@example.com", "vikram@example.org"],
50
+ "phone": ["9876543210", "+91 91234 56780"],
51
+ "order_amount": [1299, 45999],
52
+ })
53
+ report = scan(df)
54
+ print(report.summary())
55
+ print(report.risk, report.has_pii, report.pii_columns)
56
+ print(mask(df))
57
+ ```
58
+
59
+ ## What it finds
60
+
61
+ - **email** - RFC-shaped address with a real domain label and an alphabetic TLD,
62
+ including a non-ASCII local part and an IDN domain (RFC 6531).
63
+ - **phone** - international `+CC` numbers, Indian 10-digit mobiles starting 6-9 (with or
64
+ without separators, `0` or `+91` prefix) and separator-formatted NANP numbers.
65
+ - **aadhaar** - 12 digits, first digit 2-9, **Verhoeff checksum**.
66
+ - **pan** - Indian PAN `AAAAA9999A` with the fourth letter one of P/C/H/F/A/T/B/L/J/G.
67
+ - **credit_card** - 13-19 digits, plausible issuer prefix, **Luhn checksum**.
68
+ - **ipv4 / ipv6 / url** - parsed, not guessed.
69
+ - **date_of_birth** - a real calendar date within the last 120 years, plus a column-name
70
+ or cue-word hint ("born", "dob").
71
+ - **postal_code** - Indian 6-digit PIN and US ZIP / ZIP+4, with a column-name hint.
72
+ - **address** - house or flat number, `221B` and `12A` included, followed by street
73
+ words (road, nagar, marg, avenue).
74
+ - **person_name** - column-name hint plus the share of capitalised, alphabetic tokens.
75
+ - **sensitive categories** - gender, religion, caste, ethnicity, nationality, sexual
76
+ orientation, disability, political opinion, health condition, from the column name.
77
+ Each is reported under its own type; `SENSITIVE_TYPES` and `ColumnFinding.category`
78
+ (`"sensitive_category"`) let you ask for the family without listing the nine names.
79
+
80
+ Guardrails that matter in practice:
81
+
82
+ - A column whose header says id, ref, serial, count or amount is never called a phone,
83
+ whether it is stored as integers or as strings, and any other numeric column needs the
84
+ digit lengths themselves to look like phone numbers before it is flagged.
85
+ `order_amount`, `user_id` and a string-typed `txn_ref` all stay clean.
86
+ - `date_of_birth`, `postal_code`, `person_name` and the sensitive categories need the
87
+ column name to agree, because a six-digit number on its own is not evidence.
88
+ - Big frames are sampled evenly (50,000 rows by default), so a scan is deterministic
89
+ and a million-row table still takes seconds.
90
+
91
+ ## API
92
+
93
+ ### `scan(data, *, sample=50_000, min_share=0.2) -> PIIReport`
94
+
95
+ `data` is a DataFrame, a Series, a dict of columns, a path to `.csv` / `.tsv` /
96
+ `.parquet`, a string of free text, or a list of strings.
97
+
98
+ `PIIReport`:
99
+
100
+ | member | what it is |
101
+ | --- | --- |
102
+ | `.columns` | `dict[str, ColumnFinding]` for tabular input |
103
+ | `.findings` | `list[Finding]` for free text: `type`, `value_masked`, `span`, `doc` |
104
+ | `.has_pii` | `True` when anything was flagged |
105
+ | `.risk` | `"high"`, `"medium"`, `"low"` or `"none"` |
106
+ | `.types`, `.pii_columns` | what was found, and where |
107
+ | `.summary()` | human-readable text |
108
+ | `.to_dict()` | JSON-safe dictionary |
109
+ | `.to_markdown()` | the same report as a Markdown document |
110
+ | `.warnings` | e.g. a column named `email` whose values never validated |
111
+
112
+ `ColumnFinding` carries `types` (type -> share of non-null values), three **masked**
113
+ `samples`, a `confidence` from 0 to 1, the `primary` type, the `dtype` and `rows_checked`.
114
+
115
+ ### `mask(data, *, strategy="redact", columns=None, salt=None)`
116
+
117
+ Returns the same type that went in (a path gives you back the masked DataFrame).
118
+
119
+ - `"redact"` - `asha@example.com` becomes `[EMAIL]`
120
+ - `"hash"` - `sha256(salt + value)[:12]`, stable across files with the same salt
121
+ - `"partial"` - keeps the last four characters: `******3210`
122
+
123
+ With `strategy="hash"` and no `salt`, a fresh random salt is generated for that one call and
124
+ recorded on the result, so you never reproduce a mapping by accident. Read it back and pass it
125
+ in again when you do want the same mapping twice:
126
+
127
+ ```python
128
+ masked = mask(df, strategy="hash")
129
+ salt = masked.attrs["privacy_scan_ml_salt"] # a DataFrame or Series carries it here
130
+ same = mask(df, strategy="hash", salt=salt) # identical output
131
+ ```
132
+
133
+ Masked text comes back as a `str` (or `list`) carrying the salt on `.salt` instead. On the
134
+ CLI the generated salt is printed, because a CSV cannot carry it.
135
+
136
+ Every type the scan flags in a cell is replaced, and a column that masking could not change
137
+ is reported in `.attrs["privacy_scan_ml_warnings"]` rather than passing silently.
138
+
139
+ Only the matched span inside a cell is replaced, so a free-text note keeps its wording.
140
+ Columns that nothing matched in are left untouched, dtype included.
141
+
142
+ ### `PIIScanner(*, sample=50_000, min_share=0.2)`
143
+
144
+ The same settings reused across many frames: `.scan()`, `.scan_frame()`, `.scan_text()`,
145
+ `.mask()`, `.mask_frame()`.
146
+
147
+ ## CLI
148
+
149
+ ```bash
150
+ privacy-scan-ml customers.csv # print the summary
151
+ privacy-scan-ml customers.csv --json -o out.json # JSON report
152
+ privacy-scan-ml customers.csv --mask clean.csv --strategy hash --salt s3cret
153
+ privacy-scan-ml customers.csv --mask clean.csv --strategy hash # prints the salt it made
154
+ privacy-scan-ml --text "write to asha@example.com"
155
+ privacy-scan-ml customers.csv --fail-on-pii # exit 1 when PII is found
156
+ ```
157
+
158
+ `--help` lists every flag, including `--sample`, `--min-share` and `--columns`.
159
+
160
+ ## License
161
+
162
+ MIT
@@ -0,0 +1,135 @@
1
+ # privacy-scan-ml
2
+
3
+ Find the personal data in a dataset before it leaks into a model: emails, phones, Aadhaar,
4
+ PAN, cards, IPs, addresses and more. Every identifier is checked, not just pattern-matched,
5
+ so an amount column is not reported as a phone number and a random 12-digit id is not
6
+ reported as an Aadhaar. Nothing the report prints is an unmasked value.
7
+
8
+ ## Install
9
+
10
+ ```bash
11
+ pip install privacy-scan-ml
12
+ ```
13
+
14
+ ## Quickstart
15
+
16
+ ```python
17
+ import pandas as pd
18
+ from privacy_scan_ml import scan, mask
19
+
20
+ df = pd.DataFrame({
21
+ "full_name": ["Asha Rao", "Vikram Nair"],
22
+ "email": ["asha@example.com", "vikram@example.org"],
23
+ "phone": ["9876543210", "+91 91234 56780"],
24
+ "order_amount": [1299, 45999],
25
+ })
26
+ report = scan(df)
27
+ print(report.summary())
28
+ print(report.risk, report.has_pii, report.pii_columns)
29
+ print(mask(df))
30
+ ```
31
+
32
+ ## What it finds
33
+
34
+ - **email** - RFC-shaped address with a real domain label and an alphabetic TLD,
35
+ including a non-ASCII local part and an IDN domain (RFC 6531).
36
+ - **phone** - international `+CC` numbers, Indian 10-digit mobiles starting 6-9 (with or
37
+ without separators, `0` or `+91` prefix) and separator-formatted NANP numbers.
38
+ - **aadhaar** - 12 digits, first digit 2-9, **Verhoeff checksum**.
39
+ - **pan** - Indian PAN `AAAAA9999A` with the fourth letter one of P/C/H/F/A/T/B/L/J/G.
40
+ - **credit_card** - 13-19 digits, plausible issuer prefix, **Luhn checksum**.
41
+ - **ipv4 / ipv6 / url** - parsed, not guessed.
42
+ - **date_of_birth** - a real calendar date within the last 120 years, plus a column-name
43
+ or cue-word hint ("born", "dob").
44
+ - **postal_code** - Indian 6-digit PIN and US ZIP / ZIP+4, with a column-name hint.
45
+ - **address** - house or flat number, `221B` and `12A` included, followed by street
46
+ words (road, nagar, marg, avenue).
47
+ - **person_name** - column-name hint plus the share of capitalised, alphabetic tokens.
48
+ - **sensitive categories** - gender, religion, caste, ethnicity, nationality, sexual
49
+ orientation, disability, political opinion, health condition, from the column name.
50
+ Each is reported under its own type; `SENSITIVE_TYPES` and `ColumnFinding.category`
51
+ (`"sensitive_category"`) let you ask for the family without listing the nine names.
52
+
53
+ Guardrails that matter in practice:
54
+
55
+ - A column whose header says id, ref, serial, count or amount is never called a phone,
56
+ whether it is stored as integers or as strings, and any other numeric column needs the
57
+ digit lengths themselves to look like phone numbers before it is flagged.
58
+ `order_amount`, `user_id` and a string-typed `txn_ref` all stay clean.
59
+ - `date_of_birth`, `postal_code`, `person_name` and the sensitive categories need the
60
+ column name to agree, because a six-digit number on its own is not evidence.
61
+ - Big frames are sampled evenly (50,000 rows by default), so a scan is deterministic
62
+ and a million-row table still takes seconds.
63
+
64
+ ## API
65
+
66
+ ### `scan(data, *, sample=50_000, min_share=0.2) -> PIIReport`
67
+
68
+ `data` is a DataFrame, a Series, a dict of columns, a path to `.csv` / `.tsv` /
69
+ `.parquet`, a string of free text, or a list of strings.
70
+
71
+ `PIIReport`:
72
+
73
+ | member | what it is |
74
+ | --- | --- |
75
+ | `.columns` | `dict[str, ColumnFinding]` for tabular input |
76
+ | `.findings` | `list[Finding]` for free text: `type`, `value_masked`, `span`, `doc` |
77
+ | `.has_pii` | `True` when anything was flagged |
78
+ | `.risk` | `"high"`, `"medium"`, `"low"` or `"none"` |
79
+ | `.types`, `.pii_columns` | what was found, and where |
80
+ | `.summary()` | human-readable text |
81
+ | `.to_dict()` | JSON-safe dictionary |
82
+ | `.to_markdown()` | the same report as a Markdown document |
83
+ | `.warnings` | e.g. a column named `email` whose values never validated |
84
+
85
+ `ColumnFinding` carries `types` (type -> share of non-null values), three **masked**
86
+ `samples`, a `confidence` from 0 to 1, the `primary` type, the `dtype` and `rows_checked`.
87
+
88
+ ### `mask(data, *, strategy="redact", columns=None, salt=None)`
89
+
90
+ Returns the same type that went in (a path gives you back the masked DataFrame).
91
+
92
+ - `"redact"` - `asha@example.com` becomes `[EMAIL]`
93
+ - `"hash"` - `sha256(salt + value)[:12]`, stable across files with the same salt
94
+ - `"partial"` - keeps the last four characters: `******3210`
95
+
96
+ With `strategy="hash"` and no `salt`, a fresh random salt is generated for that one call and
97
+ recorded on the result, so you never reproduce a mapping by accident. Read it back and pass it
98
+ in again when you do want the same mapping twice:
99
+
100
+ ```python
101
+ masked = mask(df, strategy="hash")
102
+ salt = masked.attrs["privacy_scan_ml_salt"] # a DataFrame or Series carries it here
103
+ same = mask(df, strategy="hash", salt=salt) # identical output
104
+ ```
105
+
106
+ Masked text comes back as a `str` (or `list`) carrying the salt on `.salt` instead. On the
107
+ CLI the generated salt is printed, because a CSV cannot carry it.
108
+
109
+ Every type the scan flags in a cell is replaced, and a column that masking could not change
110
+ is reported in `.attrs["privacy_scan_ml_warnings"]` rather than passing silently.
111
+
112
+ Only the matched span inside a cell is replaced, so a free-text note keeps its wording.
113
+ Columns that nothing matched in are left untouched, dtype included.
114
+
115
+ ### `PIIScanner(*, sample=50_000, min_share=0.2)`
116
+
117
+ The same settings reused across many frames: `.scan()`, `.scan_frame()`, `.scan_text()`,
118
+ `.mask()`, `.mask_frame()`.
119
+
120
+ ## CLI
121
+
122
+ ```bash
123
+ privacy-scan-ml customers.csv # print the summary
124
+ privacy-scan-ml customers.csv --json -o out.json # JSON report
125
+ privacy-scan-ml customers.csv --mask clean.csv --strategy hash --salt s3cret
126
+ privacy-scan-ml customers.csv --mask clean.csv --strategy hash # prints the salt it made
127
+ privacy-scan-ml --text "write to asha@example.com"
128
+ privacy-scan-ml customers.csv --fail-on-pii # exit 1 when PII is found
129
+ ```
130
+
131
+ `--help` lists every flag, including `--sample`, `--min-share` and `--columns`.
132
+
133
+ ## License
134
+
135
+ MIT
@@ -0,0 +1,56 @@
1
+ [build-system]
2
+ requires = ["hatchling>=1.27"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "privacy-scan-ml"
7
+ version = "0.1.0"
8
+ description = "Find personal data in datasets before it leaks into models: emails, phones, Aadhaar, PAN, cards, IPs, addresses and more"
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ license = "MIT"
12
+ license-files = ["LICENSE"]
13
+ authors = [{ name = "Pranay Mahendrakar" }]
14
+ keywords = [
15
+ "pii",
16
+ "privacy",
17
+ "personal-data",
18
+ "data-masking",
19
+ "anonymization",
20
+ "gdpr",
21
+ "dpdp",
22
+ "aadhaar",
23
+ "pandas",
24
+ "machine-learning",
25
+ ]
26
+ classifiers = [
27
+ "Development Status :: 4 - Beta",
28
+ "Intended Audience :: Developers",
29
+ "Intended Audience :: Science/Research",
30
+ "Programming Language :: Python :: 3",
31
+ "Programming Language :: Python :: 3 :: Only",
32
+ "Operating System :: OS Independent",
33
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
34
+ ]
35
+ dependencies = [
36
+ "pandas>=1.5",
37
+ "numpy>=1.23",
38
+ ]
39
+
40
+ [project.optional-dependencies]
41
+ # heavy or niche deps go here, never in `dependencies`
42
+ parquet = ["pyarrow>=12"]
43
+ dev = ["pytest>=7", "pyarrow>=12"]
44
+
45
+ [project.scripts]
46
+ privacy-scan-ml = "privacy_scan_ml.cli:main"
47
+
48
+ [project.urls]
49
+ Homepage = "https://pypi.org/project/privacy-scan-ml/"
50
+ Author = "https://pypi.org/user/pranaymahendrakar/"
51
+
52
+ [tool.hatch.build.targets.wheel]
53
+ packages = ["src/privacy_scan_ml"]
54
+
55
+ [tool.pytest.ini_options]
56
+ testpaths = ["tests"]
@@ -0,0 +1,30 @@
1
+ """privacy-scan-ml: find personal data in a dataset before it leaks into a model.
2
+
3
+ >>> import pandas as pd, privacy_scan_ml as psm
4
+ >>> report = psm.scan(pd.DataFrame({"email": ["a@example.com"]}))
5
+ >>> report.has_pii
6
+ True
7
+ """
8
+ from __future__ import annotations
9
+
10
+ from ._detectors import ALL_TYPES, COLUMN_ONLY_TYPES, PATTERN_TYPES, SENSITIVE_TYPES
11
+ from ._mask import STRATEGIES
12
+ from .report import ColumnFinding, Finding, PIIReport
13
+ from .scanner import PIIScanner, mask, scan
14
+
15
+ __version__ = "0.1.0"
16
+
17
+ __all__ = [
18
+ "scan",
19
+ "mask",
20
+ "PIIScanner",
21
+ "PIIReport",
22
+ "ColumnFinding",
23
+ "Finding",
24
+ "ALL_TYPES",
25
+ "PATTERN_TYPES",
26
+ "COLUMN_ONLY_TYPES",
27
+ "SENSITIVE_TYPES",
28
+ "STRATEGIES",
29
+ "__version__",
30
+ ]
@@ -0,0 +1,8 @@
1
+ """Allow ``python -m privacy_scan_ml``."""
2
+
3
+ import sys
4
+
5
+ from .cli import main
6
+
7
+ if __name__ == "__main__":
8
+ sys.exit(main())