google.appengine.ext.db.metadata module

Summary

Models and helper functions for access to app’s datastore metadata.

These entities cannot be created by users, but are created as results of __namespace__, __kind__ and __property__ metadata queries such as

# Find all namespaces q = db.GqlQuery(“SELECT * FROM __namespace__”) for p in q.run():

print “namespace:”, repr(p.namespace_name)

or

# Find all properties of A whose name starts with a lower-case letter q = db.GqlQuery(“SELECT __key__ from __property__ ” +

“WHERE __key__ >= :1 AND __key__ < :2”, Property.key_for_property(“A”, “a”), Property.key_for_property(“A”, chr(ord(“z”) + 1)))

for p in q.run():

print “%s: %s” % (Property.key_to_kind(p), Property.key_to_property(p))

or, using Query objects

# Find all kinds >= “a” q = metadata.Kind().all() q.filter(“__key__ >=”, metadata.Kind.key_for_kind(“a”)) for p in q.run():

print “kind:”, repr(p.kind_name)

Contents

class google.appengine.ext.db.metadata.BaseMetadata(parent=None, key_name=None, _app=None, _from_entity=False, **kwds)source

Bases: google.appengine.ext.db.Model

Base class for all metadata models.

KIND_NAME = '__BaseMetadata__'
classmethod kind()source

Kind name override.

class google.appengine.ext.db.metadata.EntityGroup(parent=None, key_name=None, _app=None, _from_entity=False, **kwds)source

Bases: google.appengine.ext.db.metadata.BaseMetadata

Model for __entity_group__ metadata (available in HR datastore only).

This metadata contains a numeric __version__ property that is guaranteed to increase on every change to the entity group. The version may increase even in the absence of user-visible changes to the entity group. The __entity_group__ entity may not exist None if the entity group was never written to.

ID = 1
KIND_NAME = '__entity_group__'
classmethod key_for_entity(entity_or_key)source

Return the metadata key for the entity group containing entity_or_key.

Use this key to get() the __entity_group__ metadata entity for the entity group containing entity_or_key.

Parameters

entity_or_key – a key or entity whose __entity_group__ key you want.

Returns

The __entity_group__ key for the entity group containing entity_or_key.

version

An integer property.

class google.appengine.ext.db.metadata.Kind(parent=None, key_name=None, _app=None, _from_entity=False, **kwds)source

Bases: google.appengine.ext.db.metadata.BaseMetadata

Model for __kind__ metadata query results.

KIND_NAME = '__kind__'
classmethod key_for_kind(kind)source

Return the __kind__ key for kind.

Parameters

kind – kind whose key is requested.

Returns

The key for kind.

classmethod key_to_kind(key)source

Return the kind specified by a given __kind__ key.

Parameters

key – key whose name is requested.

Returns

The kind specified by key.

kind_name

Return the kind name specified by this entity’s key.

class google.appengine.ext.db.metadata.Namespace(parent=None, key_name=None, _app=None, _from_entity=False, **kwds)source

Bases: google.appengine.ext.db.metadata.BaseMetadata

Model for __namespace__ metadata query results.

EMPTY_NAMESPACE_ID = 1
KIND_NAME = '__namespace__'
classmethod key_for_namespace(namespace)source

Return the __namespace__ key for namespace.

Parameters

namespace – namespace whose key is requested.

Returns

The key for namespace.

classmethod key_to_namespace(key)source

Return the namespace specified by a given __namespace__ key.

Parameters

key – key whose name is requested.

Returns

The namespace specified by key.

namespace_name

Return the namespace name specified by this entity’s key.

class google.appengine.ext.db.metadata.Property(parent=None, key_name=None, _app=None, _from_entity=False, **kwds)source

Bases: google.appengine.ext.db.metadata.BaseMetadata

Model for __property__ metadata query results.

KIND_NAME = '__property__'
classmethod key_for_kind(kind)source

Return the __property__ key for kind.

Parameters

kind – kind whose key is requested.

Returns

The parent key for __property__ keys of kind.

classmethod key_for_property(kind, property)source

Return the __property__ key for property of kind.

Parameters
  • kind – kind whose key is requested.

  • property – property whose key is requested.

Returns

The key for property of kind.

classmethod key_to_kind(key)source

Return the kind specified by a given __property__ key.

Parameters

key – key whose kind name is requested.

Returns

The kind specified by key.

classmethod key_to_property(key)source

Return the property specified by a given __property__ key.

Parameters

key – key whose property name is requested.

Returns

property specified by key, or None if the key specified only a kind.

kind_name

Return the kind name specified by this entity’s key.

property_name

Return the property name specified by this entity’s key.

property_representation

A property that stores a list of strings.

A shorthand for the most common type of ListProperty.

google.appengine.ext.db.metadata.get_entity_group_version(entity_or_key)source

Return the version of the entity group containing entity_or_key.

Parameters

entity_or_key – a key or entity whose version you want.

Returns: The version of the entity group containing entity_or_key. This

version is guaranteed to increase on every change to the entity group. The version may increase even in the absence of user-visible changes to the entity group. May return None if the entity group was never written to.

On non-HR datatores, this function returns None.

google.appengine.ext.db.metadata.get_kinds(start=None, end=None)source

Return all kinds in the specified range.

Parameters
  • start – only return kinds >= start if start is not None.

  • end – only return kinds < end if end is not None.

Returns

A list of kind names between the (optional) start and end values.

google.appengine.ext.db.metadata.get_namespaces(start=None, end=None)source

Return all namespaces in the specified range.

Parameters
  • start – only return namespaces >= start if start is not None.

  • end – only return namespaces < end if end is not None.

Returns

A list of namespace names between the (optional) start and end values.

google.appengine.ext.db.metadata.get_properties_of_kind(kind, start=None, end=None)source

Return all properties of kind in the specified range.

NOTE: This function does not return unindexed properties.

Parameters
  • kind – name of kind whose properties you want.

  • start – only return properties >= start if start is not None.

  • end – only return properties < end if end is not None.

Returns

A list of property names of kind between the (optional) start and end values.

google.appengine.ext.db.metadata.get_representations_of_kind(kind, start=None, end=None)source

Return all representations of properties of kind in the specified range.

NOTE: This function does not return unindexed properties.

Parameters
  • kind – name of kind whose properties you want.

  • start – only return properties >= start if start is not None.

  • end – only return properties < end if end is not None.

Returns

A dictionary mapping property names to its list of representations.