The Expando Class Stay organized with collections Save and categorize content based on your preferences.
Note:Developers building new applications arestrongly encouraged to use theNDB Client Library, which has several benefitscompared to this client library, such as automatic entity caching via the MemcacheAPI. If you are currently using the older DB Client Library, read theDB to NDB Migration Guide
The Expando class is a superclass for data model definitions whose properties are determined dynamically. An Expando model can have a combination of fixed properties similar toModel and dynamic properties assigned to an entity at run-time.
Expando is provided by thegoogle.appengine.ext.db module.
Expando is a subclass ofModel, and inherits its class and instance methods from that class. The Expando class does not define or override any methods.
Introduction
An Expando model can have fixed properties and dynamic properties. Fixed properties behave similar to properties of aModel, and are similarly defined in the Expando model class using class attributes. Dynamic properties are created when they are assigned values on the instance. Two instances of the same Expando class can have different sets of dynamic properties, and can even have dynamic properties with the same name but different types. Dynamic properties are always optional, and have no default value: They don't exist until they are assigned a value.
Dynamic properties cannot useProperty instances to perform validation, set defaults or apply automatic logic to values. Dynamic properties simply store values of the supported datastore types. SeeTypes and Property Classes.
Also unlike fixed properties, dynamic properties cannot use a different name for the class attribute and the datastore property name. SeeDisallowed Property Names.
Tip: If you want to validate a dynamic property value using a Property class, you can instantiate the Property class and call itsvalidate() method on the value.
An Expando subclass can define fixed properties similar to aModel class. Fixed properties of an Expando behave similarly to properties of a Model. An Expando instance can have both fixed and dynamic properties.
importdatetimefromgoogle.appengine.extimportdbclassSong(db.Expando):title=db.StringProperty()crazy=Song(title='Crazy like a diamond',author='Lucy Sky',publish_date='yesterday',rating=5.0)hoboken=Song(title='The man from Hoboken',author=['Anthony','Lou'],publish_date=datetime.datetime(1977,5,3))crazy.last_minute_note=db.Text('Get a train to the station.')
An Expando instance's dynamic (non-fixed) properties can be deleted. To delete a dynamic property, an application deletes the instance's attribute:
del crazy.last_minute_note
Constructor
The constructor of the Expando class is defined as follows:
- class Expando(parent=None,key_name=None, **kwds)
A model class whose properties do not need to be defined in the class before use. LikeModel, the Expando class must be subclassed to define the kind of the data entities.
Expando is a subclass ofModel, and inherits or overrides its methods.
Arguments
- parent
- The Model instance or Key instance for the entity that is the new entity's parent.
- key_name
The name for the new entity. The name becomes part of the primary key. If
None, a system-generated ID is used for the key.The value forkey_name must not start with a number, and must not be of the form
__*__. If your application uses user-submitted data as datastore entity key names (such as an email address), the application should sanitize the value first, such as by prefixing it with a known string like "key:", to meet these requirements.A
key_nameis stored as a Unicode string, withstrvalues converted as ASCII text.- **kwds
- Initial values for the instance's properties, as keyword arguments. Each name corresponds with an attribute of the new instance, and may either correspond with fixed properties defined in the Expando class, or be dynamic properties.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-15 UTC.