Running the sample application

A sample application to use Developer Edition.

In the Developer Edition, a user uploads a file using the sample application, which is processed by the Data Discovery container. The containers detect sensitive data. A Python module then redacts, masks, or protects and unprotects the data. The sanitized file is saved to a configured location. For more information about the sample application, refer to Sample application.

Use the steps provided here to run the application end-to-end. If required, run the APIs and functions provided for performing specific tasks. For more information about the identification APIs, refer to Data Discovery API.

Running the applications

Applications are provided out-of-the-box to test and understand the capabilities of Developer Edition.

Running the sample find application

  1. Open a command prompt.

  2. Navigate to the directory where Developer Edition is cloned.

  3. Run the sample application using the following command.

    python samples/sample-app-find.py
    
  4. View the output of the files processed on the screen. The output displays a list of sensitive items in the source file.

“Sample application output”

  1. View the processed output file in the output directory.

Running the sample find and redact application

  1. Open a command prompt.

  2. Navigate to the directory where Developer Edition is cloned.

  3. Run the sample application using the following command.

    python samples/sample-app-find-and-redact.py
    
  4. View the output of the files processed on the screen. The output displays a list of sensitive items in the source file. It also displays the location and name of the output file with the redacted output.

“Sample application output”

  1. View the processed output file in the output directory.

Running Semantic Guardrail

  1. Open a command prompt.
  2. Navigate to the directory where Developer Edition is cloned.
  3. Run the following command to test Semantic Guardrail. The following command submits a multi-turn conversation for analysis. One for semantic and a second one for PII processing.
python semantic-guardrail/sample-guardrail-python.py

“Sample application output”

Running the sample find and protect application

  1. Ensure that the required credentials are obtained and environment variables specified, using the steps from Optional - Obtaining access to the Developer Edition API Service.

  2. Open a command prompt.

  3. Navigate to the directory where Developer Edition is cloned.

  4. Run the sample application using the following command.

    python samples/sample-app-find-and-protect.py
    
  5. View the output of the files processed on the screen. The output displays the protected data and unprotected data.

“Sample application output”

  1. View the processed output file in the output directory. The samples/sample-data/output-protect.txt file is generated with the protected, that is tokenized-like, values.

  2. To obtain the original data, run the following command.

    python samples/sample-app-find-and-unprotect.py
    

    This reads the samples/sample-data/output-protect.txt file and produces the samples/sample-data/output-unprotect.txt file with original values.

Running the script for protecting data

The sample-app-protection.py showcases the various scenarios for protecting, unprotecting, and reprotecting data.

Understanding Users and Roles

The users and roles are built-in for impersonate testing. Leverage any of the preconfigured users to showcase Protegrity’s Role-Based Access Controls. Using a different user will result in distinct views over sensitive data. Some users will only be able to protect data but will not be able to reverse the operation. Some users will only be able to re-identify selected attributes.

To use any of the roles, simply pass the chosen value to the payload in the user attribute during the protect or unprotect operation. If the user is not specified, the request will default to superuser.

The following roles and users have been configured and are available for use:

RoleUserDescription
ADMINadmin, devops, jay.banerjeeThe role can protect all data but cannot unprotect. Upon an unprotection attempt they will be displayed protected values.
FINANCEfinance, robin.goodwillThe role can unprotect all PII and PCI data. The role cannot protect any data. When attempting to unprotect data without authorization, they will be displayed nulls.
MARKETINGmarketing , merlin.ishidaThe role can unprotect some PII data that is required for analytical research and campaign outreach. When attempting to unprotect data without authorization, they will be displayed nulls. The role cannot protect any data.
HRhr , paloma.torresThe role can unprotect all PII data but cannot view any PCI data. When attempting to unprotect data without authorization, they will be displayed nulls. The role cannot protect any data.
OTHERsuperuserThe role can perform any protect and unprotect operation. The role has been made available for testing only – we strongly advise against creating superuser roles in your environments.

Additionally, you may type in any user name to simulate unauthorized user behavior.

Understanding the Data Elements

A list of supported data element is provided here. For a mapping of the Data Element and the Entity Type, refer to Supported Sensitive Entity Types.

NameDescription
nameProtect or unprotect name of a person
name_deProtect or unprotect name of a person in the German language
name_frProtect or unprotect name of a person in the French language
addressProtect or unprotect an address
address_deProtect or unprotect an address in the German language
address_frProtect or unprotect an address in the French language
cityProtect or unprotect a town or city
city_deProtect or unprotect a town or city name in the German language
city_frProtect or unprotect a town or city name in the French language
postcodeProtect or unprotect a postal code with digits and characters
zipcodeProtect or unprotect a postal code with digits only
phoneProtect or unprotect a phone number
emailProtect or unprotect an email
datetimeProtect or unprotect all components of a datetime string date, month, year, and time
datetime_ycProtect or unprotect a datetime string. Year will be in clear.
intProtect or unprotect a 4-byte integer string
ninProtect or unprotect a National Insurance Number UK
ssnProtect or unprotect a Social Security Number US
ccnProtect or unprotect a Credit Card Number
ccn_binProtect or unprotect a Credit Card Number. Leaves 8-digit BIN in the clear.
passportProtect or unprotect a passport number
ibanProtect or unprotect an International Banking Account Number
iban_ccProtect or unprotect an International Banking Account Number. Leaves letters in the clear.
stringProtect or unprotect a string
numberProtect or unprotect a number
textProtect or unprotect text using encryption

