Stay organized with collections Save and categorize content based on your preferences.
Note: Developers building new applications are strongly encouraged to use the NDB Client Library, which has several benefits compared to this client library, such as automatic entity caching via the Memcache API. If you are currently using the older DB Client Library, read the DB to NDB Migration Guide
The Property class is the superclass of property definitions for data models. A Property class defines the type of a property's value, how values are validated, and how values are stored in the datastore.
Property
is provided by the google.appengine.ext.db
module.
A property class describes the value type, default value, validation logic and other features of a property of a Model. Each property class is a subclass of the Property class. The datastore API includes property classes for each of the datastore value types, and several others that provide additional features on top of the datastore types. See Types and Property Classes.
A property class can accept configuration from arguments passed to the constructor. The base class constructor supports several arguments that are typically supported in all property classes, including all those provided in the datastore API. Such configuration can include a default value, whether or not an explicit value is required, a list of acceptable values, and custom validation logic. See the documentation for a specific property type for more information on configuring the property.
A property class defines the model for a datastore property. It does not contain the property value for a model instance. Instances of the Property class belong to the Model class, not instances of the class. In Python terms, property class instances are "descriptors" that customize how attributes of Model instances behave. See the Python documentation for more information about descriptors.
ConstructorThe constructor of the Property base class is defined as follows:
The superclass of model property definitions.
Arguments
djangoforms
library uses this to make labels for form fields, and others can use it for a similar purpose.
A default value for the property. If the property value is never given a value, or is given a value of None
, then the value is considered to be the default value.
Note: Model class definitions are cached along with the rest of the application code. This includes caching default values for properties. Do not set a default in the model definition with data specific to the request (such as users.get_current_user()
). Instead, define an __init__()
method for the Model class that initializes the property values.
If True
, the property cannot have a value of None
. A model instance must initialize all required properties in its constructor so that the instance is not created with missing values. An attempt to create an instance without initializing a required property, or an attempt to assign None
to a required property, raises a BadValueError.
A property that is both required and has a default value uses the default value if one is not given in the constructor. However, the property cannot be assigned a value of None
, and there is no automatic way to restore the default value after another value has been assigned. You can always access the property's default
attribute to get this value and assign it explicitly.
None
.
None
, then all values that otherwise pass validation are acceptable.
Whether this property should be included in the built-in and developer-defined indexes. If False
, entities written to the datastore will never be returned by queries that sort or filter on this property, similar to Blob and Text properties.
Note: Every indexed property adds a small amount of overhead, CPU cost, and latency to put()
and delete()
calls. If you'll never need to filter or sort on a property, consider using indexed=False
to avoid that overhead. Be careful, though! If you decide later that you want the property indexed after all, changing it back to indexed=True
will only affect writes from that point onward. Entities that were originally written with indexed=False
will not be re-indexed.
Subclasses of the Property class define the following class attribute:
data_type
Instances of Property classes have the following methods:
Returns the default value for the property. The base implementation uses the value of the default argument passed to the constructor. A property class could override this to provide special default value behavior, such as DateTimeProperty's auto-now feature.
The complete validation routine for the property. If value is valid, it returns the value, either unchanged or adapted to the required type. Otherwise it raises an appropriate exception.
The base implementation checks that value is not None
if required (the required argument to the base Property constructor), the value is one of the valid choices if the property was configured with choices (the choices argument), and the value passes the custom validator if any (the validator argument).
The validation routine is called when a model using the property type is instantiated (with default or initialized values), and when a property of the type is assigned a value. The routine should not have side effects.
Returns True
if value is considered an empty value for this property type. The base implementation is equivalent to not value
, which is sufficient for most types. Other types, like a Boolean type, can override this method with a more appropriate test.
Returns the value that ought to be stored in the datastore for this property in the given model instance. The base implementation simply returns the Python-native value of the property in the model instance. A property class can override this to use a different data type for the datastore than for the model instance, or to perform other data conversion just prior to storing the model instance.
Returns the Python-native representation for the given value from the datastore. The base implementation simply returns the value. A property class can override this to use a different data type for the model instance than for the datastore.
Returns the Python-native representation for the given value from the datastore index. The base implementation simply returns the value. A property class can override this to use a different data type for the model instance than for the datastore.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-07 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[[["Developers should utilize the NDB Client Library for new applications due to its advantages, such as automatic entity caching."],["The Property class, found in `google.appengine.ext.db`, serves as the foundation for defining data model properties, including their type, validation, and storage method."],["A Property class instance is a descriptor within a Model class, dictating the behavior of Model instance attributes but not storing the property's value for each specific model."],["The Property class constructor allows for configuring properties with settings like default values, requirement status, validation rules, acceptable choices, and whether they are indexed for queries."],["Property class instances offer methods such as `validate()`, `empty()`, `get_value_for_datastore()`, and more, which define how values are handled, validated, and stored in the datastore."]]],[]]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4