1- """Class for representing a single entity in the Cloud Datastore.
2-
3- Entities are akin to rows in a relational database,
4- storing the actual instance of data.
5-
6- Each entity is officially represented with
7- a :class:`gcloud.datastore.key.Key` class,
8- however it is possible that you might create
9- an Entity with only a partial Key
10- (that is, a Key with a Kind,
11- and possibly a parent, but without an ID).
12-
13- Entities in this API act like dictionaries
14- with extras built in that allow you to
15- delete or persist the data stored on the entity.
16- """
1+ """Class for representing a single entity in the Cloud Datastore."""
172
183from gcloud .datastore import datastore_v1_pb2 as datastore_pb
194from gcloud .datastore .key import Key
@@ -28,42 +13,40 @@ class NoDataset(RuntimeError):
2813
2914
3015class Entity (dict ):
31- """:type dataset: :class:`gcloud.datastore.dataset.Dataset`
32- :param dataset: The dataset in which this entity belongs.
16+ """Entities are akin to rows in a relational database
3317
34- :type kind: string
35- :param kind: The kind of entity this is, akin to a table name in a
36- relational database.
18+ An entity storing the actual instance of data.
19+
20+ Each entity is officially represented with a
21+ :class:`gcloud.datastore.key.Key` class, however it is possible that
22+ you might create an Entity with only a partial Key (that is, a Key
23+ with a Kind, and possibly a parent, but without an ID). In such a
24+ case, the datastore service will automatically assign an ID to the
25+ partial key.
26+
27+ Entities in this API act like dictionaries with extras built in that
28+ allow you to delete or persist the data stored on the entity.
3729
3830 Entities are mutable and act like a subclass of a dictionary.
3931 This means you could take an existing entity and change the key
4032 to duplicate the object.
4133
42- This can be used on its own, however it is likely easier to use
43- the shortcut methods provided by :class:`gcloud.datastore.dataset.Dataset`
44- such as:
45-
46- - :func:`gcloud.datastore.dataset.Dataset.entity` to create a new entity.
47-
48- >>> dataset.entity('MyEntityKind')
49- <Entity[{'kind': 'MyEntityKind'}] {}>
50-
51- - :func:`gcloud.datastore.dataset.Dataset.get_entity`
52- to retrieve an existing entity.
34+ Use :func:`gcloud.datastore.dataset.Dataset.get_entity`
35+ to retrieve an existing entity.
5336
5437 >>> dataset.get_entity(key)
5538 <Entity[{'kind': 'EntityKind', id: 1234}] {'property': 'value'}>
5639
57- You can the set values on the entity
58- just like you would on any other dictionary.
40+ You can the set values on the entity just like you would on any
41+ other dictionary.
5942
6043 >>> entity['age'] = 20
6144 >>> entity['name'] = 'JJ'
6245 >>> entity
6346 <Entity[{'kind': 'EntityKind', id: 1234}] {'age': 20, 'name': 'JJ'}>
6447
65- And you can cast an entity to a regular Python dictionary
66- with the `dict` builtin:
48+ And you can convert an entity to a regular Python dictionary with the
49+ `dict` builtin:
6750
6851 >>> dict(entity)
6952 {'age': 20, 'name': 'JJ'}
@@ -78,6 +61,13 @@ class Entity(dict):
7861 Python3), will be saved using the 'blob_value' field, without
7962 any decoding / encoding step.
8063
64+ :type dataset: :class:`gcloud.datastore.dataset.Dataset`
65+ :param dataset: The dataset in which this entity belongs.
66+
67+ :type kind: string
68+ :param kind: The kind of entity this is, akin to a table name in a
69+ relational database.
70+
8171 :type dataset: :class:`gcloud.datastore.dataset.Dataset`, or None
8272 :param dataset: the Dataset instance associated with this entity.
8373
@@ -101,15 +91,15 @@ def __init__(self, dataset=None, kind=None, exclude_from_indexes=()):
10191 def dataset (self ):
10292 """Get the :class:`.dataset.Dataset` in which this entity belongs.
10393
104- :rtype: :class:`gcloud.datastore.dataset.Dataset`
105- :returns: The Dataset containing the entity if there is a key,
106- else None.
107-
10894 .. note::
10995 This is based on the :class:`gcloud.datastore.key.Key` set on the
11096 entity. That means that if you have no key set, the dataset might
11197 be `None`. It also means that if you change the key on the entity,
11298 this will refer to that key's dataset.
99+
100+ :rtype: :class:`gcloud.datastore.dataset.Dataset`
101+ :returns: The Dataset containing the entity if there is a key,
102+ else None.
113103 """
114104 return self ._dataset
115105
@@ -139,12 +129,10 @@ def kind(self):
139129 """Get the kind of the current entity.
140130
141131 .. note::
142- This relies entirely on
143- the :class:`gcloud.datastore.key.Key`
144- set on the entity.
145- That means that we're not storing the kind of the entity at all,
146- just the properties and a pointer to a Key
147- which knows its Kind.
132+ This relies entirely on the :class:`gcloud.datastore.key.Key`
133+ set on the entity. That means that we're not storing the kind
134+ of the entity at all, just the properties and a pointer to a
135+ Key which knows its Kind.
148136 """
149137
150138 if self ._key :
@@ -161,8 +149,7 @@ def exclude_from_indexes(self):
161149 def from_key (cls , key , dataset = None ):
162150 """Create entity based on :class:`.datastore.key.Key`.
163151
164- .. note::
165- This is a factory method.
152+ .. note:: This is a factory method.
166153
167154 :type key: :class:`gcloud.datastore.key.Key`
168155 :param key: The key for the entity.
0 commit comments