[ Web Proxy ]
URL:
Viewing: https://docs.cloud.google.com/python/docs/reference/datastore/latest/client [Back]  [Original]

Datastore Client  |  Python client libraries  |  Google Cloud Documentation Skip to main content
Google Cloud Documentation [Google Cloud Documentation]
Send feedback

Datastore Client Stay organized with collections Save and categorize content based on your preferences.

2.26.1 (latest) 2.26.0 2.25.0 2.24.0 2.23.0 2.22.0 2.21.0 2.20.2 2.19.0 2.18.0 2.17.0 2.16.1 2.15.2 2.14.0 2.13.2 2.12.0 2.11.1 2.10.0 2.9.0 2.8.3 2.7.2 2.6.2 2.5.1 2.4.0 2.3.0 2.2.0 2.1.6 2.0.1 1.15.5 1.14.0 1.13.2 1.12.0 1.11.0 1.10.0 1.9.0

Convenience wrapper for invoking APIs/factories w/ a project.

class google.cloud.datastore.client.Client(project=None, namespace=None, credentials=None, client_info=<google.api_core.gapic_v1.client_info.ClientInfo object>, client_options=None, database=None, _http=None, _use_grpc=None)

Bases: google.cloud.client.ClientWithProject

Convenience wrapper for invoking APIs/factories w/ a project.

>>> from google.cloud import datastore
>>> client = datastore.Client()

SCOPE(: Union[Tuple[str, ...], None = ('https://www.googleapis.com/auth/datastore', )

The scopes required for authenticating as a Cloud Datastore consumer.

aggregation_query(query, **kwargs)

Proxy to google.cloud.datastore.aggregation.AggregationQuery.

Using aggregation_query to count over a query:

>>> query = client.query(kind='MyKind')
>>> aggregation_query = client.aggregation_query(query)
>>> aggregation_query.count(alias='total')
<google.cloud.datastore.aggregation.AggregationQuery object at ...>
>>> aggregation_query.fetch()
<google.cloud.datastore.aggregation.AggregationResultIterator object at ...>

Adding an aggregation to the aggregation_query

>>> query = client.query(kind='MyKind')
>>> aggregation_query.add_aggregation(CountAggregation(alias='total'))
>>> aggregation_query.fetch()
<google.cloud.datastore.aggregation.AggregationResultIterator object at ...>

Adding multiple aggregations to the aggregation_query

>>> query = client.query(kind='MyKind')
>>> total_count = CountAggregation(alias='total')
>>> all_count = CountAggregation(alias='all')
>>> aggregation_query.add_aggregations([total_count, all_count])
>>> aggregation_query.fetch()
<google.cloud.datastore.aggregation.AggregationResultIterator object at ...>

Using the aggregation_query iterator

>>> query = client.query(kind='MyKind')
>>> aggregation_query = client.aggregation_query(query)
>>> aggregation_query.count(alias='total')
<google.cloud.datastore.aggregation.AggregationQuery object at ...>
>>> aggregation_query_iter = aggregation_query.fetch()
>>> for aggregation_result in aggregation_query_iter:
...     do_something_with(aggregation_result)

or manually page through results

>>> aggregation_query_iter = aggregation_query.fetch()
>>> pages = aggregation_query_iter.pages
>>>
>>> first_page = next(pages)
>>> first_page_entities = list(first_page)
>>> aggregation_query_iter.next_page_token is None
True

allocate_ids(incomplete_key, num_ids, retry=None, timeout=None)

Allocate a list of IDs from a partial key.

property base_url()

Getter for API base URL.

batch()

Proxy to google.cloud.datastore.batch.Batch.

property current_batch()

Currently-active batch, if within the scope of a Batch context manager.

property current_transaction()

Currently-active transaction, if within the scope of a Transaction context manager.

property database()

Getter for database

delete(key, retry=None, timeout=None)

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.

delete_multi(keys, retry=None, timeout=None)

Delete keys from the Cloud Datastore.

entity(key=None, exclude_from_indexes=())

Proxy to google.cloud.datastore.entity.Entity.

get(key, missing=None, deferred=None, transaction=None, eventual=False, retry=None, timeout=None, read_time=None)

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.

get_multi(keys, missing=None, deferred=None, transaction=None, eventual=False, retry=None, timeout=None, read_time=None)

Retrieve entities, along with their attributes.

key(*path_args, **kwargs)

Proxy to google.cloud.datastore.key.Key.

Passes our project and our database.

put(entity, retry=None, timeout=None)

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.

put_multi(entities, retry=None, timeout=None)

Save entities in the Cloud Datastore.

query(**kwargs)

Proxy to google.cloud.datastore.query.Query.

Passes our project.

Using query to search a datastore:

>>> query = client.query(kind='MyKind')
>>> query.add_filter('property', '=', 'val')
<google.cloud.datastore.query.Query object at ...>

Using the query iterator

>>> filters = [('property', '=', 'val')]
>>> query = client.query(kind='MyKind', filters=filters)
>>> query_iter = query.fetch()
>>> for entity in query_iter:
...     do_something_with(entity)

or manually page through results

>>> query_iter = query.fetch()
>>> pages = query_iter.pages
>>>
>>> first_page = next(pages)
>>> first_page_entities = list(first_page)
>>> query_iter.next_page_token is None
True

reserve_ids(complete_key, num_ids, retry=None, timeout=None)

Reserve a list of IDs sequentially from a complete key.

DEPRECATED. Alias for reserve_ids_sequential().

Please use either reserve_ids_multi() (recommended) or reserve_ids_sequential().

reserve_ids_multi(complete_keys, retry=None, timeout=None)

Reserve IDs from a list of complete keys.

reserve_ids_sequential(complete_key, num_ids, retry=None, timeout=None)

Reserve a list of IDs sequentially from a complete key.

This will reserve the key passed as complete_key as well as additional keys derived by incrementing the last ID in the path of complete_key sequentially to obtain the number of keys specified in num_ids.

transaction(**kwargs)

Proxy to google.cloud.datastore.transaction.Transaction.

google.cloud.datastore.client.DATASTORE_DATASET( = 'DATASTORE_DATASET )

Environment variable defining default dataset ID under GCD.

google.cloud.datastore.client.DATASTORE_EMULATOR_HOST( = 'DATASTORE_EMULATOR_HOST )

Environment variable defining host for datastore emulator server.

google.cloud.datastore.client.DISABLE_GRPC( = 'GOOGLE_CLOUD_DISABLE_GRPC )

Environment variable acting as flag to disable gRPC.

Send feedback

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-08-25 UTC.

Need to tell us more? [[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2026-08-25 UTC."],[],[]]

Web Proxy Viewer  |  New URL  |  Original Page