Skip to content

Instantly share code, notes, and snippets.

@xlfe
Created June 30, 2019 05:56
Show Gist options
  • Save xlfe/af25f160256e4d52f499dee7e8fa212f to your computer and use it in GitHub Desktop.
Save xlfe/af25f160256e4d52f499dee7e8fa212f to your computer and use it in GitHub Desktop.
Export from Google App Engine Datastore Backup LevelDB format to JSON flat file
import sys, os, json
import datetime
sys.path.append(os.path.expanduser('~/google-cloud-sdk/platform/google_appengine/'))
from google.appengine.api.files import records
from google.appengine.datastore import entity_pb
from google.appengine.api import datastore
def myconverter(o):
if isinstance(o, datetime.datetime):
return o.isoformat()
for path, dirs, files in os.walk('./'):
for fn in files:
f = os.path.join(path, fn)
if not fn.startswith('output'):
continue
with open(f, 'r') as raw:
reader = records.RecordsReader(raw)
for record in reader:
entity_proto = entity_pb.EntityProto(contents=record)
entity = datastore.Entity.FromPb(entity_proto)
entity['table'] = path[2:]
j = json.dumps(entity, default=myconverter)
print (j)
@pansapiens
Copy link

Thanks for this ! It helped me export some data from an old App Engine app that I'd been putting off doing for years. I've forked it with some extra instructions and tweaks to better export entity kinds and key paths (ie entity identifiers) for my purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment