---
title: "Count Query Results"
url: "https://docs.ravendb.net/6.2/client-api/session/querying/how-to-count-query-results"
version: "6.2"
language: "python"
---

# Count Query Results

> Client language: Python. Also available for [C#](https://docs.ravendb.net/6.2/client-api/session/querying/how-to-count-query-results.md), [PHP](https://docs.ravendb.net/6.2/client-api/session/querying/how-to-count-query-results.php.md), [Node.js](https://docs.ravendb.net/6.2/client-api/session/querying/how-to-count-query-results.nodejs.md).
>
> RavenDB publishes an official agent skill for coding assistants at https://docs.ravendb.net/skills/ravendb/SKILL.md (also installable with `npx skills add ravendb/skills`). The skill describes itself as: "Read this before writing any RavenDB query, client call or /databases/ request. Covers server setup, document modelling, the Node.js, .NET and Python clients, RQL, indexes, vector search and AI agents. Code written from recall tends to run and return the wrong rows, because RQL resembles SQL and the clients take field names as plain strings."

> **Note**
>
> - The following options are available to **count query results**:
>
>   - [`count`](#count)
>   - [Get number of results from query stats](#get-count-from-query-stats)

## `count`

Count query results using the `count` method.

### Query

```python
number_of_orders = (
  session.advanced.document_query(object_type=Order).where_equals("ship_to.country", "UK").count()
)
# The query returns the NUMBER of orders shipped to UK (int)
```

### RQL

```sql
from "Orders"
where ship_to.country == "UK" limit 0, 0

// The RQL generated will trigger query execution
// however, no documents are returned (limit is set 0)
```

## Get count from query stats

When executing a query, you can retrieve query statistics that include the total number of results.  
To do this, define a callback function that takes `QueryStatistics` as an argument and applies whatever
logic you want to apply.

```python
def **statistics_callback(statistics: QueryStatistics) -> None:
 # Read and interact with QueryStatistics here
 total_results = statistics.total_results
 duration_milliseconds = statistics.duration_in_ms
 ...
```

Then pass your function as an argument to the `query.statistics` method and use the retrieved `QueryStatistics` object.

```python
employees = list(
session.query(object_type=Employee)
.where_equals("first_name", "Robert")
.statistics(**statistics_callback)
)
```

Learn more in [Get Query Statistics](https://docs.ravendb.net/6.2/client-api/session/querying/how-to-get-query-statistics.python.md).

## See also

- [Query overview](https://docs.ravendb.net/6.2/client-api/session/querying/how-to-query.python.md)
- [What is a Document Query](https://docs.ravendb.net/6.2/client-api/session/querying/document-query/what-is-document-query.python.md)
- [Filter by Field Presence](https://docs.ravendb.net/6.2/client-api/session/querying/how-to-filter-by-field.python.md)
- [Get Query Statistics](https://docs.ravendb.net/6.2/client-api/session/querying/how-to-get-query-statistics.python.md)
- [Filtering](https://docs.ravendb.net/6.2/indexes/querying/filtering.python.md)
- [RQL - Raven Query Language](https://docs.ravendb.net/6.2/client-api/session/querying/what-is-rql.md)
