{"id":5946,"library":"google-cloud-dns","title":"Google Cloud DNS Client Library","description":"The Google Cloud DNS API client library provides a Pythonic interface for managing DNS records and managed zones within Google Cloud DNS. It is part of the broader `google-cloud-python` monorepo, benefiting from its active development and frequent updates across Google Cloud services.","status":"active","version":"0.36.1","language":"en","source_language":"en","source_url":"https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-dns","tags":["google cloud","dns","cloud dns","networking"],"install":[{"cmd":"pip install google-cloud-dns","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Requires Python 3.9 or newer.","package":"Python","optional":false},{"reason":"Core dependency for Google Cloud client libraries, providing API client common functionality.","package":"google-api-core","optional":false},{"reason":"Core dependency for Google Cloud client libraries, handling authentication.","package":"google-auth","optional":false}],"imports":[{"note":"The direct import `from google.cloud.dns.client import Client` was used in older versions of the `google-cloud` meta-package (e.g., prior to 1.0) but is deprecated in favor of `from google.cloud import dns` where `dns.Client` is the recommended instantiation.","wrong":"from google.cloud.dns.client import Client","symbol":"Client","correct":"from google.cloud import dns"}],"quickstart":{"code":"import os\nfrom google.cloud import dns\n\n# Your Google Cloud project ID\nproject_id = os.environ.get('GOOGLE_CLOUD_PROJECT', 'your-project-id')\n\nif not project_id or project_id == 'your-project-id':\n    print(\"Please set the 'GOOGLE_CLOUD_PROJECT' environment variable or replace 'your-project-id' in the code.\")\n    exit(1)\n\n# Initialize the DNS client\n# The client automatically handles authentication using Application Default Credentials (ADC)\n# For local development, ensure you've run 'gcloud auth application-default login'\nclient = dns.Client(project=project_id)\n\ntry:\n    # List managed zones\n    print(f\"Listing managed zones for project: {project_id}\")\n    zones = client.list_zones()\n\n    if not zones:\n        print(\"No managed zones found.\")\n    else:\n        for zone in zones:\n            print(f\"  Zone Name: {zone.name}, DNS Name: {zone.dns_name}\")\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")","lang":"python","description":"This quickstart initializes the Google Cloud DNS client and lists all managed zones within a specified Google Cloud project. It leverages Application Default Credentials (ADC) for authentication, automatically inferring credentials from the environment. For local execution, ensure the `GOOGLE_CLOUD_PROJECT` environment variable is set or replace the placeholder. You'll also need to authenticate with `gcloud auth application-default login`."},"warnings":[{"fix":"Upgrade your Python environment to 3.9+ and ensure your `google-cloud-dns` library is updated accordingly. Review the official migration guides for any specific API changes if coming from very old versions.","message":"Python 2.7 support was dropped in `google-cloud-python` 2.0.0. Current versions require Python 3.9 or newer.","severity":"breaking","affected_versions":"<2.0.0 (for Python 2.7 users)"},{"fix":"Navigate to the Google Cloud Console, search for 'Cloud DNS API' in the API Library, and enable it for your project.","message":"Ensure the Cloud DNS API is enabled in your Google Cloud project. Attempting operations without enabling the API will result in 'attempted action failed' or similar permission errors.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Use A/AAAA records for the zone apex. For subdomains, ensure CNAMEs do not conflict with other record types. Always include a trailing dot for fully qualified domain names (e.g., 'example.com.') in record data.","message":"When creating DNS records, be aware of DNS specifications and Cloud DNS limitations, particularly regarding CNAME records. A CNAME record cannot exist at the zone apex (root domain) and cannot coexist with other record types for the same DNS name.","severity":"gotcha","affected_versions":"All versions"},{"fix":"For client library authentication in local development, use `gcloud auth application-default login`. In production, configure service accounts or other appropriate ADC mechanisms.","message":"Authentication for Google Cloud client libraries, including `google-cloud-dns`, typically relies on Application Default Credentials (ADC). For local development, `gcloud auth application-default login` generates user credentials for client libraries, distinct from `gcloud auth login` which authenticates the CLI itself.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-14T00:00:00.000Z","next_check":"2026-07-13T00:00:00.000Z"}