It is hard to explain, Based on the document
https://developers.google.com/appengine/docs/python/ndb/keyclass?hl=zh-tw
Keys support comparisons, for example key1 == key2 or key1 < key2. These operators compare application ID, namespace, and the full "ancestor path". They use the same ordering as the Datastore uses for queries when ordering by a key property or by key.
the cheat sheet https://docs.google.com/document/d/1AefylbadN456_Z7BZOpZEXDq8cR8LYu7QgI7bt5V0Iw/mobilebasic
and the source code. all show that the usage should be ok. The key compair the app_id, the namesapce, and the key pairs in order. Maybe you can tried to print the (key.app(), key.namespace(), key.pairs()) to see the details.
https://code.google.com/p/appengine-ndb-experiment/source/browse/ndb/key.py
def __gt__(self, other):
"""Greater than ordering."""
if not isinstance(other, Key):
return NotImplemented
return self.__tuple() > other.__tuple()
def __tuple(self):
"""Helper to return an orderable tuple."""
return (self.app(), self.namespace(), self.pairs())