datastore

This library implements various methods for working with the Google Datastore APIs.

Installation

$ pip install --upgrade gcloud-aio-datastore

Usage

We’re still working on documentation; for now, this should help get you started:

from gcloud.aio.datastore import Datastore
from gcloud.aio.datastore import Direction
from gcloud.aio.datastore import Filter
from gcloud.aio.datastore import GQLQuery
from gcloud.aio.datastore import Key
from gcloud.aio.datastore import PathElement
from gcloud.aio.datastore import PropertyFilter
from gcloud.aio.datastore import PropertyFilterOperator
from gcloud.aio.datastore import PropertyOrder
from gcloud.aio.datastore import Query
from gcloud.aio.datastore import Value

ds = Datastore('my-gcloud-project', '/path/to/creds.json')
key1 = Key('my-gcloud-project', [PathElement('Kind', 'entityname')])
key2 = Key('my-gcloud-project', [PathElement('Kind', 'entityname2')])

# batched lookups
entities = await ds.lookup([key1, key2])

# convenience functions for any datastore mutations
await ds.insert(key1, {'a_boolean': True, 'meaning_of_life': 41})
await ds.update(key1, {'a_boolean': True, 'meaning_of_life': 42})
await ds.upsert(key1, {'animal': 'aardvark'})
await ds.delete(key1)

# or build your own mutation sequences with full transaction support
transaction = await ds.beginTransaction()
try:
    mutations = [
        ds.make_mutation(Operation.INSERT, key1,
                         properties={'animal': 'sloth'}),
        ds.make_mutation(Operation.UPSERT, key1,
                         properties={'animal': 'aardvark'}),
        ds.make_mutation(Operation.INSERT, key2,
                         properties={'animal': 'aardvark'}),
    ]
    await ds.commit(transaction, mutations=mutations)
except Exception:
    await ds.rollback(transaction)

# support for partial keys
partial_key = Key('my-gcloud-project', [PathElement('Kind')])
# and ID allocation or reservation
allocated_keys = await ds.allocateIds([partial_key])
await ds.reserveIds(allocated_keys)

# query support
property_filter = PropertyFilter(prop='answer',
                                 operator=PropertyFilterOperator.EQUAL,
                                 value=Value(42))
property_order = PropertyOrder(prop='length',
                               direction=Direction.DESCENDING)
query = Query(kind='the_meaning_of_life',
              query_filter=Filter(property_filter),
              order=property_order)
results = await ds.runQuery(query, session=s)  # QueryResult
batch = results.result_batch  # QueryResultBatch
metrics = results.explain_metrics  # ExplainMetrics

# alternatively, query support using GQL
gql_query = GQLQuery(
    'SELECT * FROM meaning_of_life WHERE answer = @answer',
    named_bindings={'answer': 42})
results = await ds.runQuery(gql_query, session=s)  # QueryResult
batch = results.result_batch  # QueryResultBatch
metrics = results.explain_metrics  # ExplainMetrics

# close the HTTP session
# Note that other options include:
# * providing your own session: `Datastore(.., session=session)`
# * using a context manager: `async with Datastore(..) as ds:`
await ds.close()

Custom Subclasses

gcloud-aio-datastore provides class interfaces mirroring all official Google API types, ie. Key and PathElement, Entity and EntityResult, QueryResultBatch, and Value. These types will be returned from arbitrary Datastore operations, for example Datastore.allocateIds(...) will return a list of Key entities.

For advanced usage, all of these datatypes may be overloaded. A common use-case may be to deserialize entities into more specific classes. For example, given a custom entity class such as:

class MyEntityKind(gcloud.aio.datastore.Entity):
    def __init__(self, key, properties = None) -> None:
        self.key = key
        self.is_an_aardvark = (properties or {}).get('aardvark', False)

    def __repr__(self):
        return "I'm an aardvark!" if self.is_an_aardvark else "Sorry, nope"

We can then configure gcloud-aio-datastore to serialize/deserialize from this custom entity class with:

