Koopa Troopa
Koopa Troopa

Reputation: 28

What is the "Entity" part of the Datastore query results list?

From the Google docs, one can store Datastore query results like so:

from google.cloud import datastore
client = datastore.Client()
query = client.query()
results = list(query.fetch())

Which returns e.g.:

[<Entity('my_kind', '00001') {'my_property_01': 'abc', 'my_property_02': 'xyz'}>]

My question, which might be more related to Python than to Google Datastore, is what's going on with this list? It's enclosed in angle brackets, and has no separator between the round brackets and curly brackets. Is this a normal list, and does this format have much use in Python coding?

Upvotes: 0

Views: 55

Answers (1)

Jim Morrison
Jim Morrison

Reputation: 2887

results is a normal list. However, since you only have one result you are only seeing one entity with the key ('my_kind', '0001'), and properties of my_property_01 & my_property_02. You are probably surprised in how the Entity class overrides the __str__ method to describe the entity this way.

Upvotes: 1

Related Questions