pythongoogle-cloud-platformgoogle-cloud-datastoredatastoreendpoints-proto-datastore

Access metadata of namespace in Datastore


Is there any way to access metadata of a namespace in Google Cloud Datastore? Im interested in getting something like a created_at property.

In order to find out all provided properties/attributes for a namespace:

ds_client = get_datastore_client(project=PROJECT)

query = ds_client.query(kind="__namespace__")
query.keys_only()
for ns in  query.fetch():
    print(ns)
    print(dir(ns))

Output:

<Entity('__namespace__', 'xxxxx') {}>
['__class__', '__contains__', '__delattr__', '__delitem__', '__dict__', '__dir__',
 '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', 
'__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', 
'__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', 
'__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__',
 '_meanings', 'clear', 'copy', 'exclude_from_indexes', 'fromkeys', 'get', 'id', 'items',
 'key', 'keys', 'kind', 'pop', 'popitem', 'setdefault', 'update', 'values']

Nothing seems promising


Solution

  • Namespaces are implicitly created, so there isn't a backing entity for each namespace. Thus there isn't metadata on a namespace. Stats entities Stat_Ns_Total are the closest thing to metadata for namespaces.

    The entities from __namespace__ aren't stored entities and are created for the query itself.

    Each entity in Firestore in Datastore mode has a version field that's available through the EntityResult, but the python client library strips that away from you :( and only provides an updated time and not a created time.