Python
Client#
Convenience wrapper for invoking APIs/factories w/ a dataset ID.
-
class
gcloud.datastore.client.Client(dataset_id=None, namespace=None, connection=None)[source]# Bases:
objectConvenience wrapper for invoking APIs/factories w/ a dataset ID.
Parameters: - dataset_id (string) – (optional) dataset ID to pass to proxied API methods.
- namespace (string) – (optional) namespace to pass to proxied API methods.
- connection (
gcloud.datastore.connection.Connection, or None) – (optional) connection to pass to proxied API methods
-
allocate_ids(incomplete_key, num_ids)[source]# Allocate a list of IDs from a partial key.
Parameters: - incomplete_key (A
gcloud.datastore.key.Key) – Partial key to use as base for allocated IDs. - num_ids (integer) – The number of IDs to allocate.
Return type: list of
gcloud.datastore.key.KeyReturns: The (complete) keys allocated with
incomplete_keyas root.Raises: ValueErrorifincomplete_keyis not a partial key.- incomplete_key (A
-
batch()[source]# Proxy to
gcloud.datastore.batch.Batch.Passes our
dataset_id.
-
current_batch# Currently-active batch.
Return type: gcloud.datastore.batch.Batch, or an object implementing its API, orNoneType(if no batch is active).Returns: The batch/transaction at the top of the batch stack.
-
current_transaction# Currently-active transaction.
Return type: gcloud.datastore.transaction.Transaction, or an object implementing its API, orNoneType(if no transaction is active).Returns: The transaction at the top of the batch stack.
-
delete(key)[source]# Delete the key in the Cloud Datastore.
Note
This is just a thin wrapper over
delete_multi(). The backend API does not make a distinction between a single key or multiple keys in a commit request.Parameters: key ( gcloud.datastore.key.Key) – The key to be deleted from the datastore.
-
delete_multi(keys)[source]# Delete keys from the Cloud Datastore.
Parameters: keys (list of gcloud.datastore.key.Key) – The keys to be deleted from the datastore.
-
get(key, missing=None, deferred=None)[source]# Retrieve an entity from a single key (if it exists).
Note
This is just a thin wrapper over
get_multi(). The backend API does not make a distinction between a single key or multiple keys in a lookup request.Parameters: - key (
gcloud.datastore.key.Key) – The key to be retrieved from the datastore. - missing (an empty list or None.) – If a list is passed, the key-only entities returned by the backend as “missing” will be copied into it. Use only as a keyword param.
- deferred (an empty list or None.) – If a list is passed, the keys returned by the backend as “deferred” will be copied into it. Use only as a keyword param.
Return type: gcloud.datastore.entity.EntityorNoneTypeReturns: The requested entity if it exists.
- key (
-
get_multi(keys, missing=None, deferred=None)[source]# Retrieve entities, along with their attributes.
Parameters: - keys (list of
gcloud.datastore.key.Key) – The keys to be retrieved from the datastore. - missing (an empty list or None.) – If a list is passed, the key-only entities returned by the backend as “missing” will be copied into it. Use only as a keyword param.
- deferred (an empty list or None.) – If a list is passed, the keys returned by the backend as “deferred” will be copied into it. Use only as a keyword param.
Return type: list of
gcloud.datastore.entity.EntityReturns: The requested entities.
Raises: ValueError if one or more of
keyshas a dataset ID which does not match our dataset ID.- keys (list of
-
key(*path_args, **kwargs)[source]# Proxy to
gcloud.datastore.key.Key.Passes our
dataset_id.
-
put(entity)[source]# Save an entity in the Cloud Datastore.
Note
This is just a thin wrapper over
put_multi(). The backend API does not make a distinction between a single entity or multiple entities in a commit request.Parameters: entity ( gcloud.datastore.entity.Entity) – The entity to be saved to the datastore.
-
put_multi(entities)[source]# Save entities in the Cloud Datastore.
Parameters: entities (list of gcloud.datastore.entity.Entity) – The entities to be saved to the datastore.Raises: ValueError if entitiesis a single entity.
-
query(**kwargs)[source]# Proxy to
gcloud.datastore.query.Query.Passes our
dataset_id.
-
transaction()[source]# Proxy to
gcloud.datastore.transaction.Transaction.Passes our
dataset_id.