Notice: Over the next few months, we're reorganizing the App Engine documentation site to make it easier to find content and better align with the rest of Google Cloud products. The same content will be available, but the navigation will now match the rest of the Cloud products.

Python 2 is no longer supported by the community. We recommend that you migrate Python 2 apps to Python 3.

The SortOptions Class

Stay organized with collections Save and categorize content based on your preferences.

Class SortExpression represents a multi-dimensional sort of Documents.

Caution: **This solution is no longer recommended:** Apps that use this API can only run in the Python 2 runtime and will need to upgrade to a [recommended solution](/appengine/docs/legacy/standard/python/migrate-to-python3/migrating-services#migration_paths_for_bundled_services) before migrating to the Python 3 runtime.

The following code shows how to sort documents based on product rating in descending order and then cheapest product within similarly rated products, sorting at most 1000 documents:

             direction=SortExpression.DESCENDING, default_value=0),
         SortExpression(expression='price + tax',
             direction=SortExpression.ASCENDING, default_value=999999.99)],

SortOptions is defined in the module.


The constructor for class SortOptions is defined as follows:

class SortOptions(expressions=None, match_scorer=None, limit=1000)

Sort documents according to the specified options.



An iterable of SortExpression representing a multi-dimensional sort of Documents.


A match scorer specification which may be used to score documents or in a SortExpression combined with other features.


The limit on the number of documents to score. It is advisable to set this limit on large indexes.

Result value

A new instance of class SortOptions.



If any of the parameters have an invalid type, or an unknown attribute is passed.


If any parameter has an invalid value.


An instance of class SortOptions has the following properties:


Returns a list of SortExpression specifying a multi-dimensional sort.


Returns a match scorer used to score documents.


Returns the limit on the number of documents to score.