'Constructs a "key" value for the given entity based on the current order.
This function can be used as the key argument for list.sort() and sorted().
Args:
entity: The entity_pb.EntityProto to convert
filter_predicate: A FilterPredicate used to prune values before comparing
entities or None.
Returns:
A key value that identifies the position of the entity when sorted by
the current order.'

def key(self, entity, filter_predicate=None):

    names = self._get_prop_names()
    names.add(datastore_types.KEY_SPECIAL_PROPERTY)
    if (filter_predicate is not None):
        names |= filter_predicate._get_prop_names()
    value_map = _make_key_value_map(entity, names)
    if (filter_predicate is not None):
        filter_predicate._prune(value_map)
    return (self._key(value_map), value_map[datastore_types.KEY_SPECIAL_PROPERTY])
