{"id":494,"library":"google-cloud-dlp","title":"Google Cloud DLP","description":"The `google-cloud-dlp` Python client library provides programmatic access to the Google Cloud Data Loss Prevention (DLP) API, now part of Sensitive Data Protection. It enables scanning, discovering, classifying, and redacting privacy-sensitive data (like PII) within text, images, and various Google Cloud storage repositories such as BigQuery and Cloud Storage. The library is currently at version 3.34.0 and follows the continuous release cadence typical of Google Cloud client libraries, offering frequent updates and enhancements.","status":"active","version":"3.34.0","language":"python","source_language":"en","source_url":"https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-dlp","tags":["google-cloud","dlp","data-loss-prevention","privacy","security"],"install":[{"cmd":"pip install google-cloud-dlp","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Core library for Google Cloud API interactions.","package":"google-api-core"},{"reason":"Used for Pythonic wrappers around Protobuf messages.","package":"proto-plus"},{"reason":"Core Protobuf library for API communication.","package":"protobuf"}],"imports":[{"note":"The client is typically accessed via the versioned submodule `dlp_v2`.","wrong":"from google.cloud.dlp import DlpServiceClient","symbol":"DlpServiceClient","correct":"from google.cloud import dlp_v2\nclient = dlp_v2.DlpServiceClient()"}],"quickstart":{"code":"import os\nfrom google.cloud import dlp_v2\nfrom google.cloud.dlp_v2 import types\n\ndef inspect_text(project_id: str, text_content: str):\n    \"\"\"\n    Inspects a string of text for sensitive data using Google Cloud DLP.\n\n    Args:\n        project_id: The Google Cloud project ID.\n        text_content: The string to inspect.\n    \"\"\"\n    if not project_id:\n        print(\"GOOGLE_CLOUD_PROJECT environment variable or project_id not set.\")\n        return\n\n    client = dlp_v2.DlpServiceClient()\n\n    # Construct the item to inspect\n    item = {\"value\": text_content}\n\n    # The info types to search for in the content.\n    # See https://cloud.google.com/sensitive-data-protection/docs/infotypes-reference\n    info_types = [{\"name\": \"EMAIL_ADDRESS\"}, {\"name\": \"PHONE_NUMBER\"}]\n\n    # The minimum likelihood to constitute a match.\n    min_likelihood = types.Likelihood.POSSIBLE\n\n    # Configuration for the inspection request\n    inspect_config = {\n        \"info_types\": info_types,\n        \"min_likelihood\": min_likelihood,\n        \"limits\": {\"max_findings_per_request\": 0} # 0 for no limit\n    }\n\n    # Construct the parent path\n    parent = f\"projects/{project_id}\"\n\n    # Call the API\n    try:\n        response = client.inspect_content(\n            request={\n                \"parent\": parent,\n                \"inspect_config\": inspect_config,\n                \"item\": item,\n            }\n        )\n\n        if response.result.findings:\n            print(\"Findings:\")\n            for finding in response.result.findings:\n                if finding.quote:\n                    print(f\"  Quote: {finding.quote}\")\n                print(f\"  Info type: {finding.info_type.name}\")\n                print(f\"  Likelihood: {types.Likelihood(finding.likelihood).name}\")\n        else:\n            print(\"No findings.\")\n\n    except Exception as e:\n        print(f\"Error during DLP inspection: {e}\")\n\nif __name__ == \"__main__\":\n    # Set your Google Cloud Project ID as an environment variable or replace 'your-gcp-project-id'\n    project = os.environ.get(\"GOOGLE_CLOUD_PROJECT\", \"\") \n    if not project:\n        raise ValueError(\"Please set the GOOGLE_CLOUD_PROJECT environment variable or provide a project_id.\")\n    \n    sensitive_text = \"My email is test@example.com and my phone number is (123) 456-7890.\"\n    inspect_text(project, sensitive_text)\n","lang":"python","description":"This quickstart demonstrates how to initialize the DLP client and inspect a string of text for sensitive information like email addresses and phone numbers. Ensure your Google Cloud Project ID is set as the `GOOGLE_CLOUD_PROJECT` environment variable for authentication, and the DLP API is enabled for your project."},"warnings":[{"fix":"Enable the DLP API in your GCP project. Create a service account with `roles/dlp.user`, download its JSON key, and set `export GOOGLE_APPLICATION_CREDENTIALS=/path/to/key.json`.","message":"Authentication requires enabling the DLP API and typically using Application Default Credentials (ADC) with a service account. Set the `GOOGLE_APPLICATION_CREDENTIALS` environment variable to the path of your service account key file, and ensure the service account has the `roles/dlp.user` role. API keys are supported for some methods but not for `deidentify` or `reidentify` requests that use Cloud Key Management Service (KMS) wrapped keys.","severity":"gotcha","affected_versions":"All"},{"fix":"Upgrade your Python environment to version 3.7 or newer.","message":"Python 3.6 and older versions are no longer supported. The last version compatible with Python 2.7 was `google-cloud-dlp==1.1.0`.","severity":"breaking","affected_versions":"<3.7"},{"fix":"Implement robust access controls for any stored logs generated by the `google-cloud-dlp` client library.","message":"The library's logging functionality can emit RPC events that may contain sensitive information. Access to these logs should be restricted, and users should not depend on the immutability of log message content or levels.","severity":"gotcha","affected_versions":"All"},{"fix":"The recommended solution is to bypass the proxy for Google API endpoints by enabling Private Google Access in your VPC subnet.","message":"When operating behind a TLS-intercepting proxy, gRPC-based Google Cloud client libraries (including DLP) may encounter SSL certificate trust issues.","severity":"gotcha","affected_versions":"All"},{"fix":"Always construct the `parent` argument correctly using `client.project_path(project_id)` or `f'projects/{project_id}'`.","message":"Many DLP API operations, such as `inspect_content` and `deidentify_content`, require a `parent` argument in the format `projects/{project_id}`. Forgetting this or providing an incorrect project ID will result in errors.","severity":"gotcha","affected_versions":"All"},{"fix":"Navigate to the Google Cloud Console's 'APIs & Services' dashboard and enable the 'Cloud Data Loss Prevention API' for your project.","message":"It is crucial to explicitly enable the Cloud Data Loss Prevention API in your Google Cloud project via the GCP Console or `gcloud services enable dlp.googleapis.com` before using the client library. Otherwise, you will receive `API not enabled` errors.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-05-12T14:19:24.512Z","next_check":"2026-06-26T00:00:00.000Z","problems":[{"fix":"1. Enable the DLP API for your project: `gcloud services enable dlp.googleapis.com`. 2. Ensure your service account has the `roles/dlp.user` (DLP User) role or a custom role with `dlp.jobs.create`, `serviceusage.services.use` permissions.","cause":"The Google Cloud Data Loss Prevention (DLP) API is not enabled for the specified Google Cloud project, or the service account lacks the necessary permissions to access the API.","error":"google.api_core.exceptions.PermissionDenied: 403 Permission denied. The DLP API has not been used in project [PROJECT_ID] before or it is disabled."},{"fix":"Ensure the `google-cloud-dlp` library is correctly installed in your active Python environment: `pip install google-cloud-dlp`. If using a virtual environment, activate it first. If the error persists, check for conflicting package versions or try reinstalling Python.","cause":"This error typically indicates that the `google-cloud-dlp` library is not installed, or there's a Python environment issue where the installed package is not accessible, or an older version of the library is installed with a different module structure.","error":"ModuleNotFoundError: No module named 'google.cloud.dlp_v2'"},{"fix":"Upgrade your `google-cloud-dlp` library to the latest version or a compatible version. If you are following specific code samples, ensure your library version matches the documentation's requirements. `pip install --upgrade google-cloud-dlp` or `pip install google-cloud-dlp==<compatible_version>`.","cause":"This error often occurs due to a version incompatibility between the `google-cloud-dlp` library and the code being executed. Methods or attributes might have changed in different library versions.","error":"AttributeError: 'DlpServiceClient' object has no attribute 'project_path'"},{"fix":"Reduce the rate of your API requests, implement exponential backoff and retry logic, or request a quota increase through the Google Cloud Console's 'IAM & Admin' -> 'Quotas' page if your usage justifies it.","cause":"The number of requests to the DLP API has exceeded the allocated quota for your project within a given time frame.","error":"google.api_core.exceptions.ResourceExhausted: 429 Quota exceeded for quota group 'DlpRequestsPerMinutePerProject' and limit 'Dlp requests per minute per project'."},{"fix":"When creating the `DlpServiceClient`, specify the regional endpoint. For example, `client_options=ClientOptions(api_endpoint='us-central1-dlp.googleapis.com')` for `us-central1`. Ensure all related resources (like KMS keys) are in the same region.","cause":"DLP API operations must be directed to the correct regional endpoint if the resources (e.g., Cloud Storage buckets, BigQuery datasets, KMS keys) or the nature of the operation requires a specific region, but the client was initialized or the request was made to the global endpoint.","error":"The request concerns location 'us-central1' but was sent to location 'global'. Regional APIs must be called with a regional endpoint."}],"ecosystem":"pypi","meta_description":null,"install_score":95,"install_tag":"verified","quickstart_score":0,"quickstart_tag":"stale","pypi_latest":null,"install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":2.56,"mem_mb":37.8,"disk_size":"70.1M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.13,"mem_mb":25.2,"disk_size":"68M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":3.38,"mem_mb":39.1,"disk_size":"75.0M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.93,"mem_mb":27.6,"disk_size":"73M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":3.16,"mem_mb":38.9,"disk_size":"66.5M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":2.17,"mem_mb":27.5,"disk_size":"64M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":3.08,"mem_mb":39.5,"disk_size":"66.0M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":2.22,"mem_mb":27.9,"disk_size":"64M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":2.39,"mem_mb":37.6,"disk_size":"70.2M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.32,"mem_mb":25,"disk_size":"68M"}]},"quickstart_checks":{"last_tested":"2026-04-23","tag":"stale","tag_description":"widespread failures or data too old to trust","results":[{"runtime":"python:3.10-alpine","exit_code":1},{"runtime":"python:3.10-slim","exit_code":1},{"runtime":"python:3.11-alpine","exit_code":1},{"runtime":"python:3.11-slim","exit_code":1},{"runtime":"python:3.12-alpine","exit_code":1},{"runtime":"python:3.12-slim","exit_code":1},{"runtime":"python:3.13-alpine","exit_code":1},{"runtime":"python:3.13-slim","exit_code":1},{"runtime":"python:3.9-alpine","exit_code":1},{"runtime":"python:3.9-slim","exit_code":1}]}}