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

How to access properties of Datastore query (App Engine, python)


I'm going nuts trying to access the properties of a Datastore query. I could not find anything in the documentation (it could be me).

In the datastore I have the following:

enter image description here

Here's a snippet of my main.py:

import all the necessary stuff
...
datastore_client = datastore.Client()
u_name = 'batman' # example of the user I want to find
qn = datastore_client.query(kind='user').add_filter('user_id', '=', u_name).fetch()

So far so good, but how do I access the properties of this query?

What I haven't been able to find is how do I access the first_name of user 'batman'? Something like:

name = qn.somefuntion('first_name')

Could someone tell me how to do this and also point me to the respective documentation?

Thanks!


Solution

  • Check out the python library reference for an Entity. The key part there is "you can treat an entity like a regular Python dictionary."

    for entity in qn:
        print(entity['first_name'])