{"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":[{"wrong":"from google.cloud import dlp_v2","symbol":"DlpServiceClient","correct":"from google.cloud.dlp_v2 import 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,"search_vec":"'3.34.0':64 'access':14 'api':23 'bigqueri':54 'cadenc':70 'classifi':34 'client':10,75 'cloud':2,7,18,49,56,74,84 'continu':68 'current':61 'data':19,28,40,87 'data-loss-prevent':86 'discov':33 'dlp':3,8,22,85 'enabl':31 'enhanc':81 'follow':66 'frequent':78 'googl':1,6,17,48,73,83 'google-cloud':82 'google-cloud-dlp':5 'imag':45 'librari':11,59,76 'like':41 'loss':20,88 'offer':77 'part':25 'pii':42 'prevent':21,89 'privaci':38,90 'privacy-sensit':37 'programmat':13 'protect':29 'provid':12 'python':9 'redact':36 'releas':69 'repositori':51 'scan':32 'secur':91 'sensit':27,39 'storag':50,57 'text':44 'typic':71 'updat':79 'various':47 'version':63 'within':43","created_at":"2026-03-28T15:16:01.424796+00:00","updated_at":"2026-04-16T15:21:43.303364+00:00","problems":null,"ecosystem":"pypi","meta_description":null,"install_score":95,"quickstart_score":0,"quickstart_tag":"stale","pypi_latest":"3.38.0","cli_name":"","cli_version":null,"type":"library","homepage":"https://cloud.google.com/dlp","github":"https://github.com/googleapis/google-cloud-python","docs":null,"changelog":null,"pypi":"https://pypi.org/project/google-cloud-dlp/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["gcp","auth-security","aws","azure","ai-ml"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-30","last_verified":"2026-08-27","next_check":"2026-07-30","install_tag":"verified"}}