How to access Google Cloud Datastore entity with dash in its name?
<p>I am working on a Google App Engine project and I need to access a Datastore entity with a name that contains dash, e.g. <code>random-entity</code>. I want to do that in Python. Since <code>random-entity</code> is invalid syntax for a class name, I cannot create a model and access it like that.</p>

<p>So how can I access this entity? Is it possible to do that without creating a model and just retrieve it in JSON format?</p>

<p>Keep in mind that renaming the entity is not an option for the project I am working on.</p>

<p>If you are using <a href="https://cloud.google.com/appengine/docs/python/ndb/" rel="nofollow"><strong>NDB</strong> library</a> you need to override <a href="https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/master/ndb/model.py#L3044" rel="nofollow">class method <code>_get_kind(cls)</code></a> of model, like this:</p>

<pre><code>class RandomEntity(ndb.Model):

  @classmethod
  def _get_kind(cls)
    return 'random-entity'

  # You can override property name as well
  random_name = ndb.StringProperty('random-name')
</code></pre>

python google-app-engine google-cloud-platform google-cloud-datastore