Ivaylo Toskov Ivaylo Toskov - 10 months ago 62
Python Question

How to access Google Cloud Datastore entity with dash in its name?

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.

. I want to do that in Python. Since
is invalid syntax for a class name, I cannot create a model and access it like that.

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

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


If you are using NDB library you need to override class method _get_kind(cls) of model, like this:

class RandomEntity(ndb.Model):

  def _get_kind(cls)
    return 'random-entity'

  # You can override property name as well
  random_name = ndb.StringProperty('random-name')