'Unique key for this entity.
This property is only available if this entity is already stored in the
datastore or if it has a full key, so it is available if this entity was
fetched returned from a query, or after put() is called the first time
for new entities, or if a complete key was given when constructed.
Returns:
Datastore key of persisted entity.
Raises:
NotSavedError when entity is not persistent.'

def key(self):

    if self.is_saved():
        return self._entity.key()
    elif self._key:
        return self._key
    elif self._key_name:
        parent = (self._parent_key or (self._parent and self._parent.key()))
        self._key = Key.from_path(self.kind(), self._key_name, parent=parent, _app=self._app, namespace=self.__namespace)
        return self._key
    else:
        raise NotSavedError()
