depii 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.
Files changed (53) hide show
  1. depii-0.1.0/.gitignore +15 -0
  2. depii-0.1.0/CHANGELOG.md +18 -0
  3. depii-0.1.0/LICENSE +177 -0
  4. depii-0.1.0/PKG-INFO +285 -0
  5. depii-0.1.0/README.md +239 -0
  6. depii-0.1.0/benchmarks/evaluate.py +43 -0
  7. depii-0.1.0/benchmarks/throughput.py +41 -0
  8. depii-0.1.0/pyproject.toml +94 -0
  9. depii-0.1.0/src/depii/__init__.py +76 -0
  10. depii-0.1.0/src/depii/__main__.py +5 -0
  11. depii-0.1.0/src/depii/cli.py +256 -0
  12. depii-0.1.0/src/depii/detectors/__init__.py +6 -0
  13. depii-0.1.0/src/depii/detectors/base.py +30 -0
  14. depii-0.1.0/src/depii/detectors/global_.py +369 -0
  15. depii-0.1.0/src/depii/detectors/ner.py +72 -0
  16. depii-0.1.0/src/depii/detectors/pattern.py +134 -0
  17. depii-0.1.0/src/depii/detectors/secrets.py +97 -0
  18. depii-0.1.0/src/depii/engine.py +184 -0
  19. depii-0.1.0/src/depii/frames.py +73 -0
  20. depii-0.1.0/src/depii/locales/__init__.py +58 -0
  21. depii-0.1.0/src/depii/locales/de.py +37 -0
  22. depii-0.1.0/src/depii/locales/es.py +30 -0
  23. depii-0.1.0/src/depii/locales/eu.py +35 -0
  24. depii-0.1.0/src/depii/locales/fr.py +23 -0
  25. depii-0.1.0/src/depii/locales/gb.py +57 -0
  26. depii-0.1.0/src/depii/locales/in_.py +99 -0
  27. depii-0.1.0/src/depii/locales/it.py +19 -0
  28. depii-0.1.0/src/depii/locales/nl.py +20 -0
  29. depii-0.1.0/src/depii/locales/us.py +74 -0
  30. depii-0.1.0/src/depii/logfilter.py +70 -0
  31. depii-0.1.0/src/depii/normalize.py +55 -0
  32. depii-0.1.0/src/depii/operators.py +154 -0
  33. depii-0.1.0/src/depii/py.typed +0 -0
  34. depii-0.1.0/src/depii/registry.py +42 -0
  35. depii-0.1.0/src/depii/stream.py +61 -0
  36. depii-0.1.0/src/depii/structured.py +171 -0
  37. depii-0.1.0/src/depii/types.py +64 -0
  38. depii-0.1.0/src/depii/validators.py +384 -0
  39. depii-0.1.0/tests/conftest.py +5 -0
  40. depii-0.1.0/tests/synth.py +339 -0
  41. depii-0.1.0/tests/test_corpus.py +41 -0
  42. depii-0.1.0/tests/test_detectors.py +151 -0
  43. depii-0.1.0/tests/test_engine.py +172 -0
  44. depii-0.1.0/tests/test_frames_ner.py +116 -0
  45. depii-0.1.0/tests/test_locales.py +109 -0
  46. depii-0.1.0/tests/test_logfilter.py +93 -0
  47. depii-0.1.0/tests/test_operators.py +101 -0
  48. depii-0.1.0/tests/test_properties.py +121 -0
  49. depii-0.1.0/tests/test_readme.py +10 -0
  50. depii-0.1.0/tests/test_redos.py +64 -0
  51. depii-0.1.0/tests/test_stream_cli.py +151 -0
  52. depii-0.1.0/tests/test_structured.py +137 -0
  53. depii-0.1.0/tests/test_validators.py +68 -0
depii-0.1.0/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *.egg-info/
4
+ .venv/
5
+ venv/
6
+ build/
7
+ dist/
8
+ .pytest_cache/
9
+ .mypy_cache/
10
+ .ruff_cache/
11
+ .hypothesis/
12
+ .coverage
13
+ htmlcov/
14
+ .idea/
15
+ .vscode/
@@ -0,0 +1,18 @@
1
+ # Changelog
2
+
3
+ This project follows [Semantic Versioning](https://semver.org/). Entity names and the fields of `Span` and `Result` are part of the public interface.
4
+
5
+ ## 0.1.0 (2026-10-13)
6
+
7
+ First version.
8
+
9
+ - Detection engine: Unicode normalisation with offsets mapped back to the original text, scoring with context words, deterministic overlap resolution.
10
+ - Global detectors: email, phone, credit card, IBAN, BIC, IPv4 and IPv6, MAC address, URL, IMEI, VIN, coordinates, crypto wallets, date of birth.
11
+ - Secret detectors: cloud and service tokens, JWTs, private key blocks, bearer tokens, `key = value` assignments.
12
+ - Country packs: `us`, `in`, `gb`, `de`, `fr`, `es`, `it`, `nl`, `eu`. Third-party packs load through the `depii.locales` entry-point group.
13
+ - Operators: `Replace`, `Mask`, `Hash` (HMAC-SHA256, key required), `Tokenize` with a reversible `Vault`, `Drop`, `Keep`.
14
+ - `redact_obj` for nested data, with field-name hints.
15
+ - `PIIFilter` for the `logging` module.
16
+ - Command line: `redact` (text, JSON Lines, CSV), `scan`, `entities`.
17
+ - `redact_dataframe` for pandas (extra `pandas`).
18
+ - `SpacyDetector` for names, places and organisations (extra `ner`).
depii-0.1.0/LICENSE ADDED
@@ -0,0 +1,177 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
depii-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,285 @@
1
+ Metadata-Version: 2.5
2
+ Name: depii
3
+ Version: 0.1.0
4
+ Summary: Detect and redact personally identifiable information (PII) in text, nested data, logs, files and DataFrames.
5
+ Project-URL: Repository, https://github.com/Boredem125/piiredact
6
+ Project-URL: Issues, https://github.com/Boredem125/piiredact/issues
7
+ Project-URL: Changelog, https://github.com/Boredem125/piiredact/blob/main/CHANGELOG.md
8
+ Author: depii contributors
9
+ License-Expression: Apache-2.0
10
+ License-File: LICENSE
11
+ Keywords: anonymization,data-protection,dpdp,gdpr,logging,pii,privacy,redaction
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3 :: Only
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Programming Language :: Python :: 3.14
22
+ Classifier: Topic :: Security
23
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
24
+ Classifier: Topic :: Text Processing :: Filters
25
+ Classifier: Typing :: Typed
26
+ Requires-Python: >=3.10
27
+ Provides-Extra: all
28
+ Requires-Dist: pandas>=2.0; extra == 'all'
29
+ Requires-Dist: phonenumbers>=8.13; extra == 'all'
30
+ Requires-Dist: spacy>=3.7; extra == 'all'
31
+ Provides-Extra: dev
32
+ Requires-Dist: build>=1.2; extra == 'dev'
33
+ Requires-Dist: hypothesis>=6.100; extra == 'dev'
34
+ Requires-Dist: mypy>=1.11; extra == 'dev'
35
+ Requires-Dist: pandas-stubs; extra == 'dev'
36
+ Requires-Dist: pandas>=2.0; extra == 'dev'
37
+ Requires-Dist: pytest>=8; extra == 'dev'
38
+ Requires-Dist: ruff>=0.6; extra == 'dev'
39
+ Provides-Extra: ner
40
+ Requires-Dist: spacy>=3.7; extra == 'ner'
41
+ Provides-Extra: pandas
42
+ Requires-Dist: pandas>=2.0; extra == 'pandas'
43
+ Provides-Extra: phone
44
+ Requires-Dist: phonenumbers>=8.13; extra == 'phone'
45
+ Description-Content-Type: text/markdown
46
+
47
+ # depii
48
+
49
+ [![CI](https://github.com/Boredem125/piiredact/actions/workflows/ci.yml/badge.svg)](https://github.com/Boredem125/piiredact/actions/workflows/ci.yml)
50
+
51
+ Detect and redact personally identifiable information (PII) in text, nested data, logs, files and DataFrames.
52
+
53
+ - **No dependencies** in the core. Pure Python, 3.10 and later.
54
+ - **Validated, not just matched.** Card numbers, IBANs, Aadhaar, NHS numbers and other identifiers are checked against their check digits, so a random run of digits is not flagged.
55
+ - **Country packs** for the United States, India, the United Kingdom, Germany, France, Spain, Italy, the Netherlands and the EU, plus a plug-in mechanism for more.
56
+ - **Secrets too.** API keys, tokens, private keys and `password=...` assignments.
57
+ - **Several ways in:** strings, nested dicts and lists, a `logging` filter, a command line tool, and pandas.
58
+
59
+ ```python
60
+ >>> import depii
61
+ >>> depii.redact("Mail jane@example.com or call +1 415 555 0132")
62
+ 'Mail [EMAIL] or call [PHONE]'
63
+
64
+ ```
65
+
66
+ ## Read this first
67
+
68
+ No tool finds every piece of PII, and this one does not either. Names, street addresses and free-form descriptions ("the tall man from flat 4") cannot be found by patterns at all. Treat the output as reduced-risk data, not as anonymous data.
69
+
70
+ Using this library does not by itself make a system compliant with GDPR, HIPAA, India's DPDP Act or any other law. Measure recall on a sample of your own data before you depend on it; [Evaluation](#evaluation) shows how.
71
+
72
+ ## Install
73
+
74
+ ```bash
75
+ pip install depii
76
+ ```
77
+
78
+ Optional extras: `depii[pandas]` for DataFrames, `depii[ner]` for names and places through spaCy, `depii[phone]` for stricter validation of international phone numbers, `depii[all]` for all three.
79
+
80
+ ## Usage
81
+
82
+ ### Text
83
+
84
+ ```python
85
+ >>> from depii import Redactor, Mask
86
+ >>> redactor = Redactor(policy={"CREDIT_CARD": Mask(keep_last=4)})
87
+ >>> result = redactor.redact("jane@example.com paid with 4111 1111 1111 1111")
88
+ >>> result.text
89
+ '[EMAIL] paid with **** **** **** 1111'
90
+ >>> result.stats
91
+ {'EMAIL': 1, 'CREDIT_CARD': 1}
92
+
93
+ ```
94
+
95
+ Build a `Redactor` once and reuse it. It is immutable and safe to share between threads.
96
+
97
+ `scan` reports what was found without changing the text. The `repr` of a span leaves the matched value out, so spans can be logged:
98
+
99
+ ```python
100
+ >>> depii.scan("SSN 078-05-1120")
101
+ [Span(start=4, end=15, entity='US_SSN', score=1.0, detector='us_ssn')]
102
+
103
+ ```
104
+
105
+ ### Options
106
+
107
+ | Option | Meaning |
108
+ |---|---|
109
+ | `locales` | Country packs to load, for example `["us", "in"]`. Default: all installed. Loading only the packs you need reduces false positives. |
110
+ | `entities` / `exclude_entities` | Limit detection to, or exempt, some entity types. |
111
+ | `policy` | Entity type to operator. Others use `default_operator`. |
112
+ | `min_score` | Detections below this score are ignored. Default 0.5. |
113
+ | `strict` | Prefer over-redaction: lower the threshold and drop the need for a context word. |
114
+ | `allow` | Exact values never to redact, such as your own support address. |
115
+ | `detectors` | Extra detectors of your own. |
116
+
117
+ ### Operators
118
+
119
+ | Operator | `4111 1111 1111 1111` becomes |
120
+ |---|---|
121
+ | `Replace()` (default) | `[CREDIT_CARD]` |
122
+ | `Mask(keep_last=4)` | `**** **** **** 1111` |
123
+ | `Hash(key)` | `[CREDIT_CARD:` 16 hex digits `]` |
124
+ | `Tokenize(vault)` | `[CREDIT_CARD_1]`, reversible with `vault.restore(text)` |
125
+ | `Drop()` | nothing |
126
+ | `Keep()` | unchanged |
127
+
128
+ `Hash` needs a secret key of at least 16 bytes and uses HMAC-SHA256. An unkeyed hash of a phone number or national ID can be reversed by trying every possible value, so it is not offered. `Mask` never reveals more than half of a value. A `Vault` holds the original values: protect it as you would the unredacted data.
129
+
130
+ ### Nested data
131
+
132
+ ```python
133
+ >>> depii.redact_obj({
134
+ ... "note": "call jane@example.com",
135
+ ... "user": {"firstName": "Jane", "password": "hunter2", "age": 41},
136
+ ... })
137
+ {'note': 'call [EMAIL]', 'user': {'firstName': '[PERSON]', 'password': '[SECRET]', 'age': 41}}
138
+
139
+ ```
140
+
141
+ Field names are used as hints. A field called `password`, `ssn`, `userEmail` or `phone_number` has its whole value redacted, even when the value does not look like PII. Pass `key_hints=False` to turn this off. The input object is not modified.
142
+
143
+ ### Logging
144
+
145
+ ```python
146
+ import logging
147
+ from depii import PIIFilter
148
+
149
+ handler = logging.StreamHandler()
150
+ handler.addFilter(PIIFilter())
151
+ logging.getLogger().addHandler(handler)
152
+ ```
153
+
154
+ Attach the filter to handlers, not loggers: a filter on a logger does not see records that propagate up from child loggers. The message, its arguments, exception text, stack info and `extra` fields are all redacted. If redaction itself fails, the message is replaced with a fixed notice instead of being written unredacted.
155
+
156
+ ### Command line
157
+
158
+ ```bash
159
+ depii redact notes.txt -o clean.txt
160
+ cat app.log | depii redact - > clean.log
161
+ depii redact events.jsonl --format jsonl -o clean.jsonl
162
+ depii redact people.csv --format csv --operator mask --keep-last 4 -o clean.csv
163
+ depii scan notes.txt
164
+ depii entities --locales us,in
165
+ ```
166
+
167
+ `scan` prints `file:line:column: ENTITY (score)` for each finding and exits with status 1 when anything is found, so it can gate a commit or a CI job. It does not print the matched values unless you pass `--show-values`.
168
+
169
+ For `--operator hash`, the key is read from the environment variable `DEPII_HASH_KEY`, so that it does not appear in the process list or shell history.
170
+
171
+ Text input is streamed in chunks, so large files do not need to fit in memory. A file that is one single very long line is the exception.
172
+
173
+ ### pandas
174
+
175
+ ```python
176
+ from depii.frames import redact_dataframe
177
+
178
+ clean = redact_dataframe(df) # every text column
179
+ clean = redact_dataframe(df, columns=["notes"]) # only these
180
+ ```
181
+
182
+ Column names are used as hints in the same way as field names.
183
+
184
+ ### Names and places
185
+
186
+ Patterns cannot find names. The optional spaCy detector can, at the cost of a model download and slower runs:
187
+
188
+ ```bash
189
+ pip install "depii[ner]"
190
+ python -m spacy download en_core_web_sm
191
+ ```
192
+
193
+ ```python
194
+ from depii import Redactor
195
+ from depii.detectors.ner import SpacyDetector
196
+
197
+ redactor = Redactor(detectors=[SpacyDetector()])
198
+ ```
199
+
200
+ It emits `PERSON`, `LOCATION` and `ORGANIZATION`. Its accuracy is that of the spaCy model you load.
201
+
202
+ ### Your own detectors
203
+
204
+ ```python
205
+ >>> from depii import PatternDetector, Redactor
206
+ >>> employee_id = PatternDetector(
207
+ ... "EMPLOYEE_ID",
208
+ ... r"\bE\d{5}\b",
209
+ ... score=0.4,
210
+ ... context=("employee", "staff"),
211
+ ... require_context=True,
212
+ ... )
213
+ >>> Redactor(detectors=[employee_id]).redact("staff E12345 badge").text
214
+ 'staff [EMPLOYEE_ID] badge'
215
+
216
+ ```
217
+
218
+ A country pack is a module that exports `DETECTORS`. A separate package can register one under the `depii.locales` entry-point group, and it is then loaded like a built-in pack:
219
+
220
+ ```toml
221
+ [project.entry-points."depii.locales"]
222
+ br = "depii_br:DETECTORS"
223
+ ```
224
+
225
+ ## What is detected
226
+
227
+ | Pack | Entity types |
228
+ |---|---|
229
+ | Always on | `EMAIL`, `PHONE`, `CREDIT_CARD`, `IBAN`, `BIC`, `IP_ADDRESS`, `MAC_ADDRESS`, `URL`, `IMEI`, `VIN`, `GEO_COORDINATES`, `CRYPTO_WALLET`, `DATE_OF_BIRTH`, `SECRET` |
230
+ | `us` | `US_SSN`, `US_ITIN`, `US_EIN`, `US_PASSPORT`, `US_ROUTING_NUMBER`, `US_ZIP` |
231
+ | `in` | `IN_AADHAAR`, `IN_PAN`, `IN_GSTIN`, `IN_VOTER_ID`, `IN_PASSPORT`, `IN_IFSC`, `IN_UPI_ID`, `IN_PIN_CODE` |
232
+ | `gb` | `GB_NINO`, `GB_NHS_NUMBER`, `GB_POSTCODE`, `GB_DRIVING_LICENCE` |
233
+ | `de` | `DE_TAX_ID`, `DE_ID_CARD` |
234
+ | `fr` | `FR_NIR` |
235
+ | `es` | `ES_DNI`, `ES_NIE` |
236
+ | `it` | `IT_FISCAL_CODE` |
237
+ | `nl` | `NL_BSN` |
238
+ | `eu` | `EU_VAT` |
239
+
240
+ Field-name hints can also produce `PERSON`, `LOCATION`, `PASSPORT`, `BANK_ACCOUNT`, `NATIONAL_ID`, `TAX_ID` and `DRIVING_LICENCE`.
241
+
242
+ ### Behaviour worth knowing
243
+
244
+ - **Context words.** Shapes that are too common to trust alone need a nearby word: a bare nine-digit number is an SSN only next to "SSN", a date is a date of birth only next to "born" or "DOB", and so on. `strict=True` removes this requirement.
245
+ - **Context reaches across sentences.** The window is about 48 characters before a value and 24 after. A second date shortly after "born 3 March 1985" is redacted as well.
246
+ - **URLs.** A URL is redacted when it carries credentials or a query string. A plain link is left alone unless `strict=True`.
247
+ - **Aadhaar.** A bare twelve-digit number starting with 2 to 9 that passes the Verhoeff check is treated as an Aadhaar number. About one in twelve arbitrary twelve-digit numbers does. If your data has no Indian identifiers, leave the `in` pack out.
248
+ - **Labels can be ambiguous.** A number that is valid as two things gets one label. It is redacted either way.
249
+ - **Unicode.** Full-width digits, non-Latin digits, unusual dashes and zero-width characters inside a value are handled. Internationalised email addresses are not.
250
+ - **Not handled:** images, PDFs, audio, and PII that is written out in words ("jane at example dot com").
251
+
252
+ ## Evaluation
253
+
254
+ ```bash
255
+ python benchmarks/evaluate.py
256
+ python benchmarks/throughput.py
257
+ ```
258
+
259
+ `evaluate.py` scores the detectors on a generated corpus: valid identifiers planted in sentences, plus numeric text that holds no PII. On that corpus every listed type currently reaches a recall and precision of 1.0. This shows that the detectors agree with the formats they claim to support. It does not predict recall on real text, which is messier than anything a generator produces. To measure on your own data, label a sample and pass it to `synth.evaluate` in `tests/synth.py`.
260
+
261
+ Throughput on one development laptop (Python 3.12, all packs loaded), for orientation only:
262
+
263
+ | Input | Speed |
264
+ |---|---|
265
+ | Prose without digits | about 3.6 MB/s |
266
+ | Text dense with identifiers | about 0.3 MB/s |
267
+ | One short log line | 40 to 200 microseconds |
268
+
269
+ Loading fewer packs is the simplest way to go faster.
270
+
271
+ ## Development
272
+
273
+ ```bash
274
+ python -m venv .venv
275
+ .venv/bin/pip install -e ".[dev]" # .venv\Scripts\pip on Windows
276
+ ruff check . && ruff format --check .
277
+ mypy
278
+ pytest
279
+ ```
280
+
281
+ The test suite includes property tests (Hypothesis) and a timing test that guards every pattern against catastrophic regex backtracking. Test data is generated: do not add real personal data to this repository.
282
+
283
+ ## Licence
284
+
285
+ Apache-2.0. See [LICENSE](LICENSE).