Skip to main content

Enterprise-grade reversible anonymization using Google Cloud DLP

Project description

Reversible Anonymizer

A Python package for reversible text anonymization using Google Cloud services.

Installation

bash pip install reversible-anonymizer

Prerequisites

Google Cloud project with the following services enabled:

Cloud DLP API (dlp.googleapis.com)

Cloud Firestore API (firestore.googleapis.com)
AI Platform API (aiplatform.googleapis.com)
Google Cloud credentials configured

Usage

from reversible_anonymizer import ReversibleAnonymizer

Initialize with default settings

anonymizer = ReversibleAnonymizer(project="your-project-id")

Or customize the settings

anonymizer = ReversibleAnonymizer( project="your-project-id", info_types=[ {"name": "PERSON_NAME"}, {"name": "EMAIL_ADDRESS"} ], collection_name="custom_mappings", location="us-central1" )

Anonymize text

original_text = "Hello, my name is John Doe" anonymized_text = anonymizer.anonymize(original_text) print(f"Anonymized: {anonymized_text}")

De-anonymize text

original_text = anonymizer.deanonymize(anonymized_text) print(f"De-anonymized: {original_text}")

Error Handling

The package provides custom exceptions:

ServiceNotEnabledError: Raised when required Google Cloud services are not enabled AnonymizationError: Raised when anonymization fails DeAnonymizationError: Raised when de-anonymization fails

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Create a test file:

tests/test_anonymizer.py:

import pytest
from reversible_anonymizer import ReversibleAnonymizer
from reversible_anonymizer.exceptions import ServiceNotEnabledError

def test_anonymizer_initialization():
    with pytest.raises(ServiceNotEnabledError):
        ReversibleAnonymizer("invalid-project")

def test_custom_info_types():
    anonymizer = ReversibleAnonymizer(
        "your-project-id",
        info_types=[{"name": "EMAIL_ADDRESS"}],
        check_services=False
    )
    assert anonymizer.info_types == [{"name": "EMAIL_ADDRESS"}]

# Add more tests as needed
To use the package:

Install the package:
pip install reversible-anonymizer
Use in your code:
from reversible_anonymizer import ReversibleAnonymizer

try:
    # Initialize with custom settings
    anonymizer = ReversibleAnonymizer(
        project="your-project-id",
        info_types=[
            {"name": "PERSON_NAME"},
            {"name": "EMAIL_ADDRESS"},
            {"name": "PHONE_NUMBER"}
        ],
        collection_name="custom_mappings"
    )

    # Anonymize text
    original_text = "Hello, my name is John Doe. Call me at 123-456-7890"
    anonymized_text = anonymizer.anonymize(original_text)
    print(f"Anonymized: {anonymized_text}")

    # De-anonymize text
    original_text = anonymizer.deanonymize(anonymized_text)
    print(f"De-anonymized: {original_text}")

except Exception as e:
    print(f"Error: {str(e)}")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

reversible_anonymizer-1.0.6.tar.gz (28.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

reversible_anonymizer-1.0.6-py3-none-any.whl (31.2 kB view details)

Uploaded Python 3

File details

Details for the file reversible_anonymizer-1.0.6.tar.gz.

File metadata

  • Download URL: reversible_anonymizer-1.0.6.tar.gz
  • Upload date:
  • Size: 28.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for reversible_anonymizer-1.0.6.tar.gz
Algorithm Hash digest
SHA256 1fac783ccf02655b6ca1716fdcbc38e6e1e78b855fc2e19887ceda3f4f0450cd
MD5 40ff3854a6c834da77f5dabad16cec16
BLAKE2b-256 5e9b691133c19efc6215dfb8e0acadc10dce1a0abc5c5c7f2cf63fae9318b9d6

See more details on using hashes here.

File details

Details for the file reversible_anonymizer-1.0.6-py3-none-any.whl.

File metadata

File hashes

Hashes for reversible_anonymizer-1.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 57f01ee3bd43d488dfc3f2c73b44ed1938fddacf09cf7ec8e5baeeeaec294ecb
MD5 a9c900f3d34781b54c640bc7b8085f69
BLAKE2b-256 4d41c5b51996d2438aca2a63d896aa67611e0beb2b798063767ed7adcadb9089

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page