---
sidebar:
  label: roboto.query.api
  order: 0
title: roboto.query.api
---
## Module Contents

### MAX_VALUE_COUNTS_LIMIT

```python
roboto.query.api.MAX_VALUE_COUNTS_LIMIT: int = 1000
```

`from roboto.query import MAX_VALUE_COUNTS_LIMIT`

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

Maximum number of values one query's value counts list, and the number they list when the request sets no limit.

### QualifiedRoboqlQuery

```python
class roboto.query.api.QualifiedRoboqlQuery(/, **data: Any)
```

`from roboto.query import QualifiedRoboqlQuery`

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

Bases: `pydantic.BaseModel`

Response body of `POST /v1/query/convert/nlp-to-roboql`.

Holds the RoboQL query Roboto's AI writes from a natural-language prompt, and the kind of resource it searches.

**Parameters**

- **data** (`Any`)

**Attributes**

- **QualifiedRoboqlQuery.query** (`str`) = `None`: RoboQL query: its conditions, and any sort order and limit.
- **QualifiedRoboqlQuery.target** (`QueryTarget`) = `None`: Kind of resource the query searches.

### QueryContentMode

```python
class roboto.query.api.QueryContentMode
```

`from roboto.query import QueryContentMode`

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

Bases: `roboto.compat.StrEnum`

Content mode of query results: whether each result includes its key-value metadata.

Only dataset queries honor it. Queries of every other target return the same results in either mode.

**Attributes**

- **QueryContentMode.RecordOnly** = `'record_only'`: Results without their key-value metadata.

  Each dataset keeps its tags and custom fields. Leaving out metadata, which can be large, keeps responses small, so a page of results returns sooner and can hold more results. Use this mode unless you need each result's metadata at once.

- **QueryContentMode.RecordWithMeta** = `'record_with_meta'`: Results with their key-value metadata.

### QueryContext

```python
class roboto.query.api.QueryContext(/, **data: Any)
```

`from roboto.query import QueryContext`

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

Bases: `pydantic.BaseModel`

Stored form of a query: the format it is stored in, and its contents.

Carried in `QueryRecord.query_ctx`.

**Parameters**

- **data** (`Any`)

**Attributes**