class MyCustomDatastore(gcloud.aio.datastore.Datastore):
    entity_result_kind.entity_kind = MyEntityKind

The full list of classes which may be overridden in this way is:

class MyVeryCustomDatastore(gcloud.aio.datastore.Datastore):
    datastore_operation_kind = DatastoreOperation
    entity_result_kind = EntityResult
    entity_result_kind.entity_kind = Entity
    entity_result_kind.entity_kind.key_kind = Key
    key_kind = Key
    key_kind.path_element_kind = PathElement
    mutation_result_kind = MutationResult
    mutation_result_kind.key_kind = Key
    query_result_batch_kind = QueryResultBatch
    query_result_batch_kind.entity_result_kind = EntityResult
    value_kind = Value
    value_kind.key_kind = Key

class MyVeryCustomQuery(gcloud.aio.datastore.Query):
    value_kind = Value

class MyVeryCustomGQLQuery(gcloud.aio.datastore.GQLQuery):
    value_kind = Value

You can then drop-in the MyVeryCustomDatastore class anywhere where you previously used Datastore and do the same for Query and GQLQuery.

To override any sub-key, you’ll need to override any parents which use it. For example, if you want to use a custom Key kind and be able to use queries with it, you will need to implement your own Value, Query, and GQLQuery classes and wire them up to the rest of the custom classes:

class MyKey(gcloud.aio.datastore.Key):
    pass

class MyValue(gcloud.aio.datastore.Value):
    key_kind = MyKey

class MyEntity(gcloud.aio.datastore.Entity):
    key_kind = MyKey
    value_kind = MyValue

class MyEntityResult(gcloud.aio.datastore.EntityResult):
    entity_kind = MyEntity

class MyQueryResultBatch(gcloud.aio.datastore.QueryResultBatch):
    entity_result_kind = MyEntityResult

class MyDatastore(gcloud.aio.datastore.Datastore):
    key_kind = MyKey
    entity_result_kind = MyEntityResult
    query_result_batch = MyQueryResultBatch
    value_kind = MyValue

class MyQuery(gcloud.aio.datastore.Query):
    value_kind = MyValue

class MyGQLQuery(gcloud.aio.datastore.GQLQuery):
    value_kind = MyValue

Submodules

Attributes

SCOPES

__version__

Classes

Array

All the operations on a read-only sequence.

CompositeFilterOperator

Create a collection of name/value pairs.

Consistency

Create a collection of name/value pairs.

Direction

Create a collection of name/value pairs.

Mode

Create a collection of name/value pairs.

MoreResultsType

Create a collection of name/value pairs.

Operation

Create a collection of name/value pairs.

PropertyFilterOperator

Create a collection of name/value pairs.

ResultType

Create a collection of name/value pairs.

Datastore

DatastoreOperation

Entity

EntityResult

CompositeFilter

Filter

PropertyFilter

Key

PathElement

LatLng

MutationResult

Projection

PropertyOrder

GQLCursor

GQLQuery

Query

QueryResult

