App Engine Python SDK  v1.6.9 rev.445
The Python runtime is available as an experimental Preview feature.
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
google.appengine.api.datastore_types.Key Class Reference
Inheritance diagram for google.appengine.api.datastore_types.Key:

Public Member Functions

def __init__
 
def to_path
 
def app
 
def namespace
 
def kind
 
def id
 
def name
 
def id_or_name
 
def has_id_or_name
 
def parent
 
def ToTagUri
 
def entity_group
 
def __str__
 
def __repr__
 
def __cmp__
 
def __hash__
 

Static Public Member Functions

def from_path
 

Static Public Attributes

 ToXml = ToTagUri
 

Detailed Description

The primary key for a datastore entity.

A datastore GUID. A Key instance uniquely identifies an entity across all
apps, and includes all information necessary to fetch the entity from the
datastore with Get().

Key implements __hash__, and key instances are immutable, so Keys may be
used in sets and as dictionary keys.

Constructor & Destructor Documentation

def google.appengine.api.datastore_types.Key.__init__ (   self,
  encoded = None 
)
Constructor. Creates a Key from a string.

Args:
  # a base64-encoded primary key, generated by Key.__str__
  encoded: str

Member Function Documentation

def google.appengine.api.datastore_types.Key.__cmp__ (   self,
  other 
)
Returns negative, zero, or positive when comparing two keys.

TODO: for API v2, we should change this to make incomplete keys, ie
keys without an id or name, not equal to any other keys.

Args:
  other: Key to compare to.

Returns:
  Negative if self is less than "other"
  Zero if "other" is equal to self
  Positive if self is greater than "other"
def google.appengine.api.datastore_types.Key.__hash__ (   self)
Returns an integer hash of this key.

Implements Python's hash protocol so that Keys may be used in sets and as
dictionary keys.

Returns:
  int
def google.appengine.api.datastore_types.Key.__repr__ (   self)
Returns an eval()able string representation of this key.

Returns a Python string of the form 'datastore_types.Key.from_path(...)'
that can be used to recreate this key.

Returns:
  string
def google.appengine.api.datastore_types.Key.__str__ (   self)
Encodes this Key as an opaque string.

Returns a string representation of this key, suitable for use in HTML,
URLs, and other similar use cases. If the entity's key is incomplete,
raises a BadKeyError.

Unfortunately, this string encoding isn't particularly compact, and its
length varies with the length of the path. If you want a shorter identifier
and you know the kind and parent (if any) ahead of time, consider using just
the entity's id or name.

Returns:
  string
def google.appengine.api.datastore_types.Key.app (   self)
Returns this entity's app id, a string.
def google.appengine.api.datastore_types.Key.entity_group (   self)
Returns this key's entity group as a Key.

Note that the returned Key will be incomplete if this Key is for a root
entity and it is incomplete.
def google.appengine.api.datastore_types.Key.from_path (   args,
  kwds 
)
static
Static method to construct a Key out of a "path" (kind, id or name, ...).

This is useful when an application wants to use just the id or name portion
of a key in e.g. a URL, where the rest of the URL provides enough context to
fill in the rest, i.e. the app id (always implicit), the entity kind, and
possibly an ancestor key. Since ids and names are usually small, they're
more attractive for use in end-user-visible URLs than the full string
representation of a key.

Args:
  kind: the entity kind (a str or unicode instance)
  id_or_name: the id (an int or long) or name (a str or unicode instance)
  parent: optional parent Key; default None.
  namespace: optional namespace to use otherwise namespace_manager's
default namespace is used.

Returns:
  A new Key instance whose .kind() and .id() or .name() methods return
  the *last* kind and id or name positional arguments passed.

Raises:
  BadArgumentError for invalid arguments.
  BadKeyError if the parent key is incomplete.
def google.appengine.api.datastore_types.Key.has_id_or_name (   self)
Returns True if this entity has an id or name, False otherwise.
def google.appengine.api.datastore_types.Key.id (   self)
Returns this entity's id, or None if it doesn't have one.
def google.appengine.api.datastore_types.Key.id_or_name (   self)
Returns this entity's id or name, whichever it has, or None.
def google.appengine.api.datastore_types.Key.kind (   self)
Returns this entity's kind, as a string.
def google.appengine.api.datastore_types.Key.name (   self)
Returns this entity's name, or None if it doesn't have one.
def google.appengine.api.datastore_types.Key.namespace (   self)
Returns this entity's namespace, a string.
def google.appengine.api.datastore_types.Key.parent (   self)
Returns this entity's parent, as a Key. If this entity has no parent,
returns None.
def google.appengine.api.datastore_types.Key.to_path (   self,
  _default_id = None,
  _decode = True,
  _fail = True 
)
Construct the "path" of this key as a list.

Returns:
  A list [kind_1, id_or_name_1, ..., kind_n, id_or_name_n] of the key path.

Raises:
  datastore_errors.BadKeyError if this key does not have a valid path.
def google.appengine.api.datastore_types.Key.ToTagUri (   self)
Returns a tag: URI for this entity for use in XML output.

Foreign keys for entities may be represented in XML output as tag URIs.
RFC 4151 describes the tag URI scheme. From http://taguri.org/:

  The tag algorithm lets people mint - create - identifiers that no one
  else using the same algorithm could ever mint. It is simple enough to do
  in your head, and the resulting identifiers can be easy to read, write,
  and remember. The identifiers conform to the URI (URL) Syntax.

Tag URIs for entities use the app's auth domain and the date that the URI
 is generated. The namespace-specific part is <kind>[<key>].

For example, here is the tag URI for a Kitten with the key "Fluffy" in the
catsinsinks app:

  tag:catsinsinks.googleapps.com,2006-08-29:Kitten[Fluffy]

Raises a BadKeyError if this entity's key is incomplete.

The documentation for this class was generated from the following file: