---
sidebar:
  label: roboto.roboto_search
  order: 23
title: roboto.roboto_search
---
## Module Contents

### RobotoSearch

```python
class roboto.roboto_search.RobotoSearch(
    query_client: Optional[roboto.query.QueryClient] = None,
)
```

`from roboto import RobotoSearch`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/roboto_search.py#L42-L405)

Entry point for finding the datasets, files, topics, events and other resources that match a query.

Each `find_*` method takes a query, either a RoboQL string such as `"tags CONTAINS 'flight'"` or a [`QuerySpecification`](/docs/reference/python-sdk/roboto/query/specification#roboto.query.specification.QuerySpecification), and yields the matching resources as SDK objects, in the query's sort order. It sends nothing until iteration starts. Then it submits the query, checks every 2 seconds until Roboto has the results, and fetches them one page at a time as iteration reaches each page. To cap the number of results, add `LIMIT N` to a RoboQL query or set `max_results` on a specification.

Get a `RobotoSearch` from `from_env` or `for_roboto_client`, or build one from a [`QueryClient`](/docs/reference/python-sdk/roboto/query/client#roboto.query.client.QueryClient).

**Parameters**

- **query_client** (`Optional[roboto.query.QueryClient]`): Client that submits the queries and fetches their results. `None` builds one from the access token or config file profile that [`from_env()`](/docs/reference/python-sdk/roboto/config#roboto.config.RobotoConfig.from_env) reads. That client names no organization, so a caller who belongs to more than one organization should use `from_env` instead.

**Raises**

- `FileNotFoundError`: `query_client` is not given, no access token is set, and the config file does not exist.
- `OSError`: `query_client` is not given and the config file exists but cannot be read.
- `ValueError`: `query_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): `query_client` is not given and the access token begins with `robo_pat`, a format Roboto retired in March 2024.

> **Note**
>
> Roboto does not report a query that fails to run. Iteration keeps waiting for its results until `timeout_seconds` passes, which by default it never does.

#### RobotoSearch.find_collections()

```python
def find_collections(
    query: Optional[roboto.query.Query] = None,
    timeout_seconds: float = math.inf,
) -> collections.abc.Generator[roboto.domain.collections.Collection, None, None]
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/roboto_search.py#L114-L141)

Yield the collections that match a query.

**Parameters**

- **query** (`Optional[roboto.query.Query]`): RoboQL query string or [`QuerySpecification`](/docs/reference/python-sdk/roboto/query/specification#roboto.query.specification.QuerySpecification) to match. `None` matches every collection.
- **timeout_seconds** (`float`): Seconds to wait for the query's results. Waits indefinitely by default.

**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 ready within `timeout_seconds`. It surfaces on the first iteration.

**Returns**

- `collections.abc.Generator[roboto.domain.collections.Collection, None, None]`

**Usage**

```python
from roboto import RobotoSearch
for collection in RobotoSearch.from_env().find_collections("name CONTAINS 'regression'"):
    print(collection.collection_id)
```

#### RobotoSearch.find_datasets()

```python
def find_datasets(
    query: Optional[roboto.query.Query] = None,
    content_mode: roboto.query.QueryContentMode = QueryContentMode.RecordOnly,
    timeout_seconds: float = math.inf,
) -> collections.abc.Generator[roboto.domain.datasets.Dataset, None, None]
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/roboto_search.py#L143-L183)

Yield the datasets that match a query.

**Parameters**

- **query** (`Optional[roboto.query.Query]`): RoboQL query string or [`QuerySpecification`](/docs/reference/python-sdk/roboto/query/specification#roboto.query.specification.QuerySpecification) to match. `None` matches every dataset.
- **content_mode** (`roboto.query.QueryContentMode`): Whether each dataset comes with its key-value metadata. [`RecordOnly`](/docs/reference/python-sdk/roboto/query/api#roboto.query.api.QueryContentMode.RecordOnly) leaves it out, and the first [`get_metadata()`](/docs/reference/python-sdk/roboto/domain/datasets/dataset#roboto.domain.datasets.dataset.Dataset.get_metadata) call on a dataset fetches it. [`RecordWithMeta`](/docs/reference/python-sdk/roboto/query/api#roboto.query.api.QueryContentMode.RecordWithMeta) includes it, at the cost of larger responses.
- **timeout_seconds** (`float`): Seconds to wait for the query's results. Waits indefinitely by default.

**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 ready within `timeout_seconds`. It surfaces on the first iteration.

**Returns**

- `collections.abc.Generator[roboto.domain.datasets.Dataset, None, None]`

**Usage**

Print the metadata of every dataset tagged `flight`:

```python
from roboto import RobotoSearch
from roboto.query import QueryContentMode
for dataset in RobotoSearch.from_env().find_datasets(
    "tags CONTAINS 'flight'", content_mode=QueryContentMode.RecordWithMeta
):
    print(dataset.dataset_id, dataset.get_metadata())
```

#### RobotoSearch.find_devices()

```python
def find_devices(
    query: Optional[roboto.query.Query] = None,
    timeout_seconds: float = math.inf,
) -> collections.abc.Generator[roboto.domain.devices.Device, None, None]
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/roboto_search.py#L185-L213)

Yield the devices that match a query.

**Parameters**

- **query** (`Optional[roboto.query.Query]`): RoboQL query string or [`QuerySpecification`](/docs/reference/python-sdk/roboto/query/specification#roboto.query.specification.QuerySpecification) to match. `None` matches every device.
- **timeout_seconds** (`float`): Seconds to wait for the query's results. Waits indefinitely by default.

**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 ready within `timeout_seconds`. It surfaces on the first iteration.

**Returns**

- `collections.abc.Generator[roboto.domain.devices.Device, None, None]`

**Usage**

```python
from roboto import RobotoSearch
searcher = RobotoSearch.from_env()
for device in searcher.find_devices("tags CONTAINS 'warehouse'"):
    print(device.device_id)
```

#### RobotoSearch.find_events()

```python
def find_events(
    query: Optional[roboto.query.Query] = None,
    timeout_seconds: float = math.inf,
) -> collections.abc.Generator[Union[roboto.domain.events.Event, roboto.experimental.events.Event]]
```

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

Yield the events that match a query.

**Parameters**

- **query** (`Optional[roboto.query.Query]`): RoboQL query string or [`QuerySpecification`](/docs/reference/python-sdk/roboto/query/specification#roboto.query.specification.QuerySpecification) to match. `None` matches every event.
- **timeout_seconds** (`float`): Seconds to wait for the query's results. Waits indefinitely by default.

**Yields**

- Dataset events as [`Event`](/docs/reference/python-sdk/roboto/domain/events/event#roboto.domain.events.event.Event) and, in organizations that have session events enabled and to a caller who may view the organization's sessions, session events as `roboto.experimental.events.Event`. Only a session event has a `session_id`, so a condition on `session_id` selects one kind or the other.

**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 ready within `timeout_seconds`. It surfaces on the first iteration.

**Returns**

- `collections.abc.Generator[Union[roboto.domain.events.Event, roboto.experimental.events.Event]]`

**Usage**

Print every event named `Hard landing`:

```python
from roboto import RobotoSearch
for event in RobotoSearch.from_env().find_events("name = 'Hard landing'"):
    print(event.event_id, event.name)
```

Print only the events created on one session:

```python
for event in RobotoSearch.from_env().find_events("session_id = 'se_12345'"):
    print(event.event_id, event.start_time)
```

#### RobotoSearch.find_files()

```python
def find_files(
    query: Optional[roboto.query.Query] = None,
    timeout_seconds: float = math.inf,
) -> collections.abc.Generator[roboto.domain.files.File, None, None]
```

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

Yield the files that match a query.

**Parameters**

- **query** (`Optional[roboto.query.Query]`): RoboQL query string or [`QuerySpecification`](/docs/reference/python-sdk/roboto/query/specification#roboto.query.specification.QuerySpecification) to match. `None` matches every file.
- **timeout_seconds** (`float`): Seconds to wait for the query's results. Waits indefinitely by default.

**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 ready within `timeout_seconds`. It surfaces on the first iteration.

**Returns**

- `collections.abc.Generator[roboto.domain.files.File, None, None]`

**Usage**

```python
from roboto import RobotoSearch
for file in RobotoSearch.from_env().find_files("name CONTAINS '.mcap'"):
    print(file.file_id, file.relative_path)
```

#### RobotoSearch.find_message_paths()

```python
def find_message_paths(
    query: Optional[roboto.query.Query] = None,
    timeout_seconds: float = math.inf,
) -> collections.abc.Generator[roboto.domain.topics.MessagePath, None, None]
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/roboto_search.py#L244-L271)

Yield the message paths that match a query.

**Parameters**

- **query** (`Optional[roboto.query.Query]`): RoboQL query string or [`QuerySpecification`](/docs/reference/python-sdk/roboto/query/specification#roboto.query.specification.QuerySpecification) to match. `None` matches every message path.
- **timeout_seconds** (`float`): Seconds to wait for the query's results. Waits indefinitely by default.

**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 ready within `timeout_seconds`. It surfaces on the first iteration.

**Returns**

- `collections.abc.Generator[roboto.domain.topics.MessagePath, None, None]`

**Usage**

```python
from roboto import RobotoSearch
for message_path in RobotoSearch.from_env().find_message_paths("message_path CONTAINS 'velocity'"):
    print(message_path.topic_id, message_path.path)
```

#### RobotoSearch.find_sessions()

```python
def find_sessions(
    query: Optional[roboto.query.Query] = None,
    timeout_seconds: float = math.inf,
) -> collections.abc.Generator[roboto.experimental.sessions.Session, None, None]
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/roboto_search.py#L355-L405)

Yield the sessions that match a query.

A query can filter on these fields, among others:

- `session_id` (alias `id`).
- `name`.
- `min_timestamp_ns` (alias `start_time`): inclusive start of the session's recorded time window.
- `max_timestamp_ns` (alias `end_time`): inclusive end of the session's recorded time window.
- `duration`: `max_timestamp_ns - min_timestamp_ns`, compared only with an integer number of nanoseconds.
- `dataset.dataset_id` (alias `dataset.id`): matches sessions that include at least one file from the dataset. Takes `=` and `!=` only.
- `device.device_id` (alias `device.id`): matches sessions attached to the device. Takes `=` and `!=` only.
- `device.device_type_id`: matches sessions attached to a device of that type. Takes `=`, `!=`, `IS_NULL` and `IS_NOT_NULL` only.
- `collection.collection_id` (alias `collection.id`): matches sessions in the collection. Takes `=` and `!=` only.
- `metric.<name>` (alias `metrics.<name>`): matches sessions by the session metric `<name>`, whose dots are part of the name (`metric.cpu.load.max`). `=`, `!=`, `>`, `>=`, `<` and `<=` take a number and match only sessions that have the metric with a value that satisfies the comparison. `IS_NOT_NULL` and `EXISTS` take no value and match sessions that have the metric; `IS_NULL` and `NOT_EXISTS` match sessions that lack it.

`min_timestamp_ns` and `max_timestamp_ns` accept any value [`to_epoch_nanoseconds()`](/docs/reference/python-sdk/roboto/time#roboto.time.to_epoch_nanoseconds) accepts: an integer is nanoseconds since the Unix epoch, a float, `Decimal` or `"<sec>.<nsec>"` string is seconds, and an ISO 8601 string or a `datetime` is read as UTC when it has no timezone. A session with no files has no recorded time window, so on those two fields only `IS_NULL` matches it.

Results can be sorted by `session_id`, `name`, `min_timestamp_ns` or `duration`.

**Parameters**

- **query** (`Optional[roboto.query.Query]`): RoboQL query string or [`QuerySpecification`](/docs/reference/python-sdk/roboto/query/specification#roboto.query.specification.QuerySpecification) to match. `None` matches every session.
- **timeout_seconds** (`float`): Seconds to wait for the query's results. Waits indefinitely by default.

**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 ready within `timeout_seconds`. It surfaces on the first iteration.

**Returns**

- `collections.abc.Generator[roboto.experimental.sessions.Session, None, None]`

#### RobotoSearch.find_topics()

```python
def find_topics(
    query: Optional[roboto.query.Query] = None,
    timeout_seconds: float = math.inf,
) -> collections.abc.Generator[roboto.domain.topics.Topic, None, None]
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/roboto_search.py#L273-L307)

Yield the topics that match a query.

**Parameters**

- **query** (`Optional[roboto.query.Query]`): RoboQL query string or [`QuerySpecification`](/docs/reference/python-sdk/roboto/query/specification#roboto.query.specification.QuerySpecification) to match. `None` matches every topic.
- **timeout_seconds** (`float`): Seconds to wait for the query's results. Waits indefinitely by default.

**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 ready within `timeout_seconds`. It surfaces on the first iteration.

**Returns**

- `collections.abc.Generator[roboto.domain.topics.Topic, None, None]`

**Usage**

Plot the CPU load of every topic whose `cpuload.load` passed 0.9:

```python
import matplotlib.pyplot as plt
from roboto import RobotoSearch
searcher = RobotoSearch.from_env()
for topic in searcher.find_topics("msgpaths[cpuload.load].max > 0.9"):
    df = topic.get_data_as_df(message_paths_include=["cpuload.load"])
    plt.plot(df.index, df["cpuload.load"], label=topic.topic_id)
plt.legend()
plt.show()
```

#### RobotoSearch.for_roboto_client()

```python
@classmethod
def for_roboto_client(
    roboto_client: roboto.http.RobotoClient,
    org_id: Optional[str] = None,
) -> RobotoSearch
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/roboto_search.py#L76-L89)

Build a `RobotoSearch` that sends its queries through `roboto_client`.

**Parameters**

- **roboto_client** (`roboto.http.RobotoClient`): Client to make requests to Roboto with.
- **org_id** (`Optional[str]`): Organization to search. Required when the caller belongs to more than one organization; otherwise the caller's only organization.

**Returns**

- `RobotoSearch`

**Usage**

```python
from roboto import RobotoClient, RobotoSearch
roboto_client = RobotoClient.for_profile("prod")
roboto_search = RobotoSearch.for_roboto_client(roboto_client, org_id="og_12345")
```

#### RobotoSearch.from_env()

```python
@classmethod
def from_env() -> RobotoSearch
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/roboto_search.py#L92-L109)

Build a `RobotoSearch` that uses the credentials and organization the environment gives.

Queries go through the client [`from_env()`](/docs/reference/python-sdk/roboto/http/roboto_client#roboto.http.roboto_client.RobotoClient.from_env) returns, which reads an access token from `ROBOTO_API_KEY` or `ROBOTO_BEARER_TOKEN`, or else a profile from the Roboto config file, and raises when it can read neither. The search runs in the organization `ROBOTO_ORG_ID` names or, when that is unset, in the [`org_id`](/docs/reference/python-sdk/roboto/config#roboto.config.RobotoConfig.org_id) that `roboto setup` saved to the config file profile. Only a caller who belongs to more than one organization needs either.

**Usage**

```python
import roboto
roboto_search = roboto.RobotoSearch.from_env()
for dataset in roboto_search.find_datasets():
    print(dataset.name)
```

**Returns**

- `RobotoSearch`
