Add ndb support.

Thanks for the useful code!

I've made this modification to add ndb support; feel free to take it if you like.