Python 3.9 is now generally available.

google.appengine.api.datastore.Key

The primary key for a datastore entity.

Inherits From: expected_type

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.

a base64-encoded primary key, generated by Key.str

encoded str

Methods

ToTagUri

View source

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

View source

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

View source

Returns this entity's app id, a string.

entity_group

View source

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

View source

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

View source

Returns True if this entity has an id or name, False otherwise.

id

View source

Returns this entity's id, or None if it doesn't have one.

id_or_name

View source

Returns this entity's id or name, whichever it has, or None.

kind

View source

Returns this entity's kind, as a string.

name

View source

Returns this entity's name, or None if it doesn't have one.

namespace

View source

Returns this entity's namespace, a string.

parent

View source

Returns this entity's parent, as a Key. If this entity has no parent, returns None.

to_path

View source

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__

View source

Return self==value.

__ge__

View source

Return self>=value.

__gt__

View source

Return self>value.

__le__

View source

Return self<=value.

__lt__

View source

Return self<value.

__ne__

View source

Return self!=value.