- **QueryContext.query** (`dict[str, Any]`) = `None`: Contents of the query, in the format `query_scheme` names.

  Under `QueryScheme.QuerySpecV1`, `spec` holds the serialized [`QuerySpecification`](/docs/reference/python-sdk/roboto/query/specification#roboto.query.specification.QuerySpecification) and `content_mode` the `QueryContentMode`. A query submitted as RoboQL also holds the RoboQL string under `roboql`, and one submitted as a search term holds the term under `term`.

- **QueryContext.query_scheme** (`QueryScheme`): Format of `query`.

### QueryRecord

```python
class roboto.query.api.QueryRecord(/, **data: Any)
```

`from roboto.query import QueryRecord`

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

Bases: `pydantic.BaseModel`

Data record of a query, as the Roboto API returns it.

A query is a search of one kind of resource in an organization, stored so that its results can be fetched a page at a time. [`get_query_record()`](/docs/reference/python-sdk/roboto/query/client#roboto.query.client.QueryClient.get_query_record) and the `submit_*` methods of [`QueryClient`](/docs/reference/python-sdk/roboto/query/client#roboto.query.client.QueryClient) return it.

**Parameters**

- **data** (`Any`)

**Attributes**

- **QueryRecord.modified** (`datetime.datetime`) = `None`: Time the query was last modified.

- **QueryRecord.org_id** (`str`) = `None`: ID of the organization the query searches.

- **QueryRecord.query_ctx** (`QueryContext`) = `None`: Stored form of the query.

- **QueryRecord.query_id** (`str`) = `None`: Unique ID of the query, beginning with `q_`.

- **QueryRecord.result_count** (`int`) = `None`: Unused. Roboto always returns `0`, since it does not count a query's results when it stores the query.

  `GET /v1/query/id/{query_id}/count` returns the number of results.

- **QueryRecord.status** (`QueryStatus`) = `None`: Status of the query: whether its results are ready to fetch.

- **QueryRecord.submitted** (`datetime.datetime`) = `None`: Time the query was submitted.

- **QueryRecord.submitted_by** (`str`) = `None`: ID of the user who submitted the query.

- **QueryRecord.target** (`QueryTarget`) = `None`: Kind of resource the query searches.

### QueryScheme

```python
class roboto.query.api.QueryScheme
```

`from roboto.query import QueryScheme`

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

Bases: `roboto.compat.StrEnum`

Format of a stored query, as `QueryContext.query_scheme` holds it.

**Attributes**

- **QueryScheme.QuerySpecV1** = `'query_spec_v1'`: Query stored as a serialized [`QuerySpecification`](/docs/reference/python-sdk/roboto/query/specification#roboto.query.specification.QuerySpecification).

  Roboto stores every query this way.

### QueryStatus

```python
class roboto.query.api.QueryStatus(*args, **kwds)
```

`from roboto.query import QueryStatus`

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

Bases: `enum.Enum`

Status of a query: whether its results are ready to fetch.

Fetching the results of a query in any status but `ResultsAvailable` raises `RobotoNotReadyException`.

**Attributes**

- **QueryStatus.Failed** = `'failed'`: Unused. Roboto sets no query to this status.

  A query that cannot run instead raises an error when it is submitted or when its results are fetched.

- **QueryStatus.ResultsAvailable** = `'results_available'`: Results are ready to fetch.

  Roboto sets a query to this status when it is submitted, and runs the query each time a page of its results is fetched.

- **QueryStatus.Scheduled** = `'scheduled'`: Query is stored, and its results are not yet ready to fetch.

### QueryStorageContext

```python
class roboto.query.api.QueryStorageContext(/, **data: Any)
```

`from roboto.query import QueryStorageContext`

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

Bases: `pydantic.BaseModel`

Location and format of a query's stored results.

No SDK method or Roboto route uses this model.

**Parameters**

- **data** (`Any`)

**Attributes**

- **QueryStorageContext.storage_ctx** (`dict[str, Any]`) = `None`: Location of the stored results, in the form `storage_scheme` names.
- **QueryStorageContext.storage_scheme** (`QueryStorageScheme`): Format of the stored results.

### QueryStorageScheme

```python
class roboto.query.api.QueryStorageScheme
```

`from roboto.query import QueryStorageScheme`

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

Bases: `roboto.compat.StrEnum`

Format of a query's stored results, as `QueryStorageContext.storage_scheme` holds it.

No Roboto API returns or accepts it.

**Attributes**

- **QueryStorageScheme.S3ManifestV1** = `'s3_manifest_v1'`: Results stored as files, with a manifest file that lists the result parts and how to read them into rows.

### QueryTarget

```python
class roboto.query.api.QueryTarget
```

`from roboto.query import QueryTarget`

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

Bases: `roboto.compat.StrEnum`

Kind of resource a query searches.

**Attributes**

- **QueryTarget.Collections** = `'collections'`: Collections ([`Collection`](/docs/reference/python-sdk/roboto/domain/collections/collection#roboto.domain.collections.collection.Collection)).
- **QueryTarget.Datasets** = `'datasets'`: Datasets ([`Dataset`](/docs/reference/python-sdk/roboto/domain/datasets/dataset#roboto.domain.datasets.dataset.Dataset)).
- **QueryTarget.Devices** = `'devices'`: Devices ([`Device`](/docs/reference/python-sdk/roboto/domain/devices/device#roboto.domain.devices.device.Device)).
- **QueryTarget.Events** = `'events'`: Events ([`Event`](/docs/reference/python-sdk/roboto/domain/events/event#roboto.domain.events.event.Event)).
- **QueryTarget.Files** = `'files'`: Files ([`File`](/docs/reference/python-sdk/roboto/domain/files/file#roboto.domain.files.file.File)).
- **QueryTarget.Sessions** = `'sessions'`: Sessions ([`Session`](/docs/reference/python-sdk/roboto/experimental/sessions/session#roboto.experimental.sessions.session.Session)).
- **QueryTarget.TopicMessagePaths** = `'topic_message_paths'`: Message paths of topics ([`MessagePath`](/docs/reference/python-sdk/roboto/domain/topics/message_path#roboto.domain.topics.message_path.MessagePath)).
- **QueryTarget.Topics** = `'topics'`: Topics ([`Topic`](/docs/reference/python-sdk/roboto/domain/topics/topic#roboto.domain.topics.topic.Topic)).

### SubmitRoboqlQueryRequest

```python
class roboto.query.api.SubmitRoboqlQueryRequest(/, **data: Any)
```

`from roboto.query import SubmitRoboqlQueryRequest`

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

Bases: `pydantic.BaseModel`

Request body for [`submit_roboql()`](/docs/reference/python-sdk/roboto/query/client#roboto.query.client.QueryClient.submit_roboql).

**Parameters**

- **data** (`Any`)

**Attributes**

- **SubmitRoboqlQueryRequest.content_mode** (`QueryContentMode`) = `None`: Whether each result includes its key-value metadata (`QueryContentMode`).

- **SubmitRoboqlQueryRequest.query** (`str | None`) = `None`: RoboQL query: its conditions, and any sort order and `LIMIT` on the total number of results.

  `None` matches every resource of `target`. A string that is not valid RoboQL raises `RobotoIllegalArgumentException`.

- **SubmitRoboqlQueryRequest.target** (`QueryTarget`) = `None`: Kind of resource the query searches.

### SubmitStructuredQueryRequest

```python
class roboto.query.api.SubmitStructuredQueryRequest(/, **data: Any)
```

`from roboto.query import SubmitStructuredQueryRequest`

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

Bases: `pydantic.BaseModel`

Request body for [`submit_structured()`](/docs/reference/python-sdk/roboto/query/client#roboto.query.client.QueryClient.submit_structured).

**Parameters**

- **data** (`Any`)

**Attributes**

- **SubmitStructuredQueryRequest.content_mode** (`QueryContentMode`) = `None`: Whether each result includes its key-value metadata (`QueryContentMode`).

- **SubmitStructuredQueryRequest.query** (`roboto.query.specification.QuerySpecification`) = `None`: Condition, sort order, and maximum number of results of the query.

  When it sets no `sort_by`, Roboto sorts the results by the target's default sort field, if the target has one.

- **SubmitStructuredQueryRequest.target** (`QueryTarget`) = `None`: Kind of resource the query searches.

- **SubmitStructuredQueryRequest.value_counts** (`ValueCountsSpec | None`) = `None`: Experimental, and may change or be removed without notice.

  Field whose values to count over the records the query matches, or `None` to count none. Read the counts with `GET /v1/query/id/{query_id}/value-counts`. Only some callers may read them; any other caller gets `RobotoFeatureNotAvailableException`. Supported for the `Events`, `Sessions`, `Datasets`, `Devices`, `Collections`, and `Files` members of `QueryTarget`.

### SubmitTermQueryRequest

```python
class roboto.query.api.SubmitTermQueryRequest(/, **data: Any)
```

`from roboto.query import SubmitTermQueryRequest`

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

Bases: `pydantic.BaseModel`

Request body for [`submit_term()`](/docs/reference/python-sdk/roboto/query/client#roboto.query.client.QueryClient.submit_term).

**Parameters**

- **data** (`Any`)

**Attributes**

- **SubmitTermQueryRequest.content_mode** (`QueryContentMode`) = `None`: Whether each result includes its key-value metadata (`QueryContentMode`).
- **SubmitTermQueryRequest.target** (`QueryTarget`) = `None`: Kind of resource the query searches.
- **SubmitTermQueryRequest.term** (`str`) = `None`: Text to search for in the target's ID and text fields, such as a dataset's ID, name, description, and tags.
