Alex Rivera | Logout

How do I calculate the size of an entity stored in Google App Engine?

Asked 2010-06-15T02:46:16.747
12

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.

Edit
Report

1 Answer

19

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())

Update for ndb

Kekito points out in the comments below that for ndb entities a different approach is needed (Thanks Kekito!):

len(some_entity._to_pb().Encode())
answered 2010-06-15T02:55:41.657

Your Answer