Module key (2.11.1)

Create / interact with Google Cloud Datastore keys.

Classes

Key

Key(*path_args, **kwargs)

An immutable representation of a datastore Key.

.. testsetup:: key-ctor

from google.cloud import datastore

project = 'my-special-pony' client = datastore.Client(project=project) Key = datastore.Key

parent_key = client.key('Parent', 'foo')

To create a basic key directly:

.. doctest:: key-ctor

Key('EntityKind', 1234, project=project) <Key('EntityKind', 1234), project=...> Key('EntityKind', 'foo', project=project) <Key('EntityKind', 'foo'), project=...>

Though typical usage comes via the xref_key factory:

.. doctest:: key-ctor

client.key('EntityKind', 1234) <Key('EntityKind', 1234), project=...> client.key('EntityKind', 'foo') <Key('EntityKind', 'foo'), project=...>

To create a key with a parent:

.. doctest:: key-ctor

client.key('Parent', 'foo', 'Child', 1234) <Key('Parent', 'foo', 'Child', 1234), project=...> client.key('Child', 1234, parent=parent_key) <Key('Parent', 'foo', 'Child', 1234), project=...>

To create a partial key:

.. doctest:: key-ctor

client.key('Parent', 'foo', 'Child') <Key('Parent', 'foo', 'Child'), project=...>

Parameter
Name Description
path_args tuple of string and integer

May represent a partial (odd length) or full (even length) key path.

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025年10月30日 UTC.