protegrity-ai-developer-python 1.2.1__py3-none-any.whl
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.
- appython/__init__.py +12 -0
- appython/protector.py +554 -0
- appython/service/auth_provider.py +273 -0
- appython/service/auth_token_provider.py +45 -0
- appython/service/config.py +209 -0
- appython/service/payload_builder.py +141 -0
- appython/service/request_handler.py +115 -0
- appython/service/response_handler.py +78 -0
- appython/stats/__init__.py +3 -0
- appython/stats/collector.py +90 -0
- appython/stats/writer.py +185 -0
- appython/utils/codec_helper.py +86 -0
- appython/utils/constants.py +246 -0
- appython/utils/exceptions.py +141 -0
- appython/utils/input_preprocessor.py +325 -0
- appython/utils/output_postprocessor.py +99 -0
- protegrity_ai_developer_python-1.2.1.dist-info/METADATA +428 -0
- protegrity_ai_developer_python-1.2.1.dist-info/RECORD +53 -0
- protegrity_ai_developer_python-1.2.1.dist-info/WHEEL +5 -0
- protegrity_ai_developer_python-1.2.1.dist-info/entry_points.txt +2 -0
- protegrity_ai_developer_python-1.2.1.dist-info/licenses/LICENSE +21 -0
- protegrity_ai_developer_python-1.2.1.dist-info/top_level.txt +3 -0
- protegrity_developer_python/__init__.py +4 -0
- protegrity_developer_python/scan.py +37 -0
- protegrity_developer_python/securefind.py +83 -0
- protegrity_developer_python/utils/ccn_processing.py +59 -0
- protegrity_developer_python/utils/config.py +60 -0
- protegrity_developer_python/utils/constants.py +123 -0
- protegrity_developer_python/utils/discover.py +49 -0
- protegrity_developer_python/utils/logger.py +23 -0
- protegrity_developer_python/utils/pii_processing.py +291 -0
- protegrity_developer_python/utils/protector.py +23 -0
- protegrity_developer_python/utils/semantic_guardrails.py +240 -0
- protegrity_developer_python/utils/transform.py +66 -0
- pty_migrate/__init__.py +1 -0
- pty_migrate/check_cmd.py +871 -0
- pty_migrate/cli.py +93 -0
- pty_migrate/config.py +127 -0
- pty_migrate/create_policy_cmd.py +795 -0
- pty_migrate/payloads/__init__.py +51 -0
- pty_migrate/payloads/alphabets.json +42 -0
- pty_migrate/payloads/dataelements.json +342 -0
- pty_migrate/payloads/datastores.json +7 -0
- pty_migrate/payloads/deploy_policy_ta.json +1 -0
- pty_migrate/payloads/masks.json +18 -0
- pty_migrate/payloads/members.json +62 -0
- pty_migrate/payloads/policies.json +13 -0
- pty_migrate/payloads/roles.json +32 -0
- pty_migrate/payloads/rules.json +1639 -0
- pty_migrate/payloads/sources.json +10 -0
- pty_migrate/payloads/trusted_apps.json +8 -0
- pty_migrate/ppc_client.py +371 -0
- pty_migrate/stats_cmd.py +87 -0
|
@@ -0,0 +1,428 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: protegrity-ai-developer-python
|
|
3
|
+
Version: 1.2.1
|
|
4
|
+
Summary: Python module for integrating Protegrity's Data Discovery and Protection APIs into GenAI and traditional applications.
|
|
5
|
+
Home-page: https://www.protegrity.com/developers
|
|
6
|
+
Author: Protegrity
|
|
7
|
+
Author-email: Protegrity <info@protegrity.com>
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
Project-URL: homepage, https://www.protegrity.com/developers
|
|
10
|
+
Project-URL: repository, https://github.com/Protegrity-AI-Developer-Edition/protegrity-ai-developer-python
|
|
11
|
+
Project-URL: documentation, http://developer.docs.protegrity.com
|
|
12
|
+
Requires-Python: >=3.11
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Requires-Dist: requests
|
|
16
|
+
Requires-Dist: botocore
|
|
17
|
+
Requires-Dist: PyYAML>=6.0
|
|
18
|
+
Dynamic: license-file
|
|
19
|
+
|
|
20
|
+
<div align="center">
|
|
21
|
+
|
|
22
|
+
# Protegrity AI Developer Edition Python
|
|
23
|
+
[](https://github.com/Protegrity-AI-Developer-Edition/protegrity-ai-developer-python/releases)
|
|
24
|
+
[](https://github.com/Protegrity-AI-Developer-Edition/protegrity-ai-developer-python/blob/main/LICENSE)
|
|
25
|
+
[](https://www.python.org/downloads/)
|
|
26
|
+
[](https://www.linux.org/)
|
|
27
|
+
[](https://www.microsoft.com/windows/)
|
|
28
|
+
[](https://www.apple.com/macos/)
|
|
29
|
+
[](https://pypi.org/project/protegrity-ai-developer-python/)
|
|
30
|
+
[](https://anaconda.org/protegrity/protegrity-ai-developer-python)
|
|
31
|
+
[](https://www.protegrity.com/developers/status)
|
|
32
|
+
[](https://deepwiki.com/Protegrity-AI-Developer-Edition/protegrity-ai-developer-python)
|
|
33
|
+
</div>
|
|
34
|
+
|
|
35
|
+
Welcome to the `protegrity-ai-developer-python` repository, part of the Protegrity AI Developer Edition suite. This repository provides the Python module for integrating Protegrity's Data Discovery and Protection APIs into GenAI and traditional applications. Customize, compile, and use the module as per your requirements.
|
|
36
|
+
|
|
37
|
+
> **💡Note:** This module should be built and used only if you intend to modify the source code or default behavior.
|
|
38
|
+
|
|
39
|
+
## Table of Contents
|
|
40
|
+
|
|
41
|
+
1. [Overview](#overview)
|
|
42
|
+
- [Why This Matters](#why-this-matters)
|
|
43
|
+
2. [Repository Structure](#repository-structure)
|
|
44
|
+
3. [Features](#features)
|
|
45
|
+
- [Protegrity Developer Python](#Protegrity-Developer-Python)
|
|
46
|
+
- [Application Protector Python](#Application-Protector-Python)
|
|
47
|
+
4. [Getting Started](#getting-started)
|
|
48
|
+
- [Prerequisites](#prerequisites)
|
|
49
|
+
5. [Protegrity AI Developer Edition Python Module](#protegrity-ai-developer-edition-python-module)
|
|
50
|
+
- [Usage Examples](#usage-examples)
|
|
51
|
+
- [Find and Redact](#find-and-redact)
|
|
52
|
+
- [Find and Protect](#find-and-protect)
|
|
53
|
+
- [Find and Unprotect](#find-and-unprotect)
|
|
54
|
+
6. [Application Protector Python module](#application-protector-python-module)
|
|
55
|
+
- [Usage Examples](#usage-examples-1)
|
|
56
|
+
- [Protect & Unprotect [Single Data]](#protect--unprotect-single-data)
|
|
57
|
+
- [Protect & Unprotect [Bulk Data]](#protect--unprotect-bulk-data)
|
|
58
|
+
- [Connecting to Protegrity AI Team Edition (Cloud Protect)](#connecting-to-protegrity-ai-team-edition-cloud-protect)
|
|
59
|
+
- [Configuration Reference](#configuration-reference)
|
|
60
|
+
7. [Migrating from Protegrity AI Developer Edition to Protegrity AI Team Edition](#migrating-from-protegrity-ai-developer-edition-to-protegrity-ai-team-edition)
|
|
61
|
+
- [The `pty-migrate` CLI](#the-pty-migrate-cli)
|
|
62
|
+
- [Usage Statistics](#usage-statistics)
|
|
63
|
+
8. [Documentation](#documentation)
|
|
64
|
+
9. [Sample Use Case](#sample-use-case)
|
|
65
|
+
10. [License](#license)
|
|
66
|
+
|
|
67
|
+
## Overview
|
|
68
|
+
|
|
69
|
+
This repository contains two powerful modules designed to handle different aspects of data protection:
|
|
70
|
+
|
|
71
|
+
- **protegrity_developer_python** - Focuses on data discovery, classification, and redaction of Personally Identifiable Information (PII) in unstructured text.
|
|
72
|
+
- **appython** - Provides comprehensive data protection and unprotection capabilities for structured data.
|
|
73
|
+
|
|
74
|
+
### Why This Matters
|
|
75
|
+
|
|
76
|
+
Sensitive data shows up in more places than expected, such as logs, payloads, prompts, training sets, and unstructured text. This Python module provides the tools to find and protect that data using tokenization, masking, and discovery, whether the data is in an AI pipeline or a local script. No infrastructure, no UI, just code.
|
|
77
|
+
|
|
78
|
+
- **Developer-first experience:** Open APIs, sample apps, and modular design make it easy to embed data discovery and protection into any Python project.
|
|
79
|
+
|
|
80
|
+
- **Accelerate innovation:** Prototype and validate data discovery and protection strategies in a lightweight, containerized sandbox.
|
|
81
|
+
|
|
82
|
+
- **Enable responsible AI:** Protect sensitive information in training data, prompts, and outputs for GenAI and machine learning workflows.
|
|
83
|
+
|
|
84
|
+
- **Simplify compliance:** Meet regulatory requirements for data privacy with built-in detection and protection capabilities.
|
|
85
|
+
|
|
86
|
+
## Repository Structure
|
|
87
|
+
|
|
88
|
+
```text
|
|
89
|
+
├── LICENSE
|
|
90
|
+
├── README.md
|
|
91
|
+
├── pyproject.toml
|
|
92
|
+
├── pytest.ini
|
|
93
|
+
├── requirements.txt
|
|
94
|
+
├── setup.cfg
|
|
95
|
+
├── src
|
|
96
|
+
│ ├── appython
|
|
97
|
+
│ │ ├── __init__.py
|
|
98
|
+
│ │ ├── protector.py
|
|
99
|
+
│ │ ├── service
|
|
100
|
+
│ │ ├── stats
|
|
101
|
+
│ │ └── utils
|
|
102
|
+
│ ├── protegrity_developer_python
|
|
103
|
+
│ │ ├── __init__.py
|
|
104
|
+
│ │ ├── securefind.py
|
|
105
|
+
│ │ ├── scan.py
|
|
106
|
+
│ │ └── utils
|
|
107
|
+
│ └── pty_migrate
|
|
108
|
+
│ ├── __init__.py
|
|
109
|
+
│ ├── cli.py
|
|
110
|
+
│ ├── check_cmd.py
|
|
111
|
+
│ ├── create_policy_cmd.py
|
|
112
|
+
│ ├── stats_cmd.py
|
|
113
|
+
│ ├── config.py
|
|
114
|
+
│ ├── ppc_client.py
|
|
115
|
+
│ └── payloads
|
|
116
|
+
└── tests
|
|
117
|
+
├── e2e
|
|
118
|
+
│ ├── features
|
|
119
|
+
│ ├── steps
|
|
120
|
+
│ ├── data
|
|
121
|
+
│ ├── utils
|
|
122
|
+
│ ├── conftest.py
|
|
123
|
+
│ └── README.md
|
|
124
|
+
└── unit
|
|
125
|
+
├── appython
|
|
126
|
+
│ ├── bulk
|
|
127
|
+
│ ├── mock
|
|
128
|
+
│ └── single
|
|
129
|
+
├── find_and_secure
|
|
130
|
+
├── pty_migrate
|
|
131
|
+
└── semantic_guardrails
|
|
132
|
+
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## Features
|
|
136
|
+
|
|
137
|
+
### Protegrity Developer Python
|
|
138
|
+
|
|
139
|
+
| Feature | Description |
|
|
140
|
+
|------------------------|-----------------------------------------------------------------------------------------------|
|
|
141
|
+
| **Find and Redact** | Classifies and redacts PII in unstructured text. |
|
|
142
|
+
| **Find and Protect** | Classifies and protects PII in unstructured text using Protegrity protection policies. |
|
|
143
|
+
| **Find and Unprotect** | Restores original PII data from its protected form. |
|
|
144
|
+
| **Cross-Platform Support** | Compatible with **Linux**, **MacOS**, and **Windows**. |
|
|
145
|
+
| **Semantic Guardrail Support** | Scan conversations for PII and risk using Semantic Guardrail API. |
|
|
146
|
+
|
|
147
|
+
### Application Protector Python
|
|
148
|
+
|
|
149
|
+
| Feature | Description |
|
|
150
|
+
|------------------------|-----------------------------------------------------------------------------------------------|
|
|
151
|
+
| **Data Protection** | Protects sensitive structured data using Protegrity policies. |
|
|
152
|
+
| **Data Unprotection** | Restores original data from its protected form. |
|
|
153
|
+
| **Session Management** | Manages secure sessions for protection and unprotection operations. |
|
|
154
|
+
| **Protegrity AI Team Edition support** *(new in 1.2.1)* | Connect to Protegrity AI Team Edition / Cloud Protect endpoints using `PTY_CP_HOST`. |
|
|
155
|
+
| **Pluggable authentication** *(new in 1.2.1)* | Five auth modes: `cognito` (Protegrity AI Developer Edition default), `aws_iam` (SigV4), `bearer_token` (static JWT or one fetched using OAuth2 client-credentials), `mtls`, and `none`. Auto-detected from your environment. |
|
|
156
|
+
| **HTTP resilience** *(new in 1.2.1)* | Configurable timeouts (`PTY_REQUEST_TIMEOUT`) and automatic retries with exponential backoff on transient failures (`PTY_MAX_RETRIES`). |
|
|
157
|
+
| **Local usage statistics** *(new in 1.2.1)* | Anonymous per-operation counts written to `~/.protegrity/usage_stats.json` for migration planning. View with `pty-migrate stats`. |
|
|
158
|
+
| **`pty-migrate` CLI** *(new in 1.2.1)* | One-command migration helper: pre-flight checks, PPC policy creation, and stats reporting. |
|
|
159
|
+
| **Cross-Platform Support** | Compatible with **Linux**, **MacOS**, and **Windows**. |
|
|
160
|
+
|
|
161
|
+
## Getting Started
|
|
162
|
+
|
|
163
|
+
### Prerequisites
|
|
164
|
+
|
|
165
|
+
#### Common Prerequisites
|
|
166
|
+
- [Git](https://git-scm.com/downloads)
|
|
167
|
+
- [Python >= 3.11](https://www.python.org/downloads/)
|
|
168
|
+
- [pip](https://pip.pypa.io/en/stable/installation/)
|
|
169
|
+
- [Python Virtual Environment](https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments/)
|
|
170
|
+
|
|
171
|
+
### Protegrity Developer Python Prerequisites
|
|
172
|
+
|
|
173
|
+
No additional prerequisites required beyond the common ones.
|
|
174
|
+
|
|
175
|
+
### Application Protector Python Prerequisites
|
|
176
|
+
|
|
177
|
+
`appython` can talk to either Protegrity AI Developer Edition (DE, the hosted cloud sandbox) or Protegrity AI Team Edition (TE, your own Cloud Protect deployment). Pick one of the following, the SDK auto-detects which based on the environment variables it sees.
|
|
178
|
+
|
|
179
|
+
#### Option A: Protegrity AI Developer Edition (hosted sandbox)
|
|
180
|
+
Requires an **API Key**, **Email**, and **Password**.
|
|
181
|
+
|
|
182
|
+
**Obtaining Credentials**
|
|
183
|
+
- Visit [https://www.protegrity.com/developers/dev-edition-api](https://www.protegrity.com/developers/dev-edition-api).
|
|
184
|
+
- Register for a developer account.
|
|
185
|
+
- Open your inbox to view the email with your API key and password.
|
|
186
|
+
|
|
187
|
+
#### Option B: Protegrity AI Team Edition / Cloud Protect (own deployment)
|
|
188
|
+
Requires the Cloud Protect endpoint URL plus credentials for one of the supported [auth modes](#connecting-to-protegrity-ai-team-edition-cloud-protect).
|
|
189
|
+
|
|
190
|
+
> No portal registration needed, Protegrity AI Team Edition uses the credentials provided by the Protegrity admin.
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
### Build the protegrity-ai-developer-python module
|
|
194
|
+
|
|
195
|
+
1. Clone the repository.
|
|
196
|
+
```
|
|
197
|
+
git clone https://github.com/Protegrity-AI-Developer-Edition/protegrity-ai-developer-python.git
|
|
198
|
+
```
|
|
199
|
+
2. Navigate to the `protegrity-ai-developer-python` directory.
|
|
200
|
+
3. Activate the Python virtual environment.
|
|
201
|
+
4. Install the dependencies.
|
|
202
|
+
```bash
|
|
203
|
+
pip install -r requirements.txt
|
|
204
|
+
```
|
|
205
|
+
5. Build and install the module by running the following command from the root directory of the repository.
|
|
206
|
+
- Fresh Installation
|
|
207
|
+
```bash
|
|
208
|
+
pip install .
|
|
209
|
+
```
|
|
210
|
+
The installation completes and the success message is displayed.
|
|
211
|
+
- If you already have `protegrity-ai-developer-python` module installed and want to upgrade it, run the following command:
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
pip install --upgrade .
|
|
215
|
+
```
|
|
216
|
+
The installation completes and the success message is displayed.
|
|
217
|
+
|
|
218
|
+
## Protegrity AI Developer Edition Python Module
|
|
219
|
+
> **💡Note:** Ensure that the Protegrity AI Developer Edition is set up and running before installing this module.
|
|
220
|
+
For setup instructions, refer to the [Protegrity AI Developer Edition readme](https://github.com/Protegrity-AI-Developer-Edition/protegrity-ai-developer-edition/blob/main/README.md) or the [Protegrity AI Developer Edition documentation](https://developer.docs.protegrity.com/).
|
|
221
|
+
|
|
222
|
+
### Usage Examples
|
|
223
|
+
|
|
224
|
+
The following examples demonstrate how to use the `protegrity_developer_python` module to discover and handle sensitive data in unstructured text.
|
|
225
|
+
|
|
226
|
+
#### Find and Redact
|
|
227
|
+
|
|
228
|
+
Classify sensitive entities in text and replace them with a masking character.
|
|
229
|
+
|
|
230
|
+
```python
|
|
231
|
+
import protegrity_developer_python
|
|
232
|
+
input_text = "John Doe's SSN is 123-45-6789."
|
|
233
|
+
output_text = protegrity_developer_python.find_and_redact(input_text)
|
|
234
|
+
print(output_text)
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
#### Find and Protect
|
|
238
|
+
|
|
239
|
+
Classify sensitive entities in text and protect them using Protegrity tokenization policies.
|
|
240
|
+
|
|
241
|
+
```python
|
|
242
|
+
import protegrity_developer_python
|
|
243
|
+
|
|
244
|
+
protegrity_developer_python.configure(
|
|
245
|
+
named_entity_map={"PERSON": "NAME", "SOCIAL_SECURITY_ID": "SSN"},
|
|
246
|
+
masking_char="#",
|
|
247
|
+
classification_score_threshold=0.6,
|
|
248
|
+
method="redact",
|
|
249
|
+
enable_logging=True,
|
|
250
|
+
log_level="info"
|
|
251
|
+
)
|
|
252
|
+
|
|
253
|
+
input_text = "John Doe's SSN is 123-45-6789."
|
|
254
|
+
output_text = protegrity_developer_python.find_and_protect(input_text)
|
|
255
|
+
print(output_text)
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
#### Find and Unprotect
|
|
259
|
+
|
|
260
|
+
Restore previously protected text back to its original form using the tokenized output from `find_and_protect`.
|
|
261
|
+
|
|
262
|
+
```python
|
|
263
|
+
import protegrity_developer_python
|
|
264
|
+
|
|
265
|
+
protegrity_developer_python.configure(
|
|
266
|
+
named_entity_map={"PERSON": "NAME", "SOCIAL_SECURITY_ID": "SSN"},
|
|
267
|
+
masking_char="#",
|
|
268
|
+
classification_score_threshold=0.6,
|
|
269
|
+
method="redact",
|
|
270
|
+
enable_logging=True,
|
|
271
|
+
log_level="info"
|
|
272
|
+
)
|
|
273
|
+
|
|
274
|
+
#Pass the output received from find and protect
|
|
275
|
+
input_text = "[PERSON]7ro8 lfU'I[/PERSON] SSN is [SOCIAL_SECURITY_ID]616-16-2210[/SOCIAL_SECURITY_ID]."
|
|
276
|
+
output_text = protegrity_developer_python.find_and_unprotect(input_text)
|
|
277
|
+
print(output_text)
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
## Application Protector Python Module
|
|
281
|
+
|
|
282
|
+
The `appython` module provides tokenization-based protection and unprotection for structured data such as credit card numbers, SSNs, and other sensitive fields. It supports both Protegrity AI Developer Edition and Protegrity AI Team Edition endpoints.
|
|
283
|
+
|
|
284
|
+
### Usage Examples
|
|
285
|
+
Export your credentials which you have received during [Application Protector Python Prerequisites](#prerequisites).
|
|
286
|
+
|
|
287
|
+
```bash
|
|
288
|
+
export DEV_EDITION_EMAIL='<email_used_for_registration>'
|
|
289
|
+
export DEV_EDITION_PASSWORD='<Password_provided_in_email>'
|
|
290
|
+
export DEV_EDITION_API_KEY='<API_key_provided_in_email>'
|
|
291
|
+
```
|
|
292
|
+
#### Protect & Unprotect [Single Data]
|
|
293
|
+
|
|
294
|
+
Protect a single value and then restore it using a data element policy.
|
|
295
|
+
|
|
296
|
+
```python
|
|
297
|
+
from appython import Protector
|
|
298
|
+
|
|
299
|
+
protector = Protector()
|
|
300
|
+
user_name = "superuser"
|
|
301
|
+
data_element = "ccn"
|
|
302
|
+
data = "4111111111111111"
|
|
303
|
+
|
|
304
|
+
session = protector.create_session(user_name)
|
|
305
|
+
protected_data = session.protect(data, data_element)
|
|
306
|
+
print("Protected Data: %s" %protected_data)
|
|
307
|
+
unprotected_data = session.unprotect(protected_data, data_element)
|
|
308
|
+
print("Unprotected Data: %s "%unprotected_data)
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
#### Protect & Unprotect [Bulk Data]
|
|
312
|
+
|
|
313
|
+
Protect and restore multiple values in a single call. Bulk operations also return per-item error codes.
|
|
314
|
+
|
|
315
|
+
```python
|
|
316
|
+
|
|
317
|
+
from appython import Protector
|
|
318
|
+
|
|
319
|
+
protector = Protector()
|
|
320
|
+
user_name = "superuser"
|
|
321
|
+
data_element = "ccn"
|
|
322
|
+
data = ["5555555555554444", "378282246310005","4111111111111111"]
|
|
323
|
+
|
|
324
|
+
session = protector.create_session(user_name)
|
|
325
|
+
protected_data,error_codes = session.protect(data, data_element)
|
|
326
|
+
print("Protected Data: %s" %protected_data)
|
|
327
|
+
unprotected_data,error_codes = session.unprotect(protected_data, data_element)
|
|
328
|
+
print("Unprotected Data: %s "%unprotected_data)
|
|
329
|
+
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
> **💡Note:** You **do not** need Protegrity AI Developer Edition running before executing Application Protector Python Module.
|
|
333
|
+
|
|
334
|
+
### Connecting to Protegrity AI Team Edition (Cloud Protect)
|
|
335
|
+
|
|
336
|
+
When you are ready to move off the hosted Protegrity AI Developer Edition sandbox and point the same code at your own Cloud Protect deployment, set `PTY_CP_HOST` and pick an auth mode. The SDK auto-detects the mode from the environment, `PTY_AUTH_MODE` is only required when the detection is ambiguous.
|
|
337
|
+
|
|
338
|
+
```bash
|
|
339
|
+
# 1. Cloud Protect endpoint (required for every Protegrity AI Team Edition mode)
|
|
340
|
+
export PTY_CP_HOST=https://<your-cloud-protect-host>/pty
|
|
341
|
+
|
|
342
|
+
# 2. Pick an auth mode, examples for the two most common cases:
|
|
343
|
+
|
|
344
|
+
# AWS IAM (SigV4) - default for Cloud Protect behind AWS API Gateway
|
|
345
|
+
export AWS_ACCESS_KEY_ID=...
|
|
346
|
+
export AWS_SECRET_ACCESS_KEY=...
|
|
347
|
+
export AWS_REGION=us-east-1 # or AWS_DEFAULT_REGION
|
|
348
|
+
|
|
349
|
+
# Bearer token (static or fetched using OAuth2 client credentials)
|
|
350
|
+
export PTY_AUTH_MODE=bearer_token
|
|
351
|
+
export PTY_STATIC_TOKEN=<your-jwt>
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
Other supported modes: `mtls` (`PTY_CLIENT_CERT` + `PTY_CLIENT_KEY` + optional `PTY_CA_CERT`) and `none` (network-trust deployments such as internal OpenShift routes). For `bearer_token`, the token can either be supplied directly using `PTY_STATIC_TOKEN` or fetched automatically using the OAuth2 client-credentials grant by setting `PTY_TOKEN_ENDPOINT` + `PTY_CLIENT_ID` + `PTY_CLIENT_SECRET`.
|
|
355
|
+
|
|
356
|
+
After the environment is set, the existing `Protector` / `session.protect()` / `session.unprotect()` code works unchanged.
|
|
357
|
+
|
|
358
|
+
### Configuration Reference
|
|
359
|
+
|
|
360
|
+
All settings can be supplied using environment variables, a YAML file at `~/.protegrity/config.yaml` (override path with `PTY_CONFIG_FILE`), or built-in defaults - resolved in that order. A starter template is available at [`config.yaml.template`](config.yaml.template).
|
|
361
|
+
|
|
362
|
+
```yaml
|
|
363
|
+
# ~/.protegrity/config.yaml — keys mirror the PTY_* env vars but lowercased
|
|
364
|
+
protect_host: https://cp.example.com/pty
|
|
365
|
+
auth_mode: bearer_token
|
|
366
|
+
request_timeout: 30
|
|
367
|
+
max_retries: 3
|
|
368
|
+
# static_token: eyJhbGciOi... # see security note below
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
> **🔒 Secret keys (`static_token`, `client_secret`) are loaded from the YAML file only if the file is `chmod 600`** (owner read/write only - the same rule `ssh` and `~/.pgpass` enforce). If the file is group-readable or world-readable, secret keys are dropped at load time and a warning is printed to stderr; non-secret keys still load normally. On Windows, the POSIX permission check is skipped.
|
|
372
|
+
|
|
373
|
+
| Environment variable | Purpose | Default |
|
|
374
|
+
|---|---|---|
|
|
375
|
+
| `PTY_CP_HOST` | Cloud Protect endpoint URL (Protegrity AI Team Edition). | _none_ |
|
|
376
|
+
| `PTY_AUTH_MODE` | Force a specific auth mode: `cognito`, `aws_iam`, `bearer_token`, `mtls`, `none`. | auto-detect |
|
|
377
|
+
| `PTY_API_VERSION` | Cloud Protect API version segment. | `1` |
|
|
378
|
+
| `PTY_REQUEST_TIMEOUT` | Per-request HTTP timeout in seconds. | `30` |
|
|
379
|
+
| `PTY_MAX_RETRIES` | Retries on transient failures (HTTP 429, 5xx, connection errors) with exponential backoff. `0` disables. | `3` |
|
|
380
|
+
| `PTY_STATIC_TOKEN` | Bearer token for `bearer_token` mode. | _none_ |
|
|
381
|
+
| `PTY_TOKEN_ENDPOINT`, `PTY_CLIENT_ID`, `PTY_CLIENT_SECRET` | OAuth2 client-credentials token fetch for `bearer_token` mode. | _none_ |
|
|
382
|
+
| `PTY_CLIENT_CERT`, `PTY_CLIENT_KEY`, `PTY_CA_CERT` | mTLS material. | _none_ |
|
|
383
|
+
| `PTY_CONFIG_FILE` | Override the YAML config location. | `~/.protegrity/config.yaml` |
|
|
384
|
+
| `DEV_EDITION_EMAIL`, `DEV_EDITION_PASSWORD`, `DEV_EDITION_API_KEY` | Protegrity AI Developer Edition credentials (selects `cognito` mode). | _none_ |
|
|
385
|
+
|
|
386
|
+
## Migrating from Protegrity AI Developer Edition to Protegrity AI Team Edition
|
|
387
|
+
|
|
388
|
+
Version 1.2.1 ships a CLI to make the Protegrity AI Developer Edition (DE) → Protegrity AI Team Edition (TE) transition mechanical rather than manual.
|
|
389
|
+
|
|
390
|
+
### The `pty-migrate` CLI
|
|
391
|
+
|
|
392
|
+
Installed automatically with the package.
|
|
393
|
+
The following three subcommands are available to help you migrate:
|
|
394
|
+
|
|
395
|
+
```bash
|
|
396
|
+
pty-migrate check # Pre-flight readiness validation
|
|
397
|
+
pty-migrate create-policy # Create the equivalent DE policy on your PPC
|
|
398
|
+
pty-migrate stats # View local usage statistics
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
- **`pty-migrate check`** validates SDK version, `PTY_CP_HOST`, auth credentials, and (optionally) round-trips a real `protect` call against your Cloud Protect endpoint. Run it once after exporting your env vars; it prints actionable hints for each missing piece.
|
|
402
|
+
- **`pty-migrate create-policy`** talks to your Protegrity Provisioned Cluster (PPC) using `PTY_PPC_HOST`, `PTY_PPC_USER`, `PTY_PPC_PASSWORD`, and `PTY_WORKBENCH_PASSWORD`, then creates a TE policy whose data elements match the ones DE provided out of the box (`ccn`, `ssn`, `name`, `email`, ...). It is safe to re-run this command.
|
|
403
|
+
- **`pty-migrate stats`** prints a per-data-element, per-day breakdown so you can size your TE deployment based on real DE usage.
|
|
404
|
+
|
|
405
|
+
> **Storing PPC passwords in the YAML file** is supported but **off by default**. To opt in, add `allow_secrets_in_file: true` to `~/.protegrity/config.yaml` **and** `chmod 600` the file; only then will `ppc_password` and `workbench_password` be read from it. Without both, `pty-migrate` ignores those keys and prints a remediation hint - the same model as `~/.pgpass` and `~/.npmrc`. CLI flags (`--ppc-password`) and env vars (`PTY_PPC_PASSWORD`) always take precedence and need no opt-in.
|
|
406
|
+
|
|
407
|
+
### Usage Statistics
|
|
408
|
+
|
|
409
|
+
`appython` writes anonymous local counters (per data element: protect/unprotect/reprotect counts and first/last-used dates) to `~/.protegrity/usage_stats.json` after every `protect`/`unprotect`/`reprotect` call. Collection is active only when the `DEV_EDITION_*` environment variables are set (Developer Edition). The file never leaves your machine and contains no payloads or credentials. Override the location with `PTY_STATS_FILE`, or disable collection with `PTY_STATS=false`.
|
|
410
|
+
|
|
411
|
+
## Documentation
|
|
412
|
+
|
|
413
|
+
- [Protegrity AI Developer Edition documentation](http://developer.docs.protegrity.com/)
|
|
414
|
+
- For API reference and tutorials, visit [Developer Portal](https://www.protegrity.com/developers)
|
|
415
|
+
- For more information about Data Discovery, refer to the [Data Discovery documentation](https://docs.protegrity.com/data-discovery/2.0.0/docs/).
|
|
416
|
+
- For more information about Semantic Guardrails, refer to the [Semantic Guardrails documentation](https://docs.protegrity.com/sem_guardrail/1.1.1/docs/).
|
|
417
|
+
- For more information about Application Protector Python, refer to the [Application Protector Python documentation](https://docs.protegrity.com/protectors/10.0/docs/ap/ap_python/).
|
|
418
|
+
|
|
419
|
+
## Sample Use Case
|
|
420
|
+
|
|
421
|
+
Use this repo to build GenAI applications like chatbots that:
|
|
422
|
+
- Detect Personally Identifiable Information (PII) in prompts using the classifier.
|
|
423
|
+
- Protect, Redact, or Mask sensitive data before processing.
|
|
424
|
+
- Protect and Unprotect structured sensitive data.
|
|
425
|
+
|
|
426
|
+
## License
|
|
427
|
+
|
|
428
|
+
See [LICENSE](https://github.com/Protegrity-AI-Developer-Edition/protegrity-ai-developer-python/blob/main/LICENSE) for terms and conditions.
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
appython/__init__.py,sha256=xS47q5k64k3uFklSRLgAO6MO01_4ciSU0Fe9joMyUng,342
|
|
2
|
+
appython/protector.py,sha256=Ah1yEYppQnZGuFj1Jc1Lv-jPSTTE6A7cdj7e58MeFzk,21928
|
|
3
|
+
appython/service/auth_provider.py,sha256=J4UGOWG7LQCN4tcd_cwRU6hV0P2OmkVHqjy3N-tDYNU,9390
|
|
4
|
+
appython/service/auth_token_provider.py,sha256=iUJxazIYBg12vtvYNAdpLV2pAQ7Gst9NMEWIgLlNd9c,1997
|
|
5
|
+
appython/service/config.py,sha256=jPn6OGA7oAWUEUTXQvOynXedqYERxC0fJWcPXmlwU3U,8025
|
|
6
|
+
appython/service/payload_builder.py,sha256=Kype1tOTGxX-GPylnoqWLgmIIvKAf6xgEl4mhxuryf0,5725
|
|
7
|
+
appython/service/request_handler.py,sha256=5LV1sMcslBfCneqTYo30yPkZkPqpnN9cX5hNcuJIdqk,4427
|
|
8
|
+
appython/service/response_handler.py,sha256=sJAjjBbCAhRQMz3pYWclNfbKxRpozZi3n0uq9rCFux0,3707
|
|
9
|
+
appython/stats/__init__.py,sha256=lQOR40ajkZA1UzqCL1hNoI_M1Cr5KvgTC1o-O6dMTgI,123
|
|
10
|
+
appython/stats/collector.py,sha256=x9xj8sJ1LL31Nnox5Mu9ozNBdKSxmBFINeLl0_qO5GE,3228
|
|
11
|
+
appython/stats/writer.py,sha256=aO2qddTKzlV8F5Ja15rj2p5madP_Nx8q-3V8oAEmDsg,6078
|
|
12
|
+
appython/utils/codec_helper.py,sha256=jKi_JtrwXM3vxqO3LEOQaSOPBLopfPvXogF3m1Fngfk,2787
|
|
13
|
+
appython/utils/constants.py,sha256=aih_HYWqIbk9xvnJpaMJlTiHYoK9YKMtqAZp-70xmcE,19300
|
|
14
|
+
appython/utils/exceptions.py,sha256=kYm0h87HdXk-m-l8COWZ4IYgboG2JJSW4oNzPBmSqA0,5136
|
|
15
|
+
appython/utils/input_preprocessor.py,sha256=PKSBBRfWW1CCUH3F7mBXTlTxvKdho2YSSMVyCjtSClM,13876
|
|
16
|
+
appython/utils/output_postprocessor.py,sha256=DHfw0RsIFe0j5RQrUP6eKckbef_-999eqHyB6Qd030c,4516
|
|
17
|
+
protegrity_ai_developer_python-1.2.1.dist-info/licenses/LICENSE,sha256=IoiK1NbVIo4luQmgub6VzVmz7MCEAW8mwfZrb85a5OE,1076
|
|
18
|
+
protegrity_developer_python/__init__.py,sha256=FxnvOkJO9Py4rJ9kP3qLqG6uTIwrjmmy7aFtVJ9sdgo,198
|
|
19
|
+
protegrity_developer_python/scan.py,sha256=n_Aknjyny2mhutr6RVD0zbEfFAEsjkGDcwUBP03xxf8,1155
|
|
20
|
+
protegrity_developer_python/securefind.py,sha256=-d8sLyfhFWXT27qCzzwfML48kyinyfVle5ygebYNffU,2564
|
|
21
|
+
protegrity_developer_python/utils/ccn_processing.py,sha256=P62p2wOstAmuqaG2eNGfnzcIz_xIN-z5KbFJpepE95s,1623
|
|
22
|
+
protegrity_developer_python/utils/config.py,sha256=NTVm8uWitpmpIS1-ITHMmEC2rVDbmPQZDpgRJNN_p7M,2120
|
|
23
|
+
protegrity_developer_python/utils/constants.py,sha256=CeSSr7zH5VR-PEEkla9EcN1oFuK3QCXXTQgXQCJJoD4,2956
|
|
24
|
+
protegrity_developer_python/utils/discover.py,sha256=W_UA1PGpWcVPaEtyFRTiMx4owA1tgLD1BXfnDiPyNxk,1398
|
|
25
|
+
protegrity_developer_python/utils/logger.py,sha256=OXBYPEWDVJchmmsHusp0s_fpLognO5LTndEWg-4xA5A,623
|
|
26
|
+
protegrity_developer_python/utils/pii_processing.py,sha256=bp4UzivPm6KxqdUHMAnq_DBl2s1SY-_bT-amTauTxf4,10832
|
|
27
|
+
protegrity_developer_python/utils/protector.py,sha256=thh57okEGE4q4Qi-7DtfvKMfO3RdmfV5bpEvwjucz50,527
|
|
28
|
+
protegrity_developer_python/utils/semantic_guardrails.py,sha256=qxe8t1Col76OlpdQuyN1FlhW2AmLlykHhiBJzDI4U54,7310
|
|
29
|
+
protegrity_developer_python/utils/transform.py,sha256=Ni6jFvf10Bv_X-nIjQ8TN2AdKe3M20SzVdSkY6DmTv0,2289
|
|
30
|
+
pty_migrate/__init__.py,sha256=NqCG5wCd29gewAV9WnGNozaHGzsE-2SDkiBkgHz5vto,48
|
|
31
|
+
pty_migrate/check_cmd.py,sha256=CjZDVJGoEHWyNzqaWzad4WGRNArvOsrFgoYxhM-s9qY,36980
|
|
32
|
+
pty_migrate/cli.py,sha256=0qDc71eTem8PnuHI1XEVgyREW8bkUxBLRHHCuN9uF5g,4421
|
|
33
|
+
pty_migrate/config.py,sha256=KeUeHWNGf8DDVjJK2bwGNqCpumCE1vkOB7Ozgzd4LeI,3875
|
|
34
|
+
pty_migrate/create_policy_cmd.py,sha256=cYI-9u9-lMgM7Ut-m2vuKxfaKc1Nhuzu4-0qHRs9r2M,32471
|
|
35
|
+
pty_migrate/ppc_client.py,sha256=EM3bz5srv46bwmiDO_NoC1K55a8A8Enu_nF-N7-tqQ4,15751
|
|
36
|
+
pty_migrate/stats_cmd.py,sha256=Lu1xn-PP3WaxhhKdS0cQDIJEVwQxkno8DsY7R5_kmz0,3004
|
|
37
|
+
pty_migrate/payloads/__init__.py,sha256=EHGhAuqc51FThK0eXgmSs0ji1pesjSL8JjY1QGuoI8k,1442
|
|
38
|
+
pty_migrate/payloads/alphabets.json,sha256=H7lEADq9l950f_DJLFsMlVmv7BN08i1ib4rpvijPskQ,1307
|
|
39
|
+
pty_migrate/payloads/dataelements.json,sha256=L33WVpK4eli6ojGNLQXPcM45MitS4E8qBFzJNuAEz1E,8150
|
|
40
|
+
pty_migrate/payloads/datastores.json,sha256=rf4_sHog9e_fU2i8gz275q81RAs1D8YG039Oxluq14M,140
|
|
41
|
+
pty_migrate/payloads/deploy_policy_ta.json,sha256=z-QKDAgLgwwmovby0oN0PuPDtjqWP--PidPqnJMTilE,47
|
|
42
|
+
pty_migrate/payloads/masks.json,sha256=Bk_bTBpro6dsu5FNMpfnd0TRNFQw5Mt_lvIOecaVcf0,356
|
|
43
|
+
pty_migrate/payloads/members.json,sha256=lt-emkINFBhQbv6Y2bFPbRi38s0xpUfBj5iluyIjZk0,1238
|
|
44
|
+
pty_migrate/payloads/policies.json,sha256=fjB1ejZW-JHwtBL6-bC_uRkPxbdcudqwMrCEf5fbvsg,294
|
|
45
|
+
pty_migrate/payloads/roles.json,sha256=NKVXRzwXhJFn3fn1ahsTBx0i87_UaGHZ2C91TB8k3nY,1466
|
|
46
|
+
pty_migrate/payloads/rules.json,sha256=wxWyxdnTN6HMJuXbRGpURRogqzutxRmYvRVSgDe8KAw,36316
|
|
47
|
+
pty_migrate/payloads/sources.json,sha256=dgI-Wlhh7mjOS9KAmGlcZ5jQpjd5V6D64tYkKRnZoHw,199
|
|
48
|
+
pty_migrate/payloads/trusted_apps.json,sha256=bTu_CCq5HbwKUEXNde0U1QN0CCtHmKY-A4HtxZb_AhU,219
|
|
49
|
+
protegrity_ai_developer_python-1.2.1.dist-info/METADATA,sha256=ZanNOI4pBSHVRtnPRZOJQQDfEbh3QXscvD-CmHaWt5w,22508
|
|
50
|
+
protegrity_ai_developer_python-1.2.1.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
51
|
+
protegrity_ai_developer_python-1.2.1.dist-info/entry_points.txt,sha256=KZc6zpqfiJFy9VFE0PWueV5iYOPh_KPoXkfUx28gqEM,53
|
|
52
|
+
protegrity_ai_developer_python-1.2.1.dist-info/top_level.txt,sha256=655yT3g8VB-IzVYCS0cCxcLDG2YuFTpnzsxZjUdMImE,49
|
|
53
|
+
protegrity_ai_developer_python-1.2.1.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Protegrity USA, Inc.
|
|
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,37 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Module for scanning conversations for security risks using semantic guardrails
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from protegrity_developer_python.utils.logger import get_logger
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
from protegrity_developer_python.utils.semantic_guardrails import (
|
|
9
|
+
MessageRiskRequest,
|
|
10
|
+
scan_messages,
|
|
11
|
+
MessageBatchRiskResponse,
|
|
12
|
+
MessageBatchRiskRequest,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
logger = get_logger()
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def scan_conversation_messages(
|
|
19
|
+
messages: list[MessageRiskRequest],
|
|
20
|
+
) -> MessageBatchRiskResponse:
|
|
21
|
+
"""
|
|
22
|
+
Scan a batch of conversation messages for security risks using the Semantic Guardrails API.
|
|
23
|
+
A risk assessment is executed on messages to ensure they are within the boundaries of expected topics and content.
|
|
24
|
+
s
|
|
25
|
+
Args:
|
|
26
|
+
messages (list[MessageRiskRequest]): List of messages to scan.
|
|
27
|
+
|
|
28
|
+
Returns:
|
|
29
|
+
MessageBatchRiskResponse: Risk assessment for the batch of messages.
|
|
30
|
+
"""
|
|
31
|
+
try:
|
|
32
|
+
request = MessageBatchRiskRequest(messages=messages)
|
|
33
|
+
response = scan_messages(request)
|
|
34
|
+
return response
|
|
35
|
+
except Exception as e:
|
|
36
|
+
logger.error(f"Failed to scan conversation messages: {e}")
|
|
37
|
+
raise
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Module for discovering and redacting, masking or protecting PII entities in text.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from protegrity_developer_python.utils.logger import get_logger
|
|
6
|
+
from protegrity_developer_python.utils.discover import discover
|
|
7
|
+
from protegrity_developer_python.utils.transform import transform_label
|
|
8
|
+
from protegrity_developer_python.utils.constants import get_config
|
|
9
|
+
from protegrity_developer_python.utils.pii_processing import (
|
|
10
|
+
collect_entity_spans,
|
|
11
|
+
protect_data,
|
|
12
|
+
unprotect_data,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
# Get logger instance
|
|
16
|
+
logger = get_logger()
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def find_and_protect(text: str) -> str:
|
|
20
|
+
"""
|
|
21
|
+
Protect (tokenize) PII entities in the input text.
|
|
22
|
+
Uses index-based slicing to ensure precise replacement of PII entities
|
|
23
|
+
at known character positions. This avoids accidental replacement of repeated
|
|
24
|
+
entities and ensures correctness when multiple PII spans are present.
|
|
25
|
+
|
|
26
|
+
Args:
|
|
27
|
+
text (str): Input text to process.
|
|
28
|
+
|
|
29
|
+
Returns:
|
|
30
|
+
str: Protected text.
|
|
31
|
+
"""
|
|
32
|
+
try:
|
|
33
|
+
pii_entities = discover(text)
|
|
34
|
+
logger.debug("Discovered PII entities: %s", pii_entities)
|
|
35
|
+
if pii_entities:
|
|
36
|
+
pii_entity_spans = collect_entity_spans(pii_entities)
|
|
37
|
+
return protect_data(pii_entity_spans, text)
|
|
38
|
+
logger.info("No PII entities found.")
|
|
39
|
+
return text
|
|
40
|
+
except Exception as e:
|
|
41
|
+
logger.error("Failed to process text: %s", e)
|
|
42
|
+
raise
|
|
43
|
+
|
|
44
|
+
def find_and_unprotect(text: str) -> str:
|
|
45
|
+
"""
|
|
46
|
+
Unprotect (detokenize) to get PII entities.
|
|
47
|
+
Uses index-based slicing to ensure precise replacement of detokenized PII entities
|
|
48
|
+
at known character positions.
|
|
49
|
+
|
|
50
|
+
Args:
|
|
51
|
+
text (str): Input text to process.
|
|
52
|
+
|
|
53
|
+
Returns:
|
|
54
|
+
str: Unprotected text.
|
|
55
|
+
"""
|
|
56
|
+
try:
|
|
57
|
+
return unprotect_data(text)
|
|
58
|
+
except Exception as e:
|
|
59
|
+
logger.error("Failed to process text: %s", e)
|
|
60
|
+
raise
|
|
61
|
+
|
|
62
|
+
def find_and_redact(text: str) -> str:
|
|
63
|
+
"""
|
|
64
|
+
Redact or mask PII entities in the input text.
|
|
65
|
+
|
|
66
|
+
When method is "redact" (default), calls the Data Discovery v2 transform/label
|
|
67
|
+
endpoint which discovers PII and returns the redacted text in a single request,
|
|
68
|
+
replacing sensitive values with [ENTITY_TYPE] labels.
|
|
69
|
+
|
|
70
|
+
When method is "mask", uses the discover API to find PII entities and masks
|
|
71
|
+
them with the configured masking_char.
|
|
72
|
+
|
|
73
|
+
Args:
|
|
74
|
+
text (str): Input text to process.
|
|
75
|
+
|
|
76
|
+
Returns:
|
|
77
|
+
str: Redacted or masked text.
|
|
78
|
+
"""
|
|
79
|
+
try:
|
|
80
|
+
return transform_label(text)
|
|
81
|
+
except Exception as e:
|
|
82
|
+
logger.error("Failed to process text: %s", e)
|
|
83
|
+
raise
|