'Returns the number of entities that this query matches.
Args:
limit, a number or None. If there are more results than this, stop short
and just return this number. Providing this argument makes the count
operation more efficient.
config: Optional Configuration to use for this request.
Returns:
The number of results.'

def Count(self, limit=1000, **kwargs):

    original_offset = kwargs.pop('offset', 0)
    if (limit is None):
        offset = _MAX_INT_32
    else:
        offset = min((limit + original_offset), _MAX_INT_32)
    kwargs['limit'] = 0
    kwargs['offset'] = offset
    config = _GetConfigFromKwargs(kwargs, convert_rpc=True, config_class=datastore_query.QueryOptions)
    batch = self.GetBatcher(config=config).next()
    self.__index_list_source = (lambda : [index for (index, state) in batch.index_list])
    self.__cursor_source = (lambda : batch.cursor(0))
    self.__compiled_query_source = (lambda : batch._compiled_query)
    return max(0, (batch.skipped_results - original_offset))