Testing the sample file

  1. Ensure that the required credentials are obtained and environment variables specified, using the steps from Optional - Obtaining access to the Developer Edition API Service.

  2. Open a command prompt.

  3. Navigate to the directory where Developer Edition is cloned.

  4. Protect data using the following command.

    python samples/sample-app-protection.py --input_data "John Smith" --policy_user superuser --data_element name --protect
    
  5. Unprotect the data obtained from the earlier step using the following command.

    python samples/sample-app-protection.py --input_data "<protected_data>" --policy_user superuser --data_element name --unprotect
    
  6. View the protected and unprotected output.

    “Sample application output”

  7. Encrypt data using the following command.

    python samples/sample-app-protection.py --input_data "John Smith" --policy_user superuser --data_element text --enc
    
  8. Decrypt the data obtained from the earlier step using the following command.

    python samples/sample-app-protection.py --input_data "<encrypted_data>" --policy_user superuser --data_element text --dec
    
  9. View the encrypted and decrypted output.

  10. Use the help command for more information about using the sample file.

    python samples/sample-app-protection.py --help
    
Additional use cases for user role behavior for data protection

This section demonstrates the expected behavior of various user roles when running the sample-app-protection.py. Each section describes the permissions and restrictions for a role, followed by example commands and their outputs.


ADMIN

Users: admin, devops, jay.banerjee

This role can protect all data but cannot unprotect. When attempting to unprotect, protected values are displayed.

python sample-app-protection.py --input_data "4321567898765432" --policy_user admin --data_element ccn --protect --unprotect

Protected Data: 2839874358655598
Unprotected Data: 283987435865559
python sample-app-protection.py --input_data "4321567898765432" --policy_user devops --data_element ccn --protect --unprotect

Protected Data: 2839874358655598
Unprotected Data: 283987435865559
python sample-app-protection.py --input_data "4321567898765432" --policy_user jay.banerjee --data_element ccn --protect --unprotect

Protected Data: 2839874358655598
Unprotected Data: 283987435865559

FINANCE

Users: finance, robin.goodwill

This role can unprotect all PII and PCI data. The role cannot protect any data. When attempting to unprotect data without authorization, the value Null is displayed.

python sample-app-protection.py --input_data "Protegrity$" --policy_user finance --data_element name --protect

Error: 3, The user does not have the appropriate permissions to perform the requested operation.
python sample-app-protection.py --input_data "Protegrity$" --policy_user robin.goodwill --data_element name --protect

Error: 3, The user does not have the appropriate permissions to perform the requested operation.
python sample-app-protection.py --input_data "1998/10/11" --policy_user finance --data_element datetime  --unprotect

Unprotected Data: None
python sample-app-protection.py --input_data "1998/10/11" --policy_user robin.goodwill --data_element datetime  --unprotect

Unprotected Data: None

MARKETING

Users: marketing, merlin.ishida

This role can unprotect some PII data that is required for analytical research and campaign outreach. The role cannot protect any data. When attempting to unprotect data without authorization, the value Null is displayed.

python sample-app-protection.py --input_data "Washington, D.C." --policy_user marketing --data_element city --protect

Error: 3, The user does not have the appropriate permissions to perform the requested operation.
python sample-app-protection.py --input_data "Washington, D.C." --policy_user merlin.ishida --data_element city --protect

Error: 3, The user does not have the appropriate permissions to perform the requested operation.
python sample-app-protection.py --input_data "DnZQHKcpVJ, J.G." --policy_user marketing --data_element city --unprotect

Unprotected Data: Washington, D.C.
python sample-app-protection.py --input_data "DnZQHKcpVJ, J.G." --policy_user merlin.ishida --data_element city --unprotect

Unprotected Data: Washington, D.C.

HR

Users: hr, paloma.torres

This role can unprotect all PII data but cannot view any PCI data. The role cannot protect any data. When attempting to unprotect data without authorization, the value Null is displayed.

python sample-app-protection.py --input_data "John Doe" --policy_user hr --data_element name --protect

Error: 3, The user does not have the appropriate permissions to perform the requested operation.
python sample-app-protection.py --input_data "John Doe" --policy_user paloma.torres --data_element name --protect

Error: 3, The user does not have the appropriate permissions to perform the requested operation.
python sample-app-protection.py --input_data "CIF123654987" --policy_user hr --data_element passport --unprotect

Unprotected Data: None
python sample-app-protection.py --input_data "CIF123654987" --policy_user paloma.torres --data_element passport --unprotect

Unprotected Data: None

OTHER

User: superuser

This role can perform any protect and unprotect operation. The role is only made available for testing. It is strongly advised against creating superuser roles in an environment.

python sample-app-protection.py --input_data "4321567898765432" --policy_user superuser --data_element ccn --protect --unprotect

Protected Data: 2839874358655598
Unprotected Data: 4321567898765432

Data Discovery API

Classify API.

Semantic Guardrail APIs

Using the Semantic Guardrail API

Application Protector Python APIs

The various APIs of the AP Python


Last modified : September 26, 2025