(Optional) Options to enable query profiling for this query. When set, explain_metrics will be available on the iterator returned by query.fetch(). If not passed, will use value from given query.
(Optional) client used to connect to datastore. If not supplied, uses the query's value.
eventual
bool
(Optional) Defaults to strongly consistent (False). Setting True will use eventual consistency, but cannot be used inside a transaction or with read_time, otherwise will raise ValueError.
retry
google.api_core.retry.Retry
A retry object used to retry requests. If None is specified, requests will be retried using a default configuration.
timeout
float
Time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.
read_time
datetime
(Optional) use read_time read consistency, cannot be used inside a transaction or with eventual consistency, or will raise ValueError.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-28 UTC."],[],[],null,["# Class AggregationQuery (2.21.0)\n\nVersion latestkeyboard_arrow_down\n\n- [2.21.0 (latest)](/python/docs/reference/datastore/latest/google.cloud.datastore.aggregation.AggregationQuery)\n- [2.20.2](/python/docs/reference/datastore/2.20.2/google.cloud.datastore.aggregation.AggregationQuery)\n- [2.19.0](/python/docs/reference/datastore/2.19.0/google.cloud.datastore.aggregation.AggregationQuery)\n- [2.18.0](/python/docs/reference/datastore/2.18.0/google.cloud.datastore.aggregation.AggregationQuery)\n- [2.17.0](/python/docs/reference/datastore/2.17.0/google.cloud.datastore.aggregation.AggregationQuery)\n- [2.16.1](/python/docs/reference/datastore/2.16.1/google.cloud.datastore.aggregation.AggregationQuery)\n- [2.15.2](/python/docs/reference/datastore/2.15.2/google.cloud.datastore.aggregation.AggregationQuery)\n- [2.14.0](/python/docs/reference/datastore/2.14.0/google.cloud.datastore.aggregation.AggregationQuery)\n- [2.13.2](/python/docs/reference/datastore/2.13.2/google.cloud.datastore.aggregation.AggregationQuery)\n- [2.12.0](/python/docs/reference/datastore/2.12.0/google.cloud.datastore.aggregation.AggregationQuery)\n- [2.11.1](/python/docs/reference/datastore/2.11.1/google.cloud.datastore.aggregation.AggregationQuery)\n- [2.10.0](/python/docs/reference/datastore/2.10.0/google.cloud.datastore.aggregation.AggregationQuery)\n- [2.9.0](/python/docs/reference/datastore/2.9.0/google.cloud.datastore.aggregation.AggregationQuery)\n- [2.8.3](/python/docs/reference/datastore/2.8.3/google.cloud.datastore.aggregation.AggregationQuery)\n- [2.7.2](/python/docs/reference/datastore/2.7.2/google.cloud.datastore.aggregation.AggregationQuery)\n- [2.6.2](/python/docs/reference/datastore/2.6.2/google.cloud.datastore.aggregation.AggregationQuery)\n- [2.5.1](/python/docs/reference/datastore/2.5.1/google.cloud.datastore.aggregation.AggregationQuery)\n- [2.4.0](/python/docs/reference/datastore/2.4.0/google.cloud.datastore.aggregation.AggregationQuery)\n- [2.3.0](/python/docs/reference/datastore/2.3.0/google.cloud.datastore.aggregation.AggregationQuery)\n- [2.2.0](/python/docs/reference/datastore/2.2.0/google.cloud.datastore.aggregation.AggregationQuery)\n- [2.1.6](/python/docs/reference/datastore/2.1.6/google.cloud.datastore.aggregation.AggregationQuery)\n- [2.0.1](/python/docs/reference/datastore/2.0.1/google.cloud.datastore.aggregation.AggregationQuery)\n- [1.15.5](/python/docs/reference/datastore/1.15.5/google.cloud.datastore.aggregation.AggregationQuery)\n- [1.14.0](/python/docs/reference/datastore/1.14.0/google.cloud.datastore.aggregation.AggregationQuery)\n- [1.13.2](/python/docs/reference/datastore/1.13.2/google.cloud.datastore.aggregation.AggregationQuery)\n- [1.12.0](/python/docs/reference/datastore/1.12.0/google.cloud.datastore.aggregation.AggregationQuery)\n- [1.11.0](/python/docs/reference/datastore/1.11.0/google.cloud.datastore.aggregation.AggregationQuery)\n- [1.10.0](/python/docs/reference/datastore/1.10.0/google.cloud.datastore.aggregation.AggregationQuery)\n- [1.9.0](/python/docs/reference/datastore/1.9.0/google.cloud.datastore.aggregation.AggregationQuery) \n\n AggregationQuery(client, query, explain_options=None)\n\nAn Aggregation query against the Cloud Datastore.\n\nThis class serves as an abstraction for creating aggregations over query\nin the Cloud Datastore.\n\nProperties\n----------\n\n### namespace\n\nThe nested query's namespace\n\n### project\n\nGet the project for this AggregationQuery.\n\nMethods\n-------\n\n### add_aggregation\n\n add_aggregation(aggregation)\n\nAdds an aggregation operation to the nested query\n\n### add_aggregations\n\n add_aggregations(aggregations)\n\nAdds a list of aggregations to the nested query\n\n### avg\n\n avg(property_ref, alias=None)\n\nAdds a avg over the nested query\n\n### count\n\n count(alias=None)\n\nAdds a count over the nested query\n\n### fetch\n\n fetch(\n client=None, limit=None, eventual=False, retry=None, timeout=None, read_time=None\n )\n\nExecute the Aggregation Query; return an iterator for the aggregation results.\n\nFor example:\n\n.. testsetup:: aggregation-query-fetch \n\n import uuid\n\n from google.cloud import https://cloud.google.com/python/docs/reference/datastore/latest/\n\n unique = str(uuid.uuid4())[0:8]\n client = https://cloud.google.com/python/docs/reference/datastore/latest/.https://cloud.google.com/python/docs/reference/datastore/latest/google.cloud.datastore.client.Client.html(namespace='ns{}'.format(unique))\n\n.. doctest:: aggregation-query-fetch \n\n \u003e\u003e\u003e andy = datastore.Entity(client.key('Person', 1234))\n \u003e\u003e\u003e andy['name'] = 'Andy'\n \u003e\u003e\u003e sally = datastore.Entity(client.key('Person', 2345))\n \u003e\u003e\u003e sally['name'] = 'Sally'\n \u003e\u003e\u003e bobby = datastore.Entity(client.key('Person', 3456))\n \u003e\u003e\u003e bobby['name'] = 'Bobby'\n \u003e\u003e\u003e client.put_multi([andy, sally, bobby])\n \u003e\u003e\u003e query = client.query(kind='Andy')\n \u003e\u003e\u003e aggregation_query = client.aggregation_query(query)\n \u003e\u003e\u003e result = aggregation_query.count(alias=\"total\").fetch(limit=5)\n \u003e\u003e\u003e result\n \u003c\u003cxref uid=\"google.cloud.datastore.aggregation.AggregationResultIterator\"\u003egoogle.cloud.datastore.aggregation.AggregationResultIterator\u003c/xref\u003e object at ...\u003e\n\n.. testcleanup:: aggregation-query-fetch \n\n client.delete(andy.key)\n\n### sum\n\n sum(property_ref, alias=None)\n\nAdds a sum over the nested query"]]