Protegrity Anonymization Python SDK Installation

Steps to install Python SDK.

Python SDK

The Anonymization service can be accessed programmatically using the Python SDK.

1. Obtain an Authentication Token

export GATEWAY_URL=https://<YOUR_GATEWAY_HOSTNAME>
# Gateway URL  can be obtained using the following command:
# export GATEWAY_URL="https://$(kubectl get configmap/nfa-config -n default -o jsonpath='{.data.FQDN}')"
# Login with the Anon user and get token
TOKEN=$(curl -sk -X POST "${GATEWAY_URL}/api/v1/auth/login/token" \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d 'loginname=anonymization_admin&password=StrongPassword123!' \
-D - -o /dev/null | grep -i 'pty_access_jwt_token' | awk '{print $2}' | tr -d '\r\n')

echo "Access Token: $TOKEN"

Note: Replace default credentials and URLs for production environments.

2. Obtain the Anonymization Python SDK wheel file

curl -sk -X GET -H "Authorization: Bearer $TOKEN" "${GATEWAY_URL}/pty/anonymization/v2/whl" -o anonsdk_dir-1.4.1-py3-none-any.whl

3. Install the SDK in a Python Virtual Environment

pip install anonsdk_dir-1.4.1-py3-none-any.whl

4. Configure SDK Storage

The Python SDK uses intermediate storage to securely exchange data with the Anonymization REST API. Ensure the S3 bucket configured for the Anonymization REST API is accessible to the Python SDK.

Configure the bucket name and access options in the config.yaml file located at $HOME/.pty_anon/config.yaml.

If the directory or file does not exist, create it using the following command.

mkdir -p $HOME/.pty_anon
touch $HOME/.pty_anon/config.yaml

Update config.yaml with the following values:

STORAGE:
  ACCESS_TYPE: 'KEYS'
  CLUSTER_ENDPOINT: s3.amazonaws.com
  BUCKET_NAME: '<YOUR_BUCKET_NAME>'
  ACCESS_KEY: '<AWS_ACCESS_KEY>' 
  SECRET_KEY: '<AWS_SECRET>'

Note: Use static access keys. Temporary session credentials are not supported.

5. Test the Anonymization Python SDK

import anonsdk as asdk

conn = asdk.Connection("<GATEWAY_URL>/", security=asdk.PPCBasedSecurity("anonymization_admin", "StrongPassword123!"))

For example,

conn = asdk.Connection("https://eclipse.aws.protegrity.com/",  security=asdk.PPCBasedSecurity("anonymization_admin", "StrongPassword123!"))

If there is an error while establishing a connection, error appears. Else the connection is established successfully. For more information about SDK usage, refer to Building the request using the Python SDK.


Last modified : April 09, 2026