Container class for results returned by a query operation (with or without

QueryResultBatch

ExecutionStats

Container class for executionStats returned by analyze mode.

ExplainMetrics

Container class for explainMetrics returned by query explain.

ExplainOptions

Options for query explain operations.

IndexDefinition

Represents an index that would be used in PlanSummary.

PlanSummary

Container class for planSummary returned by query explain.

ReadOnly

ReadWrite

TransactionOptions

Value

Package Contents

class datastore.Array(items)

Bases: collections.abc.Sequence

All the operations on a read-only sequence.

Concrete subclasses must override __new__ or __init__, __getitem__, and __len__.

Parameters:

items (List[datastore.value.Value])

items
__eq__(other)
Parameters:

other (Any)

Return type:

bool

__repr__()
Return type:

str

__getitem__(index)
Parameters:

index (Any)

Return type:

Any

__len__()
Return type:

int

classmethod from_repr(data)
Parameters:

data (Dict[str, Any])

Return type:

Array

to_repr()
Return type:

Dict[str, Any]

class datastore.CompositeFilterOperator(*args, **kwds)

Bases: enum.Enum

Create a collection of name/value pairs.

Example enumeration:

>>> class Color(Enum):
...     RED = 1
...     BLUE = 2
...     GREEN = 3

Access them by:

  • attribute access:

    >>> Color.RED
    <Color.RED: 1>
    
  • value lookup:

    >>> Color(1)
    <Color.RED: 1>
    
  • name lookup:

    >>> Color['RED']
    <Color.RED: 1>
    

Enumerations can be iterated over, and know how many members they have:

>>> len(Color)
3
>>> list(Color)
[<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]

Methods can be added to enumerations, and members can have their own attributes – see the documentation for details.

AND = 'AND'
OR = 'OR'
UNSPECIFIED = 'OPERATOR_UNSPECIFIED'
class datastore.Consistency(*args, **kwds)

Bases: enum.Enum

Create a collection of name/value pairs.

Example enumeration:

>>> class Color(Enum):
...     RED = 1
...     BLUE = 2
...     GREEN = 3

Access them by:

  • attribute access:

    >>> Color.RED
    <Color.RED: 1>
    
  • value lookup:

    >>> Color(1)
    <Color.RED: 1>
    
  • name lookup:

    >>> Color['RED']
    <Color.RED: 1>
    

Enumerations can be iterated over, and know how many members they have:

>>> len(Color)
3
>>> list(Color)
[<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]

Methods can be added to enumerations, and members can have their own attributes – see the documentation for details.

EVENTUAL = 'EVENTUAL'
STRONG = 'STRONG'
UNSPECIFIED = 'READ_CONSISTENCY_UNSPECIFIED'
class datastore.Direction(*args, **kwds)

Bases: enum.Enum

Create a collection of name/value pairs.

Example enumeration:

>>> class Color(Enum):
...     RED = 1
...     BLUE = 2
...     GREEN = 3

Access them by:

  • attribute access:

    >>> Color.RED
    <Color.RED: 1>
    
  • value lookup:

    >>> Color(1)
    <Color.RED: 1>
    
  • name lookup:

    >>> Color['RED']
    <Color.RED: 1>
    

Enumerations can be iterated over, and know how many members they have:

>>> len(Color)
3
>>> list(Color)
[<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]

Methods can be added to enumerations, and members can have their own attributes – see the documentation for details.

ASCENDING = 'ASCENDING'
DESCENDING = 'DESCENDING'
UNSPECIFIED = 'DIRECTION_UNSPECIFIED'
class datastore.Mode(*args, **kwds)

Bases: enum.Enum

Create a collection of name/value pairs.

Example enumeration:

>>> class Color(Enum):
...     RED = 1
...     BLUE = 2
...     GREEN = 3

Access them by:

  • attribute access:

    >>> Color.RED
    <Color.RED: 1>
    
  • value lookup:

    >>> Color(1)
    <Color.RED: 1>
    
  • name lookup:

    >>> Color['RED']
    <Color.RED: 1>
    

Enumerations can be iterated over, and know how many members they have:

>>> len(Color)
3
>>> list(Color)
[<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]

Methods can be added to enumerations, and members can have their own attributes – see the documentation for details.

NON_TRANSACTIONAL = 'NON_TRANSACTIONAL'
TRANSACTIONAL = 'TRANSACTIONAL'
UNSPECIFIED = 'MODE_UNSPECIFIED'
class datastore.MoreResultsType(*args, **kwds)

Bases: enum.Enum

Create a collection of name/value pairs.

Example enumeration:

>>> class Color(Enum):
...     RED = 1
...     BLUE = 2
...     GREEN = 3

Access them by:

  • attribute access:

    >>> Color.RED
    <Color.RED: 1>
    
  • value lookup:

    >>> Color(1)
    <Color.RED: 1>
    
  • name lookup:

    >>> Color['RED']
    <Color.RED: 1>
    

Enumerations can be iterated over, and know how many members they have:

>>> len(Color)
3
>>> list(Color)
[<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]

Methods can be added to enumerations, and members can have their own attributes – see the documentation for details.

MORE_RESULTS_AFTER_CURSOR = 'MORE_RESULTS_AFTER_CURSOR'
MORE_RESULTS_AFTER_LIMIT = 'MORE_RESULTS_AFTER_LIMIT'
NO_MORE_RESULTS = 'NO_MORE_RESULTS'
NOT_FINISHED = 'NOT_FINISHED'
UNSPECIFIED = 'MORE_RESULTS_TYPE_UNSPECIFIED'
class datastore.Operation(*args, **kwds)

Bases: enum.Enum

Create a collection of name/value pairs.

Example enumeration:

>>> class Color(Enum):
...     RED = 1
...     BLUE = 2
...     GREEN = 3

Access them by:

  • attribute access:

    >>> Color.RED
    <Color.RED: 1>
    
  • value lookup:

    >>> Color(1)
    <Color.RED: 1>
    
  • name lookup:

    >>> Color['RED']
    <Color.RED: 1>
    

Enumerations can be iterated over, and know how many members they have:

>>> len(Color)
3
>>> list(Color)
[<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]

Methods can be added to enumerations, and members can have their own attributes – see the documentation for details.

DELETE = 'delete'
INSERT = 'insert'
UPDATE = 'update'
UPSERT = 'upsert'
class datastore.PropertyFilterOperator(*args, **kwds)

Bases: enum.Enum

Create a collection of name/value pairs.

Example enumeration:

>>> class Color(Enum):
...     RED = 1
...     BLUE = 2
...     GREEN = 3

Access them by:

  • attribute access:

    >>> Color.RED
    <Color.RED: 1>
    
  • value lookup:

    >>> Color(1)
    <Color.RED: 1>
    
  • name lookup:

    >>> Color['RED']
    <Color.RED: 1>
    

Enumerations can be iterated over, and know how many members they have:

>>> len(Color)
3
>>> list(Color)
[<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]

Methods can be added to enumerations, and members can have their own attributes – see the documentation for details.

EQUAL = 'EQUAL'
GREATER_THAN = 'GREATER_THAN'
GREATER_THAN_OR_EQUAL = 'GREATER_THAN_OR_EQUAL'
HAS_ANCESTOR = 'HAS_ANCESTOR'
IN = 'IN'
LESS_THAN = 'LESS_THAN'
LESS_THAN_OR_EQUAL = 'LESS_THAN_OR_EQUAL'
NOT_EQUAL = 'NOT_EQUAL'
NOT_IN = 'NOT_IN'
UNSPECIFIED = 'OPERATOR_UNSPECIFIED'
class datastore.ResultType(*args, **kwds)

Bases: enum.Enum

Create a collection of name/value pairs.

Example enumeration:

>>> class Color(Enum):
...     RED = 1
...     BLUE = 2
...     GREEN = 3

Access them by:

  • attribute access:

    >>> Color.RED
    <Color.RED: 1>
    
  • value lookup:

    >>> Color(1)
    <Color.RED: 1>
    
  • name lookup:

    >>> Color['RED']
    <Color.RED: 1>
    

Enumerations can be iterated over, and know how many members they have:

>>> len(Color)
3
>>> list(Color)
[<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]

Methods can be added to enumerations, and members can have their own attributes – see the documentation for details.

FULL = 'FULL'
KEY_ONLY = 'KEY_ONLY'
PROJECTION = 'PROJECTION'
UNSPECIFIED = 'RESULT_TYPE_UNSPECIFIED'
class datastore.Datastore(project=None, service_file=None, namespace='', session=None, token=None, api_root=None)
Parameters:
  • project (Optional[str])

  • service_file (Optional[Union[str, IO[AnyStr]]])

  • namespace (str)

  • session (Optional[requests.Session])

  • token (Optional[gcloud.aio.auth.Token])

  • api_root (Optional[str])

datastore_operation_kind
entity_result_kind
key_kind
mutation_result_kind
query_result_batch_kind
query_result_kind
value_kind
_project: str | None
_api_root: str
_api_is_dev: bool
Timeout
namespace = ''
session
token
async project()
Return type:

str

static _make_commit_body(mutations, transaction=None, mode=Mode.TRANSACTIONAL)
Parameters:
Return type:

Dict[str, Any]

async headers()
Return type:

Dict[str, str]

classmethod make_mutation(operation, key, properties=None)
Parameters:
Return type:

Dict[str, Any]

async allocateIds(keys, session=None, timeout=10)
Parameters:
  • keys (List[datastore.key.Key])

  • session (Optional[requests.Session])

  • timeout (Timeout)

Return type:

List[datastore.key.Key]

async beginTransaction(session=None, timeout=10)
Parameters:
  • session (Optional[requests.Session])

  • timeout (Timeout)

Return type:

str

async commit(mutations, transaction=None, mode=Mode.TRANSACTIONAL, session=None, timeout=10)
Parameters:
  • mutations (List[Dict[str, Any]])

  • transaction (Optional[str])

  • mode (datastore.constants.Mode)

  • session (Optional[requests.Session])

  • timeout (Timeout)

Return type:

Dict[str, Any]

async export(output_bucket_prefix, kinds=None, namespaces=None, labels=None, session=None, timeout=10)
Parameters:
  • output_bucket_prefix (str)

  • kinds (Optional[List[str]])

  • namespaces (Optional[List[str]])

  • labels (Optional[Dict[str, str]])

  • session (Optional[requests.Session])

  • timeout (Timeout)

Return type:

datastore.datastore_operation.DatastoreOperation

async get_datastore_operation(name, session=None, timeout=10)
Parameters:
  • name (str)

  • session (Optional[requests.Session])

  • timeout (Timeout)

Return type:

datastore.datastore_operation.DatastoreOperation

async lookup(keys, transaction=None, newTransaction=None, consistency=Consistency.STRONG, read_time=None, session=None, timeout=10)
Parameters:
Return type:

LookUpResult

_build_lookup_result(data)
Parameters:

data (Dict[str, Any])

Return type:

LookUpResult

_build_read_options(consistency, newTransaction, transaction, read_time)
Parameters:
Return type:

Dict[str, Any]

async reserveIds(keys, database_id='', session=None, timeout=10)
Parameters:
  • keys (List[datastore.key.Key])

  • database_id (str)

  • session (Optional[requests.Session])

  • timeout (Timeout)

Return type:

None

async rollback(transaction, session=None, timeout=10)
Parameters:
  • transaction (str)

  • session (Optional[requests.Session])

  • timeout (Timeout)

Return type:

None

async runQuery(query, explain_options=None, transaction=None, newTransaction=None, consistency=Consistency.EVENTUAL, read_time=None, session=None, timeout=10)
Parameters:
Return type:

datastore.query.QueryResult

async delete(key, session=None)
Parameters:
Return type:

Dict[str, Any]

async insert(key, properties, session=None)
Parameters:
  • key (datastore.key.Key)

  • properties (Dict[str, Any])

  • session (Optional[requests.Session])

Return type:

Dict[str, Any]

async update(key, properties, session=None)
Parameters:
  • key (datastore.key.Key)

  • properties (Dict[str, Any])

  • session (Optional[requests.Session])

Return type:

Dict[str, Any]

async upsert(key, properties, session=None)
Parameters:
  • key (datastore.key.Key)

  • properties (Dict[str, Any])

  • session (Optional[requests.Session])

Return type:

Dict[str, Any]

async operate(operation, key, properties=None, session=None)
Parameters:
Return type:

Dict[str, Any]

async close()
Return type:

None

async __aenter__()
Return type:

Datastore

async __aexit__(*args)
Parameters:

args (Any)

Return type:

None

datastore.SCOPES = ['https://www.googleapis.com/auth/cloud-platform', 'https://www.googleapis.com/auth/datastore']
class datastore.DatastoreOperation(name, done, metadata=None, error=None, response=None)
Parameters:
  • name (str)

  • done (bool)

  • metadata (Optional[Dict[str, Any]])

  • error (Optional[Dict[str, str]])

  • response (Optional[Dict[str, Any]])

name
done
metadata = None
error = None
response = None
__repr__()
Return type:

str

classmethod from_repr(data)
Parameters:

data (Dict[str, Any])

Return type:

DatastoreOperation

to_repr()
Return type:

Dict[str, Any]

class datastore.Entity(key, properties=None)
Parameters:
key_kind
value_kind
key
properties
__eq__(other)
Parameters:

other (Any)

Return type:

bool

__repr__()
Return type:

str

classmethod from_repr(data)
Parameters:

data (Dict[str, Any])

Return type:

Entity

to_repr()
Return type:

Dict[str, Any]

class datastore.EntityResult(entity, version='', cursor='')
Parameters:
  • entity (Entity)

  • version (str)

  • cursor (str)

entity_kind
entity
version = ''
cursor = ''
__eq__(other)
Parameters:

other (Any)

Return type:

bool

__repr__()
Return type:

str

classmethod from_repr(data)
Parameters:

data (Dict[str, Any])

Return type:

EntityResult

to_repr()
Return type:

Dict[str, Any]

class datastore.CompositeFilter(operator, filters)

Bases: BaseFilter

Parameters:
json_key = 'compositeFilter'
operator
filters
__eq__(other)
Parameters:

other (Any)

Return type:

bool

classmethod from_repr(data)
Parameters:

data (Dict[str, Any])

Return type:

CompositeFilter

to_repr()
Return type:

Dict[str, Any]

class datastore.Filter(inner_filter)
Parameters:

inner_filter (BaseFilter)

inner_filter
__repr__()
Return type:

str

__eq__(other)
Parameters:

other (Any)

Return type:

bool

classmethod from_repr(data)
Parameters:

data (Dict[str, Any])

Return type:

Filter

to_repr()
Return type:

Dict[str, Any]

class datastore.PropertyFilter(prop, operator, value)

Bases: BaseFilter

Parameters:
json_key = 'propertyFilter'
prop
operator
value
__eq__(other)
Parameters:

other (Any)

Return type:

bool

classmethod from_repr(data)
Parameters:

data (Dict[str, Any])

Return type:

PropertyFilter

to_repr()
Return type:

Dict[str, Any]

class datastore.Key(project, path, namespace='')
Parameters:
  • project (str)

  • path (List[PathElement])

  • namespace (str)

path_element_kind
project
namespace = ''
path
__eq__(other)
Parameters:

other (Any)

Return type:

bool

__repr__()
Return type:

str

classmethod from_repr(data)
Parameters:

data (Dict[str, Any])

Return type:

Key

to_repr()
Return type:

Dict[str, Any]

class datastore.PathElement(kind, *, id_=None, name=None)
Parameters:
  • kind (str)

  • id_ (Optional[int])

  • name (Optional[str])

kind
id = None
name = None
__eq__(other)
Parameters:

other (Any)

Return type:

bool

__repr__()
Return type:

str

classmethod from_repr(data)
Parameters:

data (Dict[str, Any])

Return type:

PathElement

to_repr()
Return type:

Dict[str, Any]

class datastore.LatLng(lat, lon)
Parameters:
  • lat (float)

  • lon (float)

lat
lon
__eq__(other)
Parameters:

other (Any)

Return type:

bool

__repr__()
Return type:

str

classmethod from_repr(data)
Parameters:

data (Dict[str, Any])

Return type:

LatLng

to_repr()
Return type:

Dict[str, Any]

class datastore.MutationResult(key, version, conflict_detected)
Parameters:
key_kind
key
version
conflict_detected
__eq__(other)
Parameters:

other (Any)

Return type:

bool

__repr__()
Return type:

str

classmethod from_repr(data)
Parameters:

data (Dict[str, Any])

Return type:

MutationResult

to_repr()
Return type:

Dict[str, Any]

class datastore.Projection(prop)
Parameters:

prop (str)

prop
__eq__(other)
Parameters:

other (Any)

Return type:

bool

__repr__()
Return type:

str

classmethod from_repr(data)
Parameters:

data (Dict[str, Any])

Return type:

Projection

to_repr()
Return type:

Dict[str, Any]

class datastore.PropertyOrder(prop, direction=Direction.ASCENDING)
Parameters:
prop
direction
__eq__(other)
Parameters:

other (Any)

Return type:

bool

__repr__()
Return type:

str

classmethod from_repr(data)
Parameters:

data (Dict[str, Any])

Return type:

PropertyOrder

to_repr()
Return type:

Dict[str, Any]

class datastore.GQLCursor(value)
Parameters:

value (str)

value
__eq__(other)
Parameters:

other (Any)

Return type:

bool

class datastore.GQLQuery(query_string, allow_literals=True, named_bindings=None, positional_bindings=None)

Bases: BaseQuery

Parameters:
  • query_string (str)

  • allow_literals (bool)

  • named_bindings (Optional[Dict[str, Any]])

  • positional_bindings (Optional[List[Any]])

json_key = 'gqlQuery'
query_string
allow_literals = True
named_bindings
positional_bindings = []
__eq__(other)
Parameters:

other (Any)

Return type:

bool

classmethod from_repr(data)
Parameters:

data (Dict[str, Any])

Return type:

GQLQuery

classmethod _param_from_repr(param_repr)
Parameters:

param_repr (Dict[str, Any])

Return type:

Any

to_repr()
Return type:

Dict[str, Any]

_param_to_repr(param)
Parameters:

param (Any)

Return type:

Dict[str, Any]

class datastore.Query(kind='', query_filter=None, order=None, start_cursor='', end_cursor='', offset=None, limit=None, projection=None, distinct_on=None)

Bases: BaseQuery

Parameters:
json_key = 'query'
kind = ''
query_filter = None
orders = []
start_cursor = ''
end_cursor = ''
offset = None
limit = None
projection = []
distinct_on = []
__eq__(other)
Parameters:

other (Any)

Return type:

bool

classmethod from_repr(data)
Parameters:

data (Dict[str, Any])

Return type:

Query

to_repr()
Return type:

Dict[str, Any]

class datastore.QueryResult(result_batch=None, explain_metrics=None, transaction=None)

Container class for results returned by a query operation (with or without explain metrics).

Parameters:
query_result_batch_kind
result_batch = None
explain_metrics = None
transaction = None
__repr__()
Return type:

str

__eq__(other)
Parameters:

other (object)

Return type:

bool

classmethod from_repr(data)
Parameters:

data (Dict[str, Any])

Return type:

QueryResult

to_repr()
Return type:

Dict[str, Any]

get_explain_metrics()
Return type:

Optional[datastore.query_explain.ExplainMetrics]

get_plan_summary()
Return type:

Optional[datastore.query_explain.PlanSummary]

get_execution_stats()
Return type:

Optional[datastore.query_explain.ExecutionStats]

class datastore.QueryResultBatch(end_cursor, entity_result_type=ResultType.UNSPECIFIED, entity_results=None, more_results=MoreResultsType.UNSPECIFIED, skipped_cursor='', skipped_results=0, snapshot_version='', read_time=None)
Parameters:
entity_result_kind
end_cursor
entity_result_type
entity_results = []
more_results
skipped_cursor = ''
skipped_results = 0
snapshot_version = ''
read_time = None
__eq__(other)
Parameters:

other (Any)

Return type:

bool

__repr__()
Return type:

str

classmethod from_repr(data)
Parameters:

data (Dict[str, Any])

Return type:

QueryResultBatch

to_repr()
Return type:

Dict[str, Any]

class datastore.ExecutionStats(results_returned=0, execution_duration=0.0, read_operations=0, debug_stats=None)

Container class for executionStats returned by analyze mode.

Parameters:
  • results_returned (int)

  • execution_duration (float)

  • read_operations (int)

  • debug_stats (Optional[Dict[str, Any]])

results_returned = 0
execution_duration = 0.0
read_operations = 0
debug_stats
__repr__()
Return type:

str

__eq__(other)
Parameters:

other (object)

Return type:

bool

static _parse_execution_duration(execution_duration)

Convert execution_duration from str (e.g. “0.01785s”) to float.

Parameters:

execution_duration (Optional[Union[str, float]])

Return type:

float

static _parse_debug_stats(debug_stats)

Convert debug_stats values from str to int.

Parameters:

debug_stats (Dict[str, Any])

Return type:

Dict[str, Any]

classmethod from_repr(data)
Parameters:

data (Dict[str, Any])

Return type:

ExecutionStats

to_repr()
Return type:

Dict[str, Any]

class datastore.ExplainMetrics(plan_summary=None, execution_stats=None)

Container class for explainMetrics returned by query explain.

Parameters:
plan_summary = None
execution_stats = None
__repr__()
Return type:

str

__eq__(other)
Parameters:

other (object)

Return type:

bool

classmethod from_repr(data)
Parameters:

data (Dict[str, Any])

Return type:

ExplainMetrics

to_repr()
Return type:

Dict[str, Any]

class datastore.ExplainOptions(*args, **kwds)

Bases: enum.Enum

Options for query explain operations.

DEFAULT = False
ANALYZE = True
to_repr()
Return type:

Dict[str, bool]

classmethod from_repr(data)
Parameters:

data (Dict[str, bool])

Return type:

ExplainOptions

class datastore.IndexDefinition(query_scope='', properties=None)

Represents an index that would be used in PlanSummary.

Raw:
[
{

“query_scope”: “Collection group”, “properties”: “(done ASC, priority DESC, __name__ ASC)”

}

]

query_scope: “Collection group” properties: [(“done”, “ASC”), (“priority”, “DESC”), (“__name__”, “ASC”)]

Parameters:
  • query_scope (str)

  • properties (Optional[List[Tuple[str, str]]])

_PROPERTIES_PATTERN
query_scope = ''
properties = []
__repr__()
Return type:

str

__eq__(other)
Parameters:

other (Any)

Return type:

bool

classmethod from_repr(data)
Parameters:

data (Dict[str, Any])

Return type:

IndexDefinition

to_repr()
Return type:

Dict[str, Any]

class datastore.PlanSummary(indexes_used=None)

Container class for planSummary returned by query explain.

Parameters:

indexes_used (Optional[List[IndexDefinition]])

indexes_used = []
__repr__()
Return type:

str

__eq__(other)
Parameters:

other (object)

Return type:

bool

classmethod from_repr(data)
Parameters:

data (Dict[str, Any])

Return type:

PlanSummary

to_repr()
Return type:

Dict[str, Any]

class datastore.ReadOnly
to_repr()
Return type:

Dict[str, str]

class datastore.ReadWrite(previous_transaction=None)
Parameters:

previous_transaction (Optional[str])

previous_transaction = None
to_repr()
Return type:

Dict[str, str]

class datastore.TransactionOptions(option)
Parameters:

option (Union[ReadWrite, ReadOnly])

option
to_repr()
Return type:

Dict[str, Dict[str, str]]

class datastore.Value(value, exclude_from_indexes=False)
Parameters:
  • value (Any)

  • exclude_from_indexes (bool)

key_kind
value
excludeFromIndexes = False
__eq__(other)
Parameters:

other (Any)

Return type:

bool

__repr__()
Return type:

str

classmethod from_repr(data)
Parameters:

data (Dict[str, Any])

Return type:

Value

to_repr()
Return type:

Dict[str, Any]

_infer_type(value)
Parameters:

value (Any)

Return type:

datastore.constants.TypeName

classmethod _get_supported_types()
Return type:

Dict[Any, datastore.constants.TypeName]

datastore.__version__