Python module for integrating Protegrity's Data Discovery and Protection APIs into GenAI and traditional applications.
Project description
Welcome to the protegrity-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 requirement.
๐กNote: This module should be built and used only if you intend to modify the source code or default behavior.
Table of Contents
- Overview
- Repository Structure
- Features
- Getting Started
- Protegrity AI Developer Edition Python Module
- Application Protector Python module
- Documentation
- Sample Use Case
- License
Overview
This repository contains two powerful modules designed to handle different aspects of data protection:
- protegrity_developer_python - Focuses on data discovery, classification, and redaction of Personally Identifiable Information (PII) in unstructured text
- appython - Provides comprehensive data protection and unprotection capabilities for structured data
Why This Matters
Sensitive data shows up in more places than you'd expect โ logs, payloads, prompts, training sets, and unstructured text. This Python module gives you tools to find and protect that data using tokenization, masking, and discovery โ whether it's in an AI pipeline or a local script. No infrastructure, no UI, just code.
-
Developer-first experience: Open APIs, sample apps, and modular design make it easy to embed data discovery and protection into any Python project.
-
Accelerate innovation: Prototype and validate data discovery and protection strategies in a lightweight, containerized sandbox.
-
Enable responsible AI: Protect sensitive information in training data, prompts, and outputs for GenAI and machine learning workflows.
-
Simplify compliance: Meet regulatory requirements for data privacy with built-in detection and protection capabilities.
Repository Structure
โโโ LICENSE
โโโ README.md
โโโ pyproject.toml
โโโ pytest.ini
โโโ requirements.txt
โโโ setup.cfg
โโโ src
โ โโโ appython
โ โ โโโ __init__.py
โ โ โโโ protector.py
โ โ โโโ service
โ โ โโโ utils
โ โโโ protegrity_developer_python
โ โโโ __init__.py
โ โโโ securefind.py
โ โโโ scan.py
โ โโโ utils
โโโ tests
โโโ e2e
โ โโโ features
โ โโโ steps
โ โโโ data
โ โโโ utils
| โโโ conftest.py
โ โโโ README.md
โโโ unit
โโโ appython
โ โโโ bulk
โ โโโ mock
โ โโโ single
โโโ find_and_secure
โโโ semantic_guardrail
Features
Protegrity Developer Python
| Feature | Description |
|---|---|
| Find and Redact | Classifies and redacts Personally Identifiable Information (PII) in unstructured text. |
| Find and Protect | Classifies and protects Personally Identifiable Information (PII) in unstructured text using Protegrity protection policies. |
| Find and Unprotect | Restores original Personally Identifiable Information (PII) data from its protected form. |
| Cross-Platform Support | Compatible with Linux, Windows, and MacOS. |
| Semantic Guardrail Support | Scan conversations for PII and risk using Semantic Guardrail API. |
Application Protector Python
| Feature | Description |
|---|---|
| Data Protection | Protects sensitive structured data using Protegrity policies. |
| Data Unprotection | Restores original data from its protected form. |
| Session Management | Manages secure sessions for protection and unprotection operations. |
| Cross-Platform Support | Compatible with Linux, Windows, and MacOS. |
Getting Started
Prerequisites
Common Prerequisites
Protegrity Developer Python Prerequisites
No additional prerequisites required beyond the common ones.
Application Protector Python Prerequisites
-
In addition to the common prerequisites, appython requires API Key, Email, and Password
Obtaining Credentials
Protegrity AI Developer Edition Portal Registration
- Visit https://www.protegrity.com/developers/get-api-credentials
- Register for a developer account.
- You will receive an email with your API Key and Password.
Build the protegrity-developer-python module
- Clone the repository.
git clone https://github.com/Protegrity-Developer-Edition/protegrity-developer-python.git - Navigate to the
protegrity-developer-python - Activate the Python virtual environment.
- Install the dependencies.
pip install -r requirements.txt
- Build and install the module by running the following command from the root directory of the repository.
-
Fresh Installation
pip install .
The installation completes and the success message is displayed.
-
If you already have
protegrity-developer-pythonmodule installed and want to upgrade it, run the following command:pip install --upgrade .
The installation completes and the success message is displayed.
Protegrity AI Developer Edition Python Module
๐กNote: Ensure that the Protegrity AI Developer Edition is running before installing this module. For setup instructions, please refer to the documentation here.
Usage Examples
Find and Redact
import protegrity_developer_python
protegrity_developer_python.configure(
endpoint_url="http://localhost:8580/pty/data-discovery/v1.1/classify",
named_entity_map={"PERSON": "NAME", "SOCIAL_SECURITY_ID": "SSN"},
masking_char="#",
classification_score_threshold=0.6,
method="redact",
enable_logging=True,
log_level="info"
)
input_text = "John Doe's SSN is 123-45-6789."
output_text = protegrity_developer_python.find_and_redact(input_text)
print(output_text)
Find and Protect
import protegrity_developer_python
protegrity_developer_python.configure(
endpoint_url="http://localhost:8580/pty/data-discovery/v1.1/classify",
named_entity_map={"PERSON": "NAME", "SOCIAL_SECURITY_ID": "SSN"},
masking_char="#",
classification_score_threshold=0.6,
method="redact",
enable_logging=True,
log_level="info"
)
input_text = "John Doe's SSN is 123-45-6789."
output_text = protegrity_developer_python.find_and_protect(input_text)
print(output_text)
Find and Unprotect
import protegrity_developer_python
protegrity_developer_python.configure(
endpoint_url="http://localhost:8580/pty/data-discovery/v1.1/classify",
named_entity_map={"PERSON": "NAME", "SOCIAL_SECURITY_ID": "SSN"},
masking_char="#",
classification_score_threshold=0.6,
method="redact",
enable_logging=True,
log_level="info"
)
#Pass the output received from find and protect
input_text = "[PERSON]7ro8 lfU'I[/PERSON] SSN is [SOCIAL_SECURITY_ID]616-16-2210[/SOCIAL_SECURITY_ID]."
output_text = protegrity_developer_python.find_and_unprotect(input_text)
print(output_text)
Application Protector Python Module
Usage Examples
Export your credentials which you have received during Application Protector Python Prerequisites
export DEV_EDITION_EMAIL='<email_used_for_registration>'
export DEV_EDITION_PASSWORD='<Password_provided_in_email>'
export DEV_EDITION_API_KEY='<API_key_provided_in_email>'
Protect & Unprotect [Single Data]
from appython import Protector
protector = Protector()
user_name = "superuser"
data_element = "ccn"
data = "4111111111111111"
session = protector.create_session(user_name)
protected_data = session.protect(data, data_element)
print("Protected Data: %s" %protected_data)
unprotected_data = session.unprotect(protected_data, data_element)
print("Unprotected Data:%s "%unprotected_data)
Protect & Unprotect [Bulk Data]
from appython import Protector
protector = Protector()
user_name = "superuser"
data_element = "ccn"
data = ["5555555555554444", "378282246310005","4111111111111111"]
session = protector.create_session(user_name)
protected_data,error_codes = session.protect(data, data_element)
print("Protected Data: %s" %protected_data)
unprotected_data,error_codes = session.unprotect(protected_data, data_element)
print("Unprotected Data:%s "%unprotected_data)
๐กNote: You do not need Protegrity AI Developer Edition running before executing Application Protector Python Module.
Documentation
- Protegrity AI Developer Edition documentation
- For API reference and tutorials, visit Developer Portal
- For more information about Data Discovery, refer to the Data Discovery documentation.
- For more information about Semantic Guardrails, refer to the Semantic Guardrails documentation.
- For more information about Application Protector Python, refer to the Application Protector Python documentation.
Sample Use Case
Use this repo to build GenAI applications like chatbots that:
- Detect Personally Identifiable Information (PII) in prompts using the classifier
- Protect, Redact, or Mask sensitive data before processing
- Protect and Unprotect structured sensitive data
License
See LICENSE for terms and conditions.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file protegrity_developer_python-1.1.1-py3-none-any.whl.
File metadata
- Download URL: protegrity_developer_python-1.1.1-py3-none-any.whl
- Upload date:
- Size: 38.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b047b5c1130346672bedd29ef583f4bce22c1457731a3ab682c676ec2470e657
|
|
| MD5 |
b63427911df1332b742420e27294ff24
|
|
| BLAKE2b-256 |
bd72e66b6684af402d92bfcc8f785ce7e49768bcaf6bec368d6612cf99de6728
|