Document NDB's introspection APIs #187

GoogleCodeExporter opened this Issue Jun 10, 2015 · 6 comments


None yet
2 participants
NDB does not officially support retrospection of created models. This is 
standard a feature that probably should be available in all APIs.

The current work-around is to use internal and undocumented attributes like 
("_properties" and _repeated) but this should be made part of the official API.

Original issue reported on by on 22 May 2012 at 10:22

[deleted comment]
[deleted comment]
[repost due to confusing typo]

Thanks for the reminder. The names starting with _ corresponding to property 
options are actually intended to be a part of the API. I'll make sure this is 
documented somewhere.

The reason these start with _ is that for StructuredProperty, property names of 
the model class would otherwise clash with the introspection API, e.g.

class A(Model):
  repeated = BooleanProperty()
class B(Model):
   a = StructuredProperty(A)

Now B.a.repeated refers to A's repeated property, while B.a._repeated is the 
value of B.a's repeated option.

Apologies for not having this clear in the docs.

Some more examples:

class Employee(Model):
 name = StringProperty()
 address = StringProperty(repeated=True)

>>> print
>>> print Emplotee.address._repeated

The full collection of properties of a model is given as a class variable 
_properties; in the above example,

>>> print Employee._properties
{'name': StringProperty(), 'address': StringProperty(repeated=True)}

On Expando entities, the list of properties is an instance variable; e.g.

class X(Expando): pass

>>> x = X(foo=42, bar='hello')
>>> print x._properties
{'foo': GenericProperty(), 'bar': GenericProperty()}

Original comment by on 22 May 2012 at 4:28

Original comment by on 29 May 2012 at 6:22

  • Added labels: log-6477792
[deleted comment]
(Fixing the summary and metadata to reflect that this is just a documentation 

Original comment by on 2 Jul 2012 at 2:11

  • Changed title: Document NDB's introspection APIs
  • Added labels: Type-Task
  • Removed labels: Type-Defect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment