---
sidebar:
  label: roboto.query.client
  order: 1
title: roboto.query.client
---
## Module Contents

### Query

```python
type roboto.query.client.Query = typing.Union[RoboQLQuery, QuerySpecification]
```

`from roboto.query import Query`

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

Query of either form: a RoboQL string or a [`QuerySpecification`](/docs/reference/python-sdk/roboto/query/specification#roboto.query.specification.QuerySpecification).

### QueryClient

```python
class roboto.query.client.QueryClient(
    roboto_client: Optional[roboto.http.RobotoClient] = None,
    owner_org_id: Optional[str] = None,
    roboto_profile: Optional[str] = None,
)
```

`from roboto.query import QueryClient`

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

Client that submits queries to Roboto and yields each result as a dictionary.

[`RobotoSearch`](/docs/reference/python-sdk/roboto/roboto_search#roboto.roboto_search.RobotoSearch) runs the same queries and yields SDK objects, such as [`Dataset`](/docs/reference/python-sdk/roboto/domain/datasets/dataset#roboto.domain.datasets.dataset.Dataset), in place of dictionaries.

Each method that submits a query and yields its results submits it when iteration begins, not when the method is called, and then checks every 2 seconds until the results are available.

**Parameters**

- **roboto_client** (`Optional[roboto.http.RobotoClient]`): Client to make requests to Roboto with. Defaults to one built from [`from_env()`](/docs/reference/python-sdk/roboto/config#roboto.config.RobotoConfig.from_env) with `roboto_profile`.
- **owner_org_id** (`Optional[str]`): Organization to run and read queries in when a method names none. `None` leaves it to the organization the caller acts in.
- **roboto_profile** (`Optional[str]`): Config file profile to build the default `roboto_client` from. Ignored when `roboto_client` is given or the environment holds an access token.

**Raises**

- `FileNotFoundError`: `roboto_client` is not given, no access token is set, and the config file does not exist.
- `OSError`: `roboto_client` is not given and the config file exists but cannot be read.
- `ValueError`: `roboto_client` is not given and the config file is not a JSON object, holds no valid profile, or has no profile by the chosen name.
- [`RobotoDeprecatedException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoDeprecatedException): `roboto_client` is not given and the access token begins with `robo_pat`, a format Roboto retired in March 2024.

**Properties**

- **QueryClient.roboto_client** (`roboto.http.RobotoClient`): Client this query client makes requests to Roboto with.

#### QueryClient.are_query_results_available()

```python
def are_query_results_available(
    query_id: str,
    owner_org_id: Optional[str] = None,
) -> bool
```

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

Fetch whether a query has finished and its results can be read.

Returns `False` both while the query is scheduled and after it fails. To tell those apart, read [`status`](/docs/reference/python-sdk/roboto/query/api#roboto.query.api.QueryRecord.status) from `get_query_record`.

**Parameters**

- **query_id** (`str`): ID of the query.
- **owner_org_id** (`Optional[str]`): Organization that owns the query. Defaults to the organization this client was built with, and otherwise to the organization the caller acts in.

**Raises**

- [`RobotoNotFoundException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoNotFoundException): No query has this ID.

**Returns**

- `bool`

#### QueryClient.get_query_record()

```python
def get_query_record(
    query_id: str,
    owner_org_id: Optional[str] = None,
) -> roboto.query.api.QueryRecord
```

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

Fetch a query's record, which holds its status and result count.

**Parameters**

- **query_id** (`str`): ID of the query.
- **owner_org_id** (`Optional[str]`): Organization that owns the query. Defaults to the organization this client was built with, and otherwise to the organization the caller acts in.

**Raises**

- [`RobotoNotFoundException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoNotFoundException): No query has this ID.

**Returns**

- `roboto.query.api.QueryRecord`

#### QueryClient.get_query_results()

```python
def get_query_results(
    query_id: str,
    owner_org_id: Optional[str] = None,
    page_size: Optional[int] = None,
) -> collections.abc.Generator[dict[str, Any], None, None]
```

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

Yield every result of a query, fetching one page at a time as iteration reaches it.

**Parameters**

- **query_id** (`str`): ID of a query whose results are available.
- **owner_org_id** (`Optional[str]`): Organization that owns the query. Defaults to the organization this client was built with, and otherwise to the organization the caller acts in.
- **page_size** (`Optional[int]`): Number of results to fetch per request, from 1 to 1000 ([`MAX_PAGE_SIZE`](/docs/reference/python-sdk/roboto/query/specification#roboto.query.specification.MAX_PAGE_SIZE)). `None` fetches 50 ([`DEFAULT_PAGE_SIZE`](/docs/reference/python-sdk/roboto/query/specification#roboto.query.specification.DEFAULT_PAGE_SIZE)).

**Yields**

- Record of each matching resource, as a dictionary, in the query's sort order.

**Raises**

- [`RobotoIllegalArgumentException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoIllegalArgumentException): `page_size` is outside 1 to 1000. It surfaces on the first iteration.

**Returns**

- `collections.abc.Generator[dict[str, Any], None, None]`

#### QueryClient.submit_query()

```python
def submit_query(
    query: Optional[Query],
    target: roboto.query.api.QueryTarget,
    timeout_seconds: float,
    content_mode: roboto.query.api.QueryContentMode = QueryContentMode.RecordWithMeta,
    owner_org_id: Optional[str] = None,
) -> collections.abc.Generator[dict[str, Any], None, None]
```

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

Submit a RoboQL or structured query, wait for it to finish, and yield its results.

To cap the total number of results, set `max_results` on a [`QuerySpecification`](/docs/reference/python-sdk/roboto/query/specification#roboto.query.specification.QuerySpecification), or add `LIMIT N` to a RoboQL query.

**Parameters**

- **query** (`Optional[Query]`): RoboQL string or [`QuerySpecification`](/docs/reference/python-sdk/roboto/query/specification#roboto.query.specification.QuerySpecification) to run. `None` matches every resource of the `target` kind.
- **target** (`roboto.query.api.QueryTarget`): Kind of resource to search, such as [`Datasets`](/docs/reference/python-sdk/roboto/query/api#roboto.query.api.QueryTarget.Datasets).
- **timeout_seconds** (`float`): How long to wait for the query to finish, in seconds.
- **content_mode** (`roboto.query.api.QueryContentMode`): Whether each result includes the resource's metadata. See [`QueryContentMode`](/docs/reference/python-sdk/roboto/query/api#roboto.query.api.QueryContentMode).
- **owner_org_id** (`Optional[str]`): Organization to run the query in. Defaults to the organization this client was built with, and otherwise to the organization the caller acts in.

**Yields**

- Record of each matching resource, as a dictionary, in the query's sort order.

**Raises**

- [`RobotoIllegalArgumentException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoIllegalArgumentException): `query` is a string that is not valid RoboQL. It surfaces on the first iteration.
- [`roboto.waiters.TimeoutError`](/docs/reference/python-sdk/roboto/waiters#roboto.waiters.TimeoutError): The query's results were not available within `timeout_seconds`. A query that fails keeps the wait going until the timeout. It surfaces on the first iteration.

**Returns**

- `collections.abc.Generator[dict[str, Any], None, None]`

#### QueryClient.submit_roboql()

```python
def submit_roboql(
    request: roboto.query.api.SubmitRoboqlQueryRequest,
    owner_org_id: Optional[str] = None,
) -> roboto.query.api.QueryRecord
```

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

Submit a RoboQL query and return its record without waiting for it to finish.

Pass the record's `query_id` to `get_query_results` once `are_query_results_available` returns `True`.

**Parameters**

- **request** (`roboto.query.api.SubmitRoboqlQueryRequest`): Query to submit, and the kind of resource it searches.
- **owner_org_id** (`Optional[str]`): Organization to run the query in. Defaults to the organization this client was built with, and otherwise to the organization the caller acts in.

**Raises**

- [`RobotoIllegalArgumentException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoIllegalArgumentException): The query is not valid RoboQL.

**Returns**

- `roboto.query.api.QueryRecord`

#### QueryClient.submit_roboql_and_await_results()

```python
def submit_roboql_and_await_results(
    request: roboto.query.api.SubmitRoboqlQueryRequest,
    timeout_seconds: float,
    owner_org_id: Optional[str] = None,
) -> collections.abc.Generator[dict[str, Any], None, None]
```

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

Submit a RoboQL query, wait for it to finish, and yield its results.

To cap the total number of results, add `LIMIT N` to the query.

**Parameters**

- **request** (`roboto.query.api.SubmitRoboqlQueryRequest`): Query to submit, and the kind of resource it searches.
- **timeout_seconds** (`float`): How long to wait for the query to finish, in seconds.
- **owner_org_id** (`Optional[str]`): Organization to run the query in. Defaults to the organization this client was built with, and otherwise to the organization the caller acts in.

**Yields**

- Record of each matching resource, as a dictionary, in the query's sort order.

**Raises**

- [`RobotoIllegalArgumentException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoIllegalArgumentException): The query is not valid RoboQL. It surfaces on the first iteration.
- [`roboto.waiters.TimeoutError`](/docs/reference/python-sdk/roboto/waiters#roboto.waiters.TimeoutError): The query's results were not available within `timeout_seconds`. A query that fails keeps the wait going until the timeout. It surfaces on the first iteration.

**Returns**

- `collections.abc.Generator[dict[str, Any], None, None]`

#### QueryClient.submit_structured()

```python
def submit_structured(
    request: roboto.query.api.SubmitStructuredQueryRequest,
    owner_org_id: Optional[str] = None,
) -> roboto.query.api.QueryRecord
```

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

Submit a structured query and return its record without waiting for it to finish.

Pass the record's `query_id` to `get_query_results` once `are_query_results_available` returns `True`.

**Parameters**

- **request** (`roboto.query.api.SubmitStructuredQueryRequest`): Query to submit, and the kind of resource it searches.
- **owner_org_id** (`Optional[str]`): Organization to run the query in. Defaults to the organization this client was built with, and otherwise to the organization the caller acts in.

**Returns**

- `roboto.query.api.QueryRecord`

#### QueryClient.submit_structured_and_await_results()

```python
def submit_structured_and_await_results(
    request: roboto.query.api.SubmitStructuredQueryRequest,
    timeout_seconds: float,
    owner_org_id: Optional[str] = None,
) -> collections.abc.Generator[dict[str, Any], None, None]
```

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

Submit a structured query, wait for it to finish, and yield its results.

To cap the total number of results, set `max_results` on the request's [`QuerySpecification`](/docs/reference/python-sdk/roboto/query/specification#roboto.query.specification.QuerySpecification).

**Parameters**

- **request** (`roboto.query.api.SubmitStructuredQueryRequest`): Query to submit, and the kind of resource it searches.
- **timeout_seconds** (`float`): How long to wait for the query to finish, in seconds.
- **owner_org_id** (`Optional[str]`): Organization to run the query in. Defaults to the organization this client was built with, and otherwise to the organization the caller acts in.

**Yields**

- Record of each matching resource, as a dictionary, in the query's sort order.

**Raises**

- [`roboto.waiters.TimeoutError`](/docs/reference/python-sdk/roboto/waiters#roboto.waiters.TimeoutError): The query's results were not available within `timeout_seconds`. A query that fails keeps the wait going until the timeout. It surfaces on the first iteration.

**Returns**

- `collections.abc.Generator[dict[str, Any], None, None]`

#### QueryClient.submit_term()

```python
def submit_term(
    request: roboto.query.api.SubmitTermQueryRequest,
    owner_org_id: Optional[str] = None,
) -> roboto.query.api.QueryRecord
```

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

Submit a term query and return its record without waiting for it to finish.

A term query matches resources whose fields contain a search term. Pass the record's `query_id` to `get_query_results` once `are_query_results_available` returns `True`.

**Parameters**

- **request** (`roboto.query.api.SubmitTermQueryRequest`): Term to search for, and the kind of resource to search.
- **owner_org_id** (`Optional[str]`): Organization to run the query in. Defaults to the organization this client was built with, and otherwise to the organization the caller acts in.

**Returns**

- `roboto.query.api.QueryRecord`

#### QueryClient.submit_term_and_await_results()

```python
def submit_term_and_await_results(
    request: roboto.query.api.SubmitTermQueryRequest,
    timeout_seconds: float = math.inf,
    owner_org_id: Optional[str] = None,
) -> collections.abc.Generator[dict[str, Any], None, None]
```

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

Submit a term query, wait for it to finish, and yield its results.

**Parameters**

- **request** (`roboto.query.api.SubmitTermQueryRequest`): Term to search for, and the kind of resource to search.
- **timeout_seconds** (`float`): How long to wait for the query to finish, in seconds. Defaults to waiting indefinitely.
- **owner_org_id** (`Optional[str]`): Organization to run the query in. Defaults to the organization this client was built with, and otherwise to the organization the caller acts in.

**Yields**

- Record of each matching resource, as a dictionary, in the query's sort order.

**Raises**

- [`roboto.waiters.TimeoutError`](/docs/reference/python-sdk/roboto/waiters#roboto.waiters.TimeoutError): The query's results were not available within `timeout_seconds`. A query that fails keeps the wait going until the timeout, so with the default `timeout_seconds` the first iteration never returns.

**Returns**

- `collections.abc.Generator[dict[str, Any], None, None]`

### RoboQLQuery

```python
type roboto.query.client.RoboQLQuery = str
```

`from roboto.query.client import RoboQLQuery`

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

Query written in RoboQL, such as `"tags CONTAINS 'warehouse'"`.
