Search code examples
google-app-enginegoogle-cloud-datastore

app engine ndb - how to load entity by key using id?


I am trying to load an entity by key using the id it was assigned by the datastore but I don't see any api method to do this (using NDB). I thought I would be able to make a Key from an integer id and use key.get() to load the entity, but I don't see a way to make a key from just an id. I suspect I am missing something obvious here. How should I load an entity where I only know the id of it?


Solution

  • YourModel.get_by_id() gets a model instance by id.

    here the docs:
    https://developers.google.com/appengine/docs/python/ndb/modelclass#Model_get_by_id

    don't think you can't get an entity by id without knowing the kind because instances of different Model classes can have the same id/key_name