{"id":735,"library":"google-cloud-memcache","title":"Google Cloud Memcache API Client Library","description":"The `google-cloud-memcache` client library for Python provides programmatic access to the Google Cloud Memorystore for Memcached API. It allows developers to manage and interact with fully-managed Memcached instances on Google Cloud. The library is currently at version 1.15.0 and is actively maintained as part of the broader `googleapis/google-cloud-python` monorepo, with frequent updates.","status":"active","version":"1.15.0","language":"python","source_language":"en","source_url":"https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-memcache","tags":["google cloud","memcache","caching","memorystore","cloud computing"],"install":[{"cmd":"pip install google-cloud-memcache","lang":"bash","label":"Install the latest version"}],"dependencies":[],"imports":[{"note":"The service-specific client is usually versioned and nested under `_v1` or similar, not directly under `google.cloud`.","wrong":"from google.cloud import memcache","symbol":"CloudMemcacheClient","correct":"from google.cloud.memcache_v1 import CloudMemcacheClient"}],"quickstart":{"code":"import os\nfrom google.cloud.memcache_v1 import CloudMemcacheClient\n\n# Set your Google Cloud Project ID and a region where Memcached instances exist or can be created.\n# For example, 'us-central1' or 'europe-west1'.\nproject_id = os.environ.get('GOOGLE_CLOUD_PROJECT', 'your-project-id')\nlocation_id = 'us-central1' # e.g., 'us-central1'\n\ntry:\n    # Initialize a client\n    client = CloudMemcacheClient()\n\n    # The parent resource for all instances, in the format: `projects/{project_id}/locations/{location_id}`\n    parent = f\"projects/{project_id}/locations/{location_id}\"\n\n    # List Memcached instances in the specified location\n    print(f\"Listing Memcached instances in {parent}:\")\n    request = {\"parent\": parent}\n    for instance in client.list_instances(request=request):\n        print(f\"  Instance: {instance.name}, State: {instance.state.name}\")\n\n    print(\"Successfully listed Memcached instances.\")\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\n    print(\"Please ensure you have authenticated with `gcloud auth application-default login` \")\n    print(\"and that the Memcache API is enabled for your project.\")\n    print(f\"You can set GOOGLE_CLOUD_PROJECT and optionally GOOGLE_APPLICATION_CREDENTIALS environment variables.\")\n","lang":"python","description":"This quickstart demonstrates how to instantiate the `CloudMemcacheClient` and list existing Memcached instances within a specified Google Cloud project and location. Ensure your `GOOGLE_CLOUD_PROJECT` environment variable is set and you've authenticated with `gcloud auth application-default login` or equivalent service account credentials. The Memcache API must also be enabled for your project."},"warnings":[{"fix":"Plan to migrate existing Memcached instances to Memorystore for Valkey. For new projects, avoid creating Memorystore for Memcached instances. Consult the official Google Cloud documentation for migration guides.","message":"Google Cloud Memorystore for Memcached is being deprecated and will be shut down on January 31, 2029. After February 1, 2027, you cannot create new Memorystore for Memcached instances in new projects. Migration to Memorystore for Valkey (a Redis-compatible service) is strongly recommended for existing and new workloads.","severity":"breaking","affected_versions":"All versions"},{"fix":"For Python 3 App Engine, use the `google-cloud-memcache` library to interact with a Memorystore for Memcached instance, or switch to Memorystore for Valkey. Do not expect `google.appengine.api.memcache` to work in Python 3.","message":"The `google-cloud-memcache` library is distinct from the legacy App Engine `google.appengine.api.memcache` service. The App Engine Memcache service is NOT available for Python 3 runtimes. If you are developing a Python 3 App Engine application and need caching, you must use the `google-cloud-memcache` client library to connect to a provisioned Memorystore for Memcached instance (or preferably Memorystore for Valkey due to deprecation) via Serverless VPC Access.","severity":"gotcha","affected_versions":"All versions, especially when migrating from Python 2 App Engine"},{"fix":"Run `gcloud auth application-default login` in your terminal or provide a service account key JSON file via `os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = '/path/to/key.json'`.","message":"Standard Google Cloud authentication is required. If running locally, ensure you've authenticated via `gcloud auth application-default login` or set the `GOOGLE_APPLICATION_CREDENTIALS` environment variable to a service account key file. Permissions to manage Memcached instances are also required.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-05-12T18:26:14.386Z","next_check":"2026-06-26T00:00:00.000Z","problems":[{"fix":"Ensure the library is installed using pip: `pip install google-cloud-memcache`.","cause":"The `google-cloud-memcache` library or its specific sub-module is not installed or accessible in the Python environment where the code is being run.","error":"ModuleNotFoundError: No module named 'google.cloud.memcache'"},{"fix":"Verify the Memcached instance's IP address and port, check VPC network peering and firewall rules to ensure they allow traffic, and confirm the instance is in a 'READY' state and located in the same region and network as the client.","cause":"The client application cannot establish a network connection to the Memcached instance, often due to incorrect IP address/port, firewall rules blocking access, or the Memcached instance not being in a 'READY' state or not reachable from the client's network.","error":"telnet: Unable to connect to remote host: Connection refused"},{"fix":"Allocate additional IP addresses to your private services access connection. Refer to Google Cloud documentation on expanding IP address allocation for private services access.","cause":"The private services access connection for your VPC network has exhausted its allocated IP address range, preventing the creation of new Memcached instances.","error":"ERROR: (gcloud.memcache.instances.create) { \"code\": 9, \"message\": \"Unable to create instance. The allocated private IP address space is exhausted.\" }"},{"fix":"Establish a private services access connection for your project's network by following the setup instructions in the Google Cloud documentation.","cause":"A private services access connection has not been established or is incorrectly configured for the network where you are attempting to create the Memorystore for Memcached instance.","error":"Unable to create instance. Enable private service access for the authorized network and try again."},{"fix":"Grant the required IAM roles to the principal for the Memcached instance or project. Common roles include 'Cloud Memorystore Memcached Editor' or more granular permissions like `memcache.instances.get` for read access.","cause":"The principal (user account or service account) attempting to perform an action on the Memcached instance or interact with the API lacks the necessary Identity and Access Management (IAM) permissions.","error":"Permission denied"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"install_tag":"verified","quickstart_score":80,"quickstart_tag":"verified","pypi_latest":"1.15.0","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":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":1.67,"mem_mb":23.6,"disk_size":"69.2M"},{"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":1.69,"mem_mb":23.8,"disk_size":"68.1M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":6.6,"import_time_s":1.1,"mem_mb":20.6,"disk_size":"67M"},{"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":0.99,"mem_mb":20.8,"disk_size":"66M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":2.35,"mem_mb":25.6,"disk_size":"73.9M"},{"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":2.57,"mem_mb":25.9,"disk_size":"72.7M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":5.4,"import_time_s":1.54,"mem_mb":22.8,"disk_size":"72M"},{"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.49,"mem_mb":23.1,"disk_size":"70M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":2.43,"mem_mb":24.9,"disk_size":"65.3M"},{"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":2.57,"mem_mb":25.7,"disk_size":"64.2M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":4.9,"import_time_s":1.82,"mem_mb":22.1,"disk_size":"63M"},{"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":1.93,"mem_mb":22.9,"disk_size":"62M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":2.19,"mem_mb":25.9,"disk_size":"65.0M"},{"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":2.5,"mem_mb":26.4,"disk_size":"63.8M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":4.6,"import_time_s":1.8,"mem_mb":23,"disk_size":"63M"},{"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.1,"mem_mb":23.6,"disk_size":"62M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":1.56,"mem_mb":23.5,"disk_size":"69.2M"},{"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":1.47,"mem_mb":23.4,"disk_size":"68.2M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":7.1,"import_time_s":1.24,"mem_mb":20.6,"disk_size":"67M"},{"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.07,"mem_mb":20.4,"disk_size":"66M"}]},"quickstart_checks":{"last_tested":"2026-04-24","tag":"verified","tag_description":"quickstart runs on critical runtimes, recently tested","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}}