Client Reference¶
Datastore client connection manager for the Google Cloud Datastore ODM.
This module provides a singleton pattern to ensure that only one instance
of the google.cloud.datastore.Client is created per GCP project and database.
This prevents connection overhead and memory leaks.
get_client(project=None, database=None)
¶
Retrieve the global Google Cloud Datastore client instance.
If the client for the requested project and database has not been initialized yet,
this function will create and cache a new instance. If project or database
is None, it automatically infers the defaults from the host environment
(e.g., the GOOGLE_CLOUD_PROJECT environment variable).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project
|
str | None
|
The specific GCP project ID to connect to. Defaults to |
None
|
database
|
str | None
|
The specific Datastore database name to connect to. Defaults to |
None
|
Returns:
| Type | Description |
|---|---|
Client
|
datastore.Client: The active Datastore client connection. |
Examples:
Retrieve the default client inferred from the environment:
Retrieve a client for a specific tenant database: