Like this project? it on

Query Sets

Query sets are used to work with sets of objects that have been retrieved from the database. For example, whenever you call the filter function of the backend, you will receive a QuerySet object in return. This object stores references to all documents matching your query and can retrieve these objects for you if necessary.

This class is an abstract base class that gets implemented by the specific backends.

class blitzdb.queryset.QuerySet(backend, cls)[source]

Stores information about objects returned by a database query and retrieves instances of these objects if necessary.

  • backend – The backend to use for :py:meth:filter`filtering` etc.
  • cls – The class of the documents stored in the query set.

Checks if two query sets are equal. Implement this in your derived query set class.

Parameters:other – The object this query set is compared to.

Returns a specific element from a query set.

If i is a slice instead of an index (e.g. qs[:50]), returns a subset of the query results. This allows user to specify an offset and/or limit for the query.


Return the number of documents contained in this query set.


Checks if two query sets are unequal.

Parameters:other – The object this query set is compared to.

Deletes all objects contained in this query set from the database.

filter(*args, **kwargs)[source]

Performs a filter operation on all documents contained in the query set. See blitzdb.backends.base.Backend.filter() for more details.

sort(*args, **kwargs)[source]

Sort documents in this query set based on a key and order

  • key – the property name to sort on
  • order – either blitzdb.queryset.QuerySet.ASCENDING or blitzdb.queryset.QuerySet.DESCENDING

this queryset