View source on GitHub |
The primary key for a datastore entity.
Inherits From: expected_type
google.appengine.api.datastore.Key(
encoded=None
)
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.
Args | |
---|---|
a base64-encoded primary key, generated by Key.str |
|
encoded
|
str |
Methods
ToTagUri
ToTagUri()
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.
ToXml
ToXml()
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.
app
app()
Returns this entity's app id, a string.
entity_group
entity_group()
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.
from_path
@staticmethod
from_path( *args, **kwds )
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 other properties. For example, 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.
|
has_id_or_name
has_id_or_name()
Returns True if this entity has an id or name, False otherwise.
id
id()
Returns this entity's id, or None if it doesn't have one.
id_or_name
id_or_name()
Returns this entity's id or name, whichever it has, or None.
kind
kind()
Returns this entity's kind, as a string.
name
name()
Returns this entity's name, or None if it doesn't have one.
namespace
namespace()
Returns this entity's namespace, a string.
parent
parent()
Returns this entity's parent, as a Key. If this entity has no parent, returns None.
to_path
to_path(
_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. |
__eq__
__eq__(
other
)
Return self==value.
__ge__
__ge__(
other
)
Return self>=value.
__gt__
__gt__(
other
)
Return self>value.
__le__
__le__(
other
)
Return self<=value.
__lt__
__lt__(
other
)
Return self<value.
__ne__
__ne__(
other
)
Return self!=value.