Reputation: 2331
Is there an easy way to calculate the size of an entity stored in App Engine? I would like to know how close a particular entity is to hitting the 1 MB upper limit on entity size.
Upvotes: 13
Views: 2338
Reputation: 16243
App engine stores each entity as a protobuf. You can use the db.model_to_protobuf()
function described here to manually convert your entity into a protobuf and then use the standard len()
method to determine its size in bytes.
Example usage:
from google.appengine.ext import db
sz_in_bytes = len(db.model_to_protobuf(some_entity).Encode())
Kekito points out in the comments below that for ndb
entities a different approach is needed (Thanks Kekito!):
len(some_entity._to_pb().Encode())
Upvotes: 20