google.appengine.ext.ndb.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__, __property__ and __entity_group__ metadata queries or gets.

A simplified API is also offered:

ndb.metadata.get_namespaces(): A list of namespace names. ndb.metadata.get_kinds(): A list of kind names. ndb.metadata.get_properties_of_kind(kind):

A list of property names for the given kind name.

ndb.metadata.get_representations_of_kind(kind):

A dict mapping property names to lists of representation ids.

ndb.metadata.get_entity_group_version(key):

The version of the entity group containing key (HRD only).

get_kinds(), get_properties_of_kind(), get_representations_of_kind() implicitly apply to the current namespace.

get_namespaces(), get_kinds(), get_properties_of_kind(), get_representations_of_kind() have optional start and end arguments to limit the query to a range of names, such that start <= name < end.

Contents

class google.appengine.ext.ndb.metadata.Namespace(*args, **kwds)source

Bases: google.appengine.ext.ndb.metadata._BaseMetadata

Model for __namespace__ metadata query results.

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

Return the Key for a namespace.

Parameters

namespace – A string giving the namespace whose key is requested.

Returns

The Key for the 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.ndb.metadata.Kind(*args, **kwds)source

Bases: google.appengine.ext.ndb.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.ndb.metadata.Property(*args, **kwds)source

Bases: google.appengine.ext.ndb.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

An indexed Property whose value is a text string of limited length.

class google.appengine.ext.ndb.metadata.EntityGroup(*args, **kwds)source

Bases: google.appengine.ext.ndb.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 if the entity group was never written to.

ID = 1
KIND_NAME = '__entity_group__'
classmethod key_for_entity_group(key)source

Return the key for the entity group containing key.

Parameters

key – a key for an entity group whose __entity_group__ key you want.

Returns

The __entity_group__ key for the entity group containing key.

version

A Property whose value is a Python int or long (or bool).

google.appengine.ext.ndb.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.ndb.metadata.get_kinds(start=None, end=None)source

Return all kinds in the specified range, for the current namespace.

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.ndb.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.ndb.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.

google.appengine.ext.ndb.metadata.get_entity_group_version(key)source

Return the version of the entity group containing key.

Parameters

key – a key for an entity group whose __entity_group__ key you want.

Returns

The version of the entity group containing 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.