We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
datastore: No way to exclude_from_indexes new properties on updated entities
When loading an `Entity` from the datastore and updating it, there is no way to exclude new attributes from being indexed, since the only public API for setting `exclude_from_indexes` is on the `Entity` constructor. To work around this, I am currently setting `entity._exclude_from_indexes = (...)` in my code, which is not a "public" API.

Example:

```python
client = google.cloud.datastore.Client()
key = client.key('SomeEntityKey')
entity = google.cloud.datastore.Entity(key, exclude_from_indexes=('foo', 'bar'))
entity['foo'] = 'foo'
print 'entity.exclude_from_indexes:', entity.exclude_from_indexes
client.put(entity)

entity2 = client.get(entity.key)
print 'entity2.exclude_from_indexes:', entity2.exclude_from_indexes
entity2['bar'] = 'bar'
client.put(entity2)
```

Output:

```
entity.exclude_from_indexes: frozenset(['foo', 'bar'])
entity2.exclude_from_indexes: frozenset([u'foo'])
```

This is actually "expected" based on how the Datastore works, however, in the code sample above, there should be some way for me to put the entity back, without copying it into a brand new `Entity`.


Tested using:

* Mac OS X 10.11.6
* Python 2.7.10
* The following Google packages:
```
gapic-google-cloud-datastore-v1==0.15.3
google-auth==1.0.1
google-auth-httplib2==0.0.2
google-cloud-core==0.24.1
google-cloud-datastore==1.0.0
google-cloud-storage==1.1.1
google-gax==0.15.13
google-resumable-media==0.0.2
googleapis-common-protos==1.5.2
proto-google-cloud-datastore-v1==0.90.4
```


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `datastore/google/cloud/datastore/entity.py`
Content:
```
1 # Copyright 2014 Google Inc.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 
15 """Class for representing a single entity in the Cloud Datastore."""
16 
17 
18 from google.cloud._helpers import _ensure_tuple_or_list
19 
20 
21 class Entity(dict):
22     """Entities are akin to rows in a relational database
23 
24     An entity storing the actual instance of data.
25 
26     Each entity is officially represented with a
27     :class:`~google.cloud.datastore.key.Key`, however it is possible that
28     you might create an entity with only a partial key (that is, a key
29     with a kind, and possibly a parent, but without an ID).  In such a
30     case, the datastore service will automatically assign an ID to the
31     partial key.
32 
33     Entities in this API act like dictionaries with extras built in that
34     allow you to delete or persist the data stored on the entity.
35 
36     Entities are mutable and act like a subclass of a dictionary.
37     This means you could take an existing entity and change the key
38     to duplicate the object.
39 
40     Use :meth:`~google.cloud.datastore.client.Client.get` to retrieve an
41     existing entity:
42 
43     .. testsetup:: entity-ctor
44 
45        from google.cloud import datastore
46        from tests.system.test_system import Config  # system tests
47 
48        client = datastore.Client()
49        key = client.key('EntityKind', 1234, namespace='_Doctest')
50        entity = datastore.Entity(key=key)
51        entity['property'] = 'value'
52        Config.TO_DELETE.append(entity)
53 
54        client.put(entity)
55 
56     .. doctest:: entity-ctor
57 
58        >>> client.get(key)
59        <Entity('EntityKind', 1234) {'property': 'value'}>
60 
61     You can the set values on the entity just like you would on any
62     other dictionary.
63 
64     .. doctest:: entity-ctor
65 
66        >>> entity['age'] = 20
67        >>> entity['name'] = 'JJ'
68 
69     However, not all types are allowed as a value for a Google Cloud Datastore
70     entity. The following basic types are supported by the API:
71 
72     * :class:`datetime.datetime`
73     * :class:`~google.cloud.datastore.key.Key`
74     * :class:`bool`
75     * :class:`float`
76     * :class:`int` (as well as :class:`long` in Python 2)
77     * ``unicode`` (called ``str`` in Python 3)
78     * ``bytes`` (called ``str`` in Python 2)
79     * :class:`~google.cloud.datastore.helpers.GeoPoint`
80     * :data:`None`
81 
82     In addition, two container types are supported:
83 
84     * :class:`list`
85     * :class:`~google.cloud.datastore.entity.Entity`
86 
87     Each entry in a list must be one of the value types (basic or
88     container) and each value in an
89     :class:`~google.cloud.datastore.entity.Entity` must as well. In
90     this case an :class:`~google.cloud.datastore.entity.Entity` **as a
91     container** acts as a :class:`dict`, but also has the special annotations
92     of ``key`` and ``exclude_from_indexes``.
93 
94     And you can treat an entity like a regular Python dictionary:
95 
96     .. testsetup:: entity-dict
97 
98        from google.cloud import datastore
99 
100        entity = datastore.Entity()
101        entity['age'] = 20
102        entity['name'] = 'JJ'
103 
104     .. doctest:: entity-dict
105 
106        >>> sorted(entity.keys())
107        ['age', 'name']
108        >>> sorted(entity.items())
109        [('age', 20), ('name', 'JJ')]
110 
111     .. note::
112 
113        When saving an entity to the backend, values which are "text"
114        (``unicode`` in Python2, ``str`` in Python3) will be saved using
115        the 'text_value' field, after being encoded to UTF-8.  When
116        retrieved from the back-end, such values will be decoded to "text"
117        again.  Values which are "bytes" (``str`` in Python2, ``bytes`` in
118        Python3), will be saved using the 'blob_value' field, without
119        any decoding / encoding step.
120 
121     :type key: :class:`google.cloud.datastore.key.Key`
122     :param key: Optional key to be set on entity.
123 
124     :type exclude_from_indexes: tuple of string
125     :param exclude_from_indexes: Names of fields whose values are not to be
126                                  indexed for this entity.
127     """
128 
129     def __init__(self, key=None, exclude_from_indexes=()):
130         super(Entity, self).__init__()
131         self.key = key
132         self._exclude_from_indexes = set(_ensure_tuple_or_list(
133             'exclude_from_indexes', exclude_from_indexes))
134         # NOTE: This will be populated when parsing a protobuf in
135         #       google.cloud.datastore.helpers.entity_from_protobuf.
136         self._meanings = {}
137 
138     def __eq__(self, other):
139         """Compare two entities for equality.
140 
141         Entities compare equal if their keys compare equal and their
142         properties compare equal.
143 
144         :rtype: bool
145         :returns: True if the entities compare equal, else False.
146         """
147         if not isinstance(other, Entity):
148             return False
149 
150         return (self.key == other.key and
151                 self._exclude_from_indexes == other._exclude_from_indexes and
152                 self._meanings == other._meanings and
153                 super(Entity, self).__eq__(other))
154 
155     def __ne__(self, other):
156         """Compare two entities for inequality.
157 
158         Entities compare equal if their keys compare equal and their
159         properties compare equal.
160 
161         :rtype: bool
162         :returns: False if the entities compare equal, else True.
163         """
164         return not self.__eq__(other)
165 
166     @property
167     def kind(self):
168         """Get the kind of the current entity.
169 
170         .. note::
171           This relies entirely on the :class:`google.cloud.datastore.key.Key`
172           set on the entity.  That means that we're not storing the kind
173           of the entity at all, just the properties and a pointer to a
174           Key which knows its Kind.
175         """
176         if self.key:
177             return self.key.kind
178 
179     @property
180     def exclude_from_indexes(self):
181         """Names of fields which are *not* to be indexed for this entity.
182 
183         :rtype: sequence of field names
184         :returns: The set of fields excluded from indexes.
185         """
186         return frozenset(self._exclude_from_indexes)
187 
188     def __repr__(self):
189         if self.key:
190             return '<Entity%s %s>' % (self.key._flat_path,
191                                       super(Entity, self).__repr__())
192         else:
193             return '<Entity %s>' % (super(Entity, self).__repr__(),)
194
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/datastore/google/cloud/datastore/entity.py b/datastore/google/cloud/datastore/entity.py
--- a/datastore/google/cloud/datastore/entity.py
+++ b/datastore/google/cloud/datastore/entity.py
@@ -129,8 +129,9 @@
     def __init__(self, key=None, exclude_from_indexes=()):
         super(Entity, self).__init__()
         self.key = key
-        self._exclude_from_indexes = set(_ensure_tuple_or_list(
+        self.exclude_from_indexes = set(_ensure_tuple_or_list(
             'exclude_from_indexes', exclude_from_indexes))
+        """Names of fields which are *not* to be indexed for this entity."""
         # NOTE: This will be populated when parsing a protobuf in
         #       google.cloud.datastore.helpers.entity_from_protobuf.
         self._meanings = {}
@@ -148,7 +149,7 @@
             return False
 
         return (self.key == other.key and
-                self._exclude_from_indexes == other._exclude_from_indexes and
+                self.exclude_from_indexes == other.exclude_from_indexes and
                 self._meanings == other._meanings and
                 super(Entity, self).__eq__(other))
 
@@ -176,15 +177,6 @@
         if self.key:
             return self.key.kind
 
-    @property
-    def exclude_from_indexes(self):
-        """Names of fields which are *not* to be indexed for this entity.
-
-        :rtype: sequence of field names
-        :returns: The set of fields excluded from indexes.
-        """
-        return frozenset(self._exclude_from_indexes)
-
     def __repr__(self):
         if self.key:
             return '<Entity%s %s>' % (self.key._flat_path,

{"golden_diff": "diff --git a/datastore/google/cloud/datastore/entity.py b/datastore/google/cloud/datastore/entity.py\n--- a/datastore/google/cloud/datastore/entity.py\n+++ b/datastore/google/cloud/datastore/entity.py\n@@ -129,8 +129,9 @@\n     def __init__(self, key=None, exclude_from_indexes=()):\n         super(Entity, self).__init__()\n         self.key = key\n-        self._exclude_from_indexes = set(_ensure_tuple_or_list(\n+        self.exclude_from_indexes = set(_ensure_tuple_or_list(\n             'exclude_from_indexes', exclude_from_indexes))\n+        \"\"\"Names of fields which are *not* to be indexed for this entity.\"\"\"\n         # NOTE: This will be populated when parsing a protobuf in\n         #       google.cloud.datastore.helpers.entity_from_protobuf.\n         self._meanings = {}\n@@ -148,7 +149,7 @@\n             return False\n \n         return (self.key == other.key and\n-                self._exclude_from_indexes == other._exclude_from_indexes and\n+                self.exclude_from_indexes == other.exclude_from_indexes and\n                 self._meanings == other._meanings and\n                 super(Entity, self).__eq__(other))\n \n@@ -176,15 +177,6 @@\n         if self.key:\n             return self.key.kind\n \n-    @property\n-    def exclude_from_indexes(self):\n-        \"\"\"Names of fields which are *not* to be indexed for this entity.\n-\n-        :rtype: sequence of field names\n-        :returns: The set of fields excluded from indexes.\n-        \"\"\"\n-        return frozenset(self._exclude_from_indexes)\n-\n     def __repr__(self):\n         if self.key:\n             return '<Entity%s %s>' % (self.key._flat_path,\n", "issue": "datastore: No way to exclude_from_indexes new properties on updated entities\nWhen loading an `Entity` from the datastore and updating it, there is no way to exclude new attributes from being indexed, since the only public API for setting `exclude_from_indexes` is on the `Entity` constructor. To work around this, I am currently setting `entity._exclude_from_indexes = (...)` in my code, which is not a \"public\" API.\r\n\r\nExample:\r\n\r\n```python\r\nclient = google.cloud.datastore.Client()\r\nkey = client.key('SomeEntityKey')\r\nentity = google.cloud.datastore.Entity(key, exclude_from_indexes=('foo', 'bar'))\r\nentity['foo'] = 'foo'\r\nprint 'entity.exclude_from_indexes:', entity.exclude_from_indexes\r\nclient.put(entity)\r\n\r\nentity2 = client.get(entity.key)\r\nprint 'entity2.exclude_from_indexes:', entity2.exclude_from_indexes\r\nentity2['bar'] = 'bar'\r\nclient.put(entity2)\r\n```\r\n\r\nOutput:\r\n\r\n```\r\nentity.exclude_from_indexes: frozenset(['foo', 'bar'])\r\nentity2.exclude_from_indexes: frozenset([u'foo'])\r\n```\r\n\r\nThis is actually \"expected\" based on how the Datastore works, however, in the code sample above, there should be some way for me to put the entity back, without copying it into a brand new `Entity`.\r\n\r\n\r\nTested using:\r\n\r\n* Mac OS X 10.11.6\r\n* Python 2.7.10\r\n* The following Google packages:\r\n```\r\ngapic-google-cloud-datastore-v1==0.15.3\r\ngoogle-auth==1.0.1\r\ngoogle-auth-httplib2==0.0.2\r\ngoogle-cloud-core==0.24.1\r\ngoogle-cloud-datastore==1.0.0\r\ngoogle-cloud-storage==1.1.1\r\ngoogle-gax==0.15.13\r\ngoogle-resumable-media==0.0.2\r\ngoogleapis-common-protos==1.5.2\r\nproto-google-cloud-datastore-v1==0.90.4\r\n```\r\n\n", "before_files": [{"content": "# Copyright 2014 Google Inc.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\n\"\"\"Class for representing a single entity in the Cloud Datastore.\"\"\"\n\n\nfrom google.cloud._helpers import _ensure_tuple_or_list\n\n\nclass Entity(dict):\n    \"\"\"Entities are akin to rows in a relational database\n\n    An entity storing the actual instance of data.\n\n    Each entity is officially represented with a\n    :class:`~google.cloud.datastore.key.Key`, however it is possible that\n    you might create an entity with only a partial key (that is, a key\n    with a kind, and possibly a parent, but without an ID).  In such a\n    case, the datastore service will automatically assign an ID to the\n    partial key.\n\n    Entities in this API act like dictionaries with extras built in that\n    allow you to delete or persist the data stored on the entity.\n\n    Entities are mutable and act like a subclass of a dictionary.\n    This means you could take an existing entity and change the key\n    to duplicate the object.\n\n    Use :meth:`~google.cloud.datastore.client.Client.get` to retrieve an\n    existing entity:\n\n    .. testsetup:: entity-ctor\n\n       from google.cloud import datastore\n       from tests.system.test_system import Config  # system tests\n\n       client = datastore.Client()\n       key = client.key('EntityKind', 1234, namespace='_Doctest')\n       entity = datastore.Entity(key=key)\n       entity['property'] = 'value'\n       Config.TO_DELETE.append(entity)\n\n       client.put(entity)\n\n    .. doctest:: entity-ctor\n\n       >>> client.get(key)\n       <Entity('EntityKind', 1234) {'property': 'value'}>\n\n    You can the set values on the entity just like you would on any\n    other dictionary.\n\n    .. doctest:: entity-ctor\n\n       >>> entity['age'] = 20\n       >>> entity['name'] = 'JJ'\n\n    However, not all types are allowed as a value for a Google Cloud Datastore\n    entity. The following basic types are supported by the API:\n\n    * :class:`datetime.datetime`\n    * :class:`~google.cloud.datastore.key.Key`\n    * :class:`bool`\n    * :class:`float`\n    * :class:`int` (as well as :class:`long` in Python 2)\n    * ``unicode`` (called ``str`` in Python 3)\n    * ``bytes`` (called ``str`` in Python 2)\n    * :class:`~google.cloud.datastore.helpers.GeoPoint`\n    * :data:`None`\n\n    In addition, two container types are supported:\n\n    * :class:`list`\n    * :class:`~google.cloud.datastore.entity.Entity`\n\n    Each entry in a list must be one of the value types (basic or\n    container) and each value in an\n    :class:`~google.cloud.datastore.entity.Entity` must as well. In\n    this case an :class:`~google.cloud.datastore.entity.Entity` **as a\n    container** acts as a :class:`dict`, but also has the special annotations\n    of ``key`` and ``exclude_from_indexes``.\n\n    And you can treat an entity like a regular Python dictionary:\n\n    .. testsetup:: entity-dict\n\n       from google.cloud import datastore\n\n       entity = datastore.Entity()\n       entity['age'] = 20\n       entity['name'] = 'JJ'\n\n    .. doctest:: entity-dict\n\n       >>> sorted(entity.keys())\n       ['age', 'name']\n       >>> sorted(entity.items())\n       [('age', 20), ('name', 'JJ')]\n\n    .. note::\n\n       When saving an entity to the backend, values which are \"text\"\n       (``unicode`` in Python2, ``str`` in Python3) will be saved using\n       the 'text_value' field, after being encoded to UTF-8.  When\n       retrieved from the back-end, such values will be decoded to \"text\"\n       again.  Values which are \"bytes\" (``str`` in Python2, ``bytes`` in\n       Python3), will be saved using the 'blob_value' field, without\n       any decoding / encoding step.\n\n    :type key: :class:`google.cloud.datastore.key.Key`\n    :param key: Optional key to be set on entity.\n\n    :type exclude_from_indexes: tuple of string\n    :param exclude_from_indexes: Names of fields whose values are not to be\n                                 indexed for this entity.\n    \"\"\"\n\n    def __init__(self, key=None, exclude_from_indexes=()):\n        super(Entity, self).__init__()\n        self.key = key\n        self._exclude_from_indexes = set(_ensure_tuple_or_list(\n            'exclude_from_indexes', exclude_from_indexes))\n        # NOTE: This will be populated when parsing a protobuf in\n        #       google.cloud.datastore.helpers.entity_from_protobuf.\n        self._meanings = {}\n\n    def __eq__(self, other):\n        \"\"\"Compare two entities for equality.\n\n        Entities compare equal if their keys compare equal and their\n        properties compare equal.\n\n        :rtype: bool\n        :returns: True if the entities compare equal, else False.\n        \"\"\"\n        if not isinstance(other, Entity):\n            return False\n\n        return (self.key == other.key and\n                self._exclude_from_indexes == other._exclude_from_indexes and\n                self._meanings == other._meanings and\n                super(Entity, self).__eq__(other))\n\n    def __ne__(self, other):\n        \"\"\"Compare two entities for inequality.\n\n        Entities compare equal if their keys compare equal and their\n        properties compare equal.\n\n        :rtype: bool\n        :returns: False if the entities compare equal, else True.\n        \"\"\"\n        return not self.__eq__(other)\n\n    @property\n    def kind(self):\n        \"\"\"Get the kind of the current entity.\n\n        .. note::\n          This relies entirely on the :class:`google.cloud.datastore.key.Key`\n          set on the entity.  That means that we're not storing the kind\n          of the entity at all, just the properties and a pointer to a\n          Key which knows its Kind.\n        \"\"\"\n        if self.key:\n            return self.key.kind\n\n    @property\n    def exclude_from_indexes(self):\n        \"\"\"Names of fields which are *not* to be indexed for this entity.\n\n        :rtype: sequence of field names\n        :returns: The set of fields excluded from indexes.\n        \"\"\"\n        return frozenset(self._exclude_from_indexes)\n\n    def __repr__(self):\n        if self.key:\n            return '<Entity%s %s>' % (self.key._flat_path,\n                                      super(Entity, self).__repr__())\n        else:\n            return '<Entity %s>' % (super(Entity, self).__repr__(),)\n", "path": "datastore/google/cloud/datastore/entity.py"}], "after_files": [{"content": "# Copyright 2014 Google Inc.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\n\"\"\"Class for representing a single entity in the Cloud Datastore.\"\"\"\n\n\nfrom google.cloud._helpers import _ensure_tuple_or_list\n\n\nclass Entity(dict):\n    \"\"\"Entities are akin to rows in a relational database\n\n    An entity storing the actual instance of data.\n\n    Each entity is officially represented with a\n    :class:`~google.cloud.datastore.key.Key`, however it is possible that\n    you might create an entity with only a partial key (that is, a key\n    with a kind, and possibly a parent, but without an ID).  In such a\n    case, the datastore service will automatically assign an ID to the\n    partial key.\n\n    Entities in this API act like dictionaries with extras built in that\n    allow you to delete or persist the data stored on the entity.\n\n    Entities are mutable and act like a subclass of a dictionary.\n    This means you could take an existing entity and change the key\n    to duplicate the object.\n\n    Use :meth:`~google.cloud.datastore.client.Client.get` to retrieve an\n    existing entity:\n\n    .. testsetup:: entity-ctor\n\n       from google.cloud import datastore\n       from tests.system.test_system import Config  # system tests\n\n       client = datastore.Client()\n       key = client.key('EntityKind', 1234, namespace='_Doctest')\n       entity = datastore.Entity(key=key)\n       entity['property'] = 'value'\n       Config.TO_DELETE.append(entity)\n\n       client.put(entity)\n\n    .. doctest:: entity-ctor\n\n       >>> client.get(key)\n       <Entity('EntityKind', 1234) {'property': 'value'}>\n\n    You can the set values on the entity just like you would on any\n    other dictionary.\n\n    .. doctest:: entity-ctor\n\n       >>> entity['age'] = 20\n       >>> entity['name'] = 'JJ'\n\n    However, not all types are allowed as a value for a Google Cloud Datastore\n    entity. The following basic types are supported by the API:\n\n    * :class:`datetime.datetime`\n    * :class:`~google.cloud.datastore.key.Key`\n    * :class:`bool`\n    * :class:`float`\n    * :class:`int` (as well as :class:`long` in Python 2)\n    * ``unicode`` (called ``str`` in Python 3)\n    * ``bytes`` (called ``str`` in Python 2)\n    * :class:`~google.cloud.datastore.helpers.GeoPoint`\n    * :data:`None`\n\n    In addition, two container types are supported:\n\n    * :class:`list`\n    * :class:`~google.cloud.datastore.entity.Entity`\n\n    Each entry in a list must be one of the value types (basic or\n    container) and each value in an\n    :class:`~google.cloud.datastore.entity.Entity` must as well. In\n    this case an :class:`~google.cloud.datastore.entity.Entity` **as a\n    container** acts as a :class:`dict`, but also has the special annotations\n    of ``key`` and ``exclude_from_indexes``.\n\n    And you can treat an entity like a regular Python dictionary:\n\n    .. testsetup:: entity-dict\n\n       from google.cloud import datastore\n\n       entity = datastore.Entity()\n       entity['age'] = 20\n       entity['name'] = 'JJ'\n\n    .. doctest:: entity-dict\n\n       >>> sorted(entity.keys())\n       ['age', 'name']\n       >>> sorted(entity.items())\n       [('age', 20), ('name', 'JJ')]\n\n    .. note::\n\n       When saving an entity to the backend, values which are \"text\"\n       (``unicode`` in Python2, ``str`` in Python3) will be saved using\n       the 'text_value' field, after being encoded to UTF-8.  When\n       retrieved from the back-end, such values will be decoded to \"text\"\n       again.  Values which are \"bytes\" (``str`` in Python2, ``bytes`` in\n       Python3), will be saved using the 'blob_value' field, without\n       any decoding / encoding step.\n\n    :type key: :class:`google.cloud.datastore.key.Key`\n    :param key: Optional key to be set on entity.\n\n    :type exclude_from_indexes: tuple of string\n    :param exclude_from_indexes: Names of fields whose values are not to be\n                                 indexed for this entity.\n    \"\"\"\n\n    def __init__(self, key=None, exclude_from_indexes=()):\n        super(Entity, self).__init__()\n        self.key = key\n        self.exclude_from_indexes = set(_ensure_tuple_or_list(\n            'exclude_from_indexes', exclude_from_indexes))\n        \"\"\"Names of fields which are *not* to be indexed for this entity.\"\"\"\n        # NOTE: This will be populated when parsing a protobuf in\n        #       google.cloud.datastore.helpers.entity_from_protobuf.\n        self._meanings = {}\n\n    def __eq__(self, other):\n        \"\"\"Compare two entities for equality.\n\n        Entities compare equal if their keys compare equal and their\n        properties compare equal.\n\n        :rtype: bool\n        :returns: True if the entities compare equal, else False.\n        \"\"\"\n        if not isinstance(other, Entity):\n            return False\n\n        return (self.key == other.key and\n                self.exclude_from_indexes == other.exclude_from_indexes and\n                self._meanings == other._meanings and\n                super(Entity, self).__eq__(other))\n\n    def __ne__(self, other):\n        \"\"\"Compare two entities for inequality.\n\n        Entities compare equal if their keys compare equal and their\n        properties compare equal.\n\n        :rtype: bool\n        :returns: False if the entities compare equal, else True.\n        \"\"\"\n        return not self.__eq__(other)\n\n    @property\n    def kind(self):\n        \"\"\"Get the kind of the current entity.\n\n        .. note::\n          This relies entirely on the :class:`google.cloud.datastore.key.Key`\n          set on the entity.  That means that we're not storing the kind\n          of the entity at all, just the properties and a pointer to a\n          Key which knows its Kind.\n        \"\"\"\n        if self.key:\n            return self.key.kind\n\n    def __repr__(self):\n        if self.key:\n            return '<Entity%s %s>' % (self.key._flat_path,\n                                      super(Entity, self).__repr__())\n        else:\n            return '<Entity %s>' % (super(Entity, self).__repr__(),)\n", "path": "datastore/google/cloud/datastore/entity.py"}]}