Stay organized with collections Save and categorize content based on your preferences.
Create / interact with Google Cloud Datastore queries.
class google.cloud.datastore.query.Iterator(query, client, limit=None, offset=None, start_cursor=None, end_cursor=None, eventual=False)Bases: google.api_core.page_iterator.Iterator
Represent the state of a given execution of a Query.
Parameters
query (Query
) – Query object holding permanent configuration (i.e. things that don’t change on with each page in a results set).
client (Client
) – The client used to make a request.
limit (int) – (Optional) Limit the number of results returned.
offset (int) – (Optional) Offset used to begin a query.
start_cursor (bytes) – (Optional) Cursor to begin paging through query results.
end_cursor (bytes) – (Optional) Cursor to end paging through query results.
eventual (bool) – (Optional) Defaults to strongly consistent (False). Setting True will use eventual consistency, but cannot be used inside a transaction or will raise ValueError.
Bases: object
A Query against the Cloud Datastore.
This class serves as an abstraction for creating a query over data stored in the Cloud Datastore.
Parameters
client (google.cloud.datastore.client.Client
) – The client used to connect to Datastore.
kind (str) – The kind to query.
project (str) – (Optional) The project associated with the query. If not passed, uses the client’s value.
namespace (str) – (Optional) The namespace to which to restrict results. If not passed, uses the client’s value.
ancestor (Key
) – (Optional) key of the ancestor to which this query’s results are restricted.
filters (tuple[str, *[str](https://python.readthedocs.io/en/latest/library/stdtypes.html#str), [str](https://python.readthedocs.io/en/latest/library/stdtypes.html#str)]*) – Property filters applied by this query. The sequence is (property_name, operator, value)
.
projection (sequence of string) – fields returned as part of query results.
order (sequence of string) – field names used to order query results. Prepend -
to a field name to sort it in descending order.
distinct_on (sequence of string) – field names used to group query results.
Raises
ValueError if project
is not passed and no implicit default is set.
Mapping of operator strings and their protobuf equivalents.
add_filter(property_name, operator, value)Filter the query based on a property name, operator and a value.
Expressions take the form of:
.add_filter('<property>', '<operator>', <value>)
where property is a property stored on the entity in the datastore and operator is one of OPERATORS
(ie, =
, <
, <=
, >
, >=
):
>>> from google.cloud import datastore
>>> client = datastore.Client()
>>> query = client.query(kind='Person')
>>> query = query.add_filter('name', '=', 'James')
>>> query = query.add_filter('age', '>', 50)
Parameters
property_name (str) – A property name.
operator (str) – One of =
, <
, <=
, >
, >=
.
value (int
, str
, bool
, float
, NoneType
, datetime.datetime
, google.cloud.datastore.key.Key
) – The value to filter on.
Return type
Query
Returns
A query object.
Raises
ValueError
if operation
is not one of the specified values, or if a filter names '__key__'
but passes an invalid value (a key is required).
The ancestor key for the query.
Return type
Key
or None
Returns
The ancestor for the query.
Names of fields used to group query results.
Return type
sequence of string
Returns
The “distinct on” fields set on the query.
Execute the Query; return an iterator for the matching entities.
For example:
>>> from google.cloud import datastore
>>> client = datastore.Client()
>>> query = client.query(kind='Person')
>>> result = query.add_filter('name', '=', 'Sally').fetch()
>>> list(result)
[<Entity object>, <Entity object>, ...]
>>> list(query.fetch(1))
[<Entity object>]
Parameters
limit (int) – (Optional) limit passed through to the iterator.
offset (int) – (Optional) offset passed through to the iterator.
start_cursor (bytes) – (Optional) cursor passed through to the iterator.
end_cursor (bytes) – (Optional) cursor passed through to the iterator.
client (google.cloud.datastore.client.Client
) – (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 will raise ValueError.
Return type
Iterator
Returns
The iterator for the query.
Filters set on the query.
Return type
Returns
The filters set on the query. The sequence is (property_name, operator, value)
.
Filter on a key.
Parameters
key (google.cloud.datastore.key.Key
) – The key to filter on.
operator (str) – (Optional) One of =
, <
, <=
, >
, >=
. Defaults to =
.
Set the projection to include only keys.
property kind()Get the Kind of the Query.
Return type
Returns
The kind for the query.
This query’s namespace
property order()Names of fields used to sort query results.
Return type
sequence of string
Returns
The order(s) set on the query.
Get the project for this Query.
Return type
Returns
The project for the query.
Fields names returned by the query.
Return type
sequence of string
Returns
Names of fields in query results.
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 2025-08-07 UTC.
[[["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 2025-08-07 UTC."],[],[]]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4