Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get a list of namespaces on google app engine?

I would like to make a backup of all user data in the datastore. My application is using the new namespace feature to provide multi tenanting on a per user basis (as per the example in the docs).

The bulk loader needs the namespace for each customer to download the data. I don't keep a list of users, so I can't generate the namespaces. Is there a method of detecting all the currently used namespaces?

like image 349
No Name Avatar asked Aug 30 '10 18:08

No Name


People also ask

What are namespaces in GCP?

What is a Namespace? You can think of a Namespace as a virtual cluster inside your Kubernetes cluster. You can have multiple namespaces inside a single Kubernetes cluster, and they are all logically isolated from each other. They can help you and your teams with organization, security, and even performance!

What is data store in Google App Engine?

Datastore is a NoSQL document database built for automatic scaling, high performance, and ease of application development. Datastore features include: Atomic transactions. Datastore can execute a set of operations where either all succeed, or none occur. High availability of reads and writes.

What do you mean by namespace?

A namespace is a declarative region that provides a scope to the identifiers (the names of types, functions, variables, etc) inside it. Namespaces are used to organize code into logical groups and to prevent name collisions that can occur especially when your code base includes multiple libraries.

What is namespace in cloud?

A namespace is a way to group services for an application. When you create a namespace, you specify how you want to discover service instances that you register with AWS Cloud Map: using API calls or using DNS queries. You also specify the name that you want your application to use to discover instances. Topics.


2 Answers

Using ndb

from google.appengine.ext.ndb import metadata
all_namespaces = [ns for ns in metadata.get_namespaces()]

Using datastore

Per Datastore Metadata:

query = client.query(kind='__namespace__')
query.keys_only()   
all_namespaces = [entity.key.id_or_name for entity in query.fetch()]
like image 121
Brian M. Hunt Avatar answered Oct 22 '22 14:10

Brian M. Hunt


Since SDK 1.4.0 you can use Metadata Queries:

from google.appengine.ext.db import metadata

for ns in metadata.get_namespaces():
    print "namespace: '%s'" % ns.namespace_name

For NDB the import is slightly different:

from google.appengine.ext.ndb import metadata
like image 41
systempuntoout Avatar answered Oct 22 '22 15:10

systempuntoout