---
sidebar:
  label: roboto.query.specification
  order: 5
title: roboto.query.specification
---
## Module Contents

### DEFAULT_PAGE_SIZE

```python
roboto.query.specification.DEFAULT_PAGE_SIZE: int = 50
```

`from roboto.query import DEFAULT_PAGE_SIZE`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/query/specification.py#L18-L18)

Number of results in one page of query results when the caller sets no page size.

### MAX_PAGE_SIZE

```python
roboto.query.specification.MAX_PAGE_SIZE: int = 1000
```

`from roboto.query import MAX_PAGE_SIZE`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/query/specification.py#L15-L15)

Maximum number of results in one page of query results.

### QuerySpecification

```python
class roboto.query.specification.QuerySpecification(/, **data: Any)
```

`from roboto.query import QuerySpecification`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/query/specification.py#L54-L110)

Bases: `pydantic.BaseModel`

A structured query: a condition on the fields of one kind of resource, and how to sort and page its results.

Run it with [`QueryClient`](/docs/reference/python-sdk/roboto/query/client#roboto.query.client.QueryClient) or [`RobotoSearch`](/docs/reference/python-sdk/roboto/roboto_search#roboto.roboto_search.RobotoSearch), or pass it to a method that takes one, such as [`query()`](/docs/reference/python-sdk/roboto/domain/datasets/dataset#roboto.domain.datasets.dataset.Dataset.query). To combine conditions, set `condition` to a [`ConditionGroup`](/docs/reference/python-sdk/roboto/query/conditions#roboto.query.conditions.ConditionGroup), whose conditions may themselves be groups. Keys the model does not declare are ignored. Building a specification raises `pydantic.ValidationError` when `max_results` is less than 1.

**Parameters**

- **data** (`Any`)

**Attributes**

- **QuerySpecification.after** (`str | None`) = `None`: Token from a previous page's response that resumes the listing after it. `None` starts at the first page.

- **QuerySpecification.condition** (`roboto.query.conditions.Condition | roboto.query.conditions.ConditionGroup | None`) = `None`: Condition the results must match: one comparison, or a group of them. `None` matches every resource.

- **QuerySpecification.limit** (`int`) = `1000`: Maximum number of results per page.

  Queries run through [`QueryClient`](/docs/reference/python-sdk/roboto/query/client#roboto.query.client.QueryClient) or [`RobotoSearch`](/docs/reference/python-sdk/roboto/roboto_search#roboto.roboto_search.RobotoSearch) ignore it: their page size is the `page_size` given to [`get_query_results()`](/docs/reference/python-sdk/roboto/query/client#roboto.query.client.QueryClient.get_query_results).

- **QuerySpecification.max_results** (`int | None`) = `None`: Maximum number of results across all pages, at least 1. `None` returns every result.

  Only queries run through [`QueryClient`](/docs/reference/python-sdk/roboto/query/client#roboto.query.client.QueryClient) or [`RobotoSearch`](/docs/reference/python-sdk/roboto/roboto_search#roboto.roboto_search.RobotoSearch) honor it. Other methods that take a `QuerySpecification`, such as [`query()`](/docs/reference/python-sdk/roboto/domain/datasets/dataset#roboto.domain.datasets.dataset.Dataset.query), ignore it and return every result.

- **QuerySpecification.model_config**: Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

- **QuerySpecification.sort_by** (`str | None`) = `None`: Field to sort results by. `None` sorts by a default field that depends on the kind of resource queried.

- **QuerySpecification.sort_direction** (`SortDirection | None`) = `None`: Direction to sort results in. `None` uses a default that depends on the kind of resource queried.

#### QuerySpecification.fields()

```python
def fields() -> set[str]
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/query/specification.py#L93-L110)

Return every field the query's conditions compare, including those in nested condition groups.

**Returns**

- `set[str]`

### SortDirection

```python
class roboto.query.specification.SortDirection
```

`from roboto.query import SortDirection`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/query/specification.py#L22-L51)

Bases: `roboto.compat.StrEnum`

Direction to sort query results in.

**Attributes**

- **SortDirection.Ascending** = `'ASC'`: Smallest or earliest value first.
- **SortDirection.Descending** = `'DESC'`: Largest or latest value first.

#### SortDirection.from_string()

```python
@staticmethod
def from_string(value: str) -> SortDirection
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/query/specification.py#L32-L48)

Return the sort direction that `"asc"` or `"desc"` names, in any case.

**Parameters**

- **value** (`str`): `"asc"` or `"desc"`, in any combination of upper and lower case.

**Raises**

- `ValueError`: `value` is neither `"asc"` nor `"desc"`.

**Returns**

- `SortDirection`
