For existing entity on Google Cloud Datastore I would like to add a new property as a Blob?

Question:

For existing entity on Google Cloud Datastore I would like to add a new property "s11_data" for all of the keys within that entity. I click on a key and click on New Property and name it appropriately, save, and voila. It is now a property column [set to null] for all of the keys. But I want this property to be a Blob (like some of the existing entries are already). If I click one of the existing entries, then "Blob" is an option in the drop-down menu of the property pane.

But it is not an option for the new property. I thought the resolution was to be sure to turn off indexing. But nope, even with Index unchecked the Blob option does not appear.

I’m happy to set it via Python is that is best way forward, but I can’t work that out either (I can client.put() a property value but cannot find how to assign a property type.

Suggestions appreciated. Thanks,

Edit: here is the drop-down menu showing "Blob"enter image description here

Asked By: Tunneller

||

Answers:

If you wish to do it in code via Python, then I don’t believe blob is a property if you’re using the datastore library (see types). But you can get it as a property if you’re using the ndb library

  1. If you’re using the bundled ndb library, then you can set the property type in your model definition (see documentation for property types) e.g.
    s11_data = ndb.BlobProperty()
  1. If you’re using cloud ndb library, you also define it in model definition (see documentation) e.g.
    class YourModel(Model):
        s11_data = BlobProperty()
        
  1. It looks like you can also specify a blob if you’re directly making REST API calls. Refer to documentation (see blobValue field)
Answered By: NoCommandLine

Actually easier than I thought. Just write a bytes class and Google automatically sets it as a Blob

json_data = {}
json_data["V"] = 0.123
json_data["Q"] = 4. 
a = codecs.encode(json.dumps(json_data).encode('utf-8'), encoding='zlib_codec')

with client.transaction():    
   task = client.get(key)    
   task["s11_data"] = a
   client.put(task)

google snapshot

Answered By: Tunneller