Registry / gcp / google-cloud-memcache

google-cloud-memcache

JSON →
library1.16.0pypypi✓ verified 24d ago

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.

pip install google-cloud-memcache
INSTALL
IMPORT
SIG · GOOGLE-CLOUD-MEMCA
G
google-cloud-memcache
gcppythonv1.16.0
Install
5.6s avg
Import
1460ms
Disk
68MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.16.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 1.706s · 70.1MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 5.6s · import 1.214s · 68MB
68MB installed
● package 68MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

CloudMemcacheClient
from google.cloud.memcache_v1 import CloudMemcacheClient
from google.cloud import memcache
The service-specific client is usually versioned and nested under `_v1` or similar, not directly under `google.cloud`.

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.

import os from google.cloud.memcache_v1 import CloudMemcacheClient # Set your Google Cloud Project ID and a region where Memcached instances exist or can be created. # For example, 'us-central1' or 'europe-west1'. project_id = os.environ.get('GOOGLE_CLOUD_PROJECT', 'your-project-id') location_id = 'us-central1' # e.g., 'us-central1' try: # Initialize a client client = CloudMemcacheClient() # The parent resource for all instances, in the format: `projects/{project_id}/locations/{location_id}` parent = f"projects/{project_id}/locations/{location_id}" # List Memcached instances in the specified location print(f"Listing Memcached instances in {parent}:") request = {"parent": parent} for instance in client.list_instances(request=request): print(f" Instance: {instance.name}, State: {instance.state.name}") print("Successfully listed Memcached instances.") except Exception as e: print(f"An error occurred: {e}") print("Please ensure you have authenticated with `gcloud auth application-default login` ") print("and that the Memcache API is enabled for your project.") print(f"You can set GOOGLE_CLOUD_PROJECT and optionally GOOGLE_APPLICATION_CREDENTIALS environment variables.")
Debug
Known issues
breakingGoogle 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.
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.
affects: All versions
gotchaThe `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.
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.
affects: All versions, especially when migrating from Python 2 App Engine
gotchaStandard 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.
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'`.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'google.cloud.memcache'
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.
fix
Ensure the library is installed using pip: `pip install google-cloud-memcache`.
telnet: Unable to connect to remote host: Connection refused
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.
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.
ERROR: (gcloud.memcache.instances.create) { "code": 9, "message": "Unable to create instance. The allocated private IP address space is exhausted." }
The private services access connection for your VPC network has exhausted its allocated IP address range, preventing the creation of new Memcached instances.
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.
Unable to create instance. Enable private service access for the authorized network and try again.
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.
fix
Establish a private services access connection for your project's network by following the setup instructions in the Google Cloud documentation.
Permission denied
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.
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.
Upgrade
Version history
1.16.0latest on PyPI · released Jun 22, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
25 hits · last 30 days
node
22
OpenAI (training)
1
Resources
google-cloud-memcache — pip install google-cloud-memcache · libregistry