No need for metadata requests. The NDB method for requesting a request for __key__ as follows:
ModelClass.query(ModelClass._key == key_value)
Just as a request for the foo property is performed by filtering on ModelClass.foo == value , ModelClass._key is a pseudo-property representing the key.
Other posters are correct if you are only one object with a full key, using the get() method on a Key object is better (faster and cheaper). In addition, if e is an entity (an instance of the model), in NDB the key is not e.key() , but e.key (or e._key - yes, the same _key attribute that I mentioned above, it works like a class attribute and as an attribute of an instance).
Indeed, if you have a urlsafe key (for example, 'agFfcg4LEghFbXBsb3llZRgDDA' ), the way to turn it into a Key ndb.Key(urlsafe='agFfcg4LEghFbXBsb3llZRgDDA') object ndb.Key(urlsafe='agFfcg4LEghFbXBsb3llZRgDDA') .
Good luck
source share