---
sidebar:
  hidden: true
title: roboto.domain.topics.topic_reader
---
## Module Contents

### Timestamp

```python
type roboto.domain.topics.topic_reader.Timestamp = typing.Union[int, float]
```

`from roboto.domain.topics import Timestamp`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/topics/topic_reader.py#L21-L21)

Time of a topic message, in nanoseconds since the Unix epoch.

### TopicReader

```python
class roboto.domain.topics.topic_reader.TopicReader
```

`from roboto.domain.topics.topic_reader import TopicReader`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/topics/topic_reader.py#L25-L103)

Bases: `abc.ABC`

Interface for reading topic data stored in one storage format, such as MCAP or Parquet.

The SDK's own code uses it; to read topic data, use the `get_data` or `get_data_as_df` method of [`Topic`](/docs/reference/python-sdk/roboto/domain/topics/topic#roboto.domain.topics.topic.Topic), [`MessagePath`](/docs/reference/python-sdk/roboto/domain/topics/message_path#roboto.domain.topics.message_path.MessagePath), or [`Event`](/docs/reference/python-sdk/roboto/domain/events/event#roboto.domain.events.event.Event) instead.

[`TopicDataService`](/docs/reference/python-sdk/roboto/domain/topics/topic_data_service#roboto.domain.topics.topic_data_service.TopicDataService) reads a topic with the first reader whose `accepts` returns `True` for the topic's selected representations.

#### TopicReader.accepts()

```python
@staticmethod
@abstractmethod
def accepts(
    message_paths_to_representations: collections.abc.Iterable[roboto.domain.topics.record.MessagePathRepresentationMapping],
) -> bool
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/topics/topic_reader.py#L38-L47)

Return whether this reader can read every mapping's representation.

**Parameters**

- **message_paths_to_representations** (`collections.abc.Iterable[roboto.domain.topics.record.MessagePathRepresentationMapping]`): Message paths to read, each paired with the representation that stores it.

**Returns**

- `bool`

#### TopicReader.get_data()

```python
@abstractmethod
def get_data(
    message_paths_to_representations: collections.abc.Iterable[roboto.domain.topics.record.MessagePathRepresentationMapping],
    start_time: Optional[int] = None,
    end_time: Optional[int] = None,
    timestamp_message_path_representation_mapping: Optional[roboto.domain.topics.record.MessagePathRepresentationMapping] = None,
) -> collections.abc.Generator[tuple[Timestamp, dict[str, Any]], None, None]
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/topics/topic_reader.py#L50-L75)

Yield `(timestamp, record)` pairs for the message paths, limited to a time range.

**Parameters**

- **message_paths_to_representations** (`collections.abc.Iterable[roboto.domain.topics.record.MessagePathRepresentationMapping]`): Message paths to read, each paired with the representation that stores it.
- **start_time** (`Optional[int]`): Inclusive start of the time range, in nanoseconds since the Unix epoch. `None` leaves the range unbounded below.
- **end_time** (`Optional[int]`): Exclusive end of the time range, in nanoseconds since the Unix epoch. `None` leaves the range unbounded above.
- **timestamp_message_path_representation_mapping** (`Optional[roboto.domain.topics.record.MessagePathRepresentationMapping]`): Mapping whose message paths include the one with canonical data type [`Timestamp`](/docs/reference/python-sdk/roboto/domain/topics/record#roboto.domain.topics.record.CanonicalDataType.Timestamp), whose values become each record's timestamp. A reader whose storage format records each message's time, as MCAP does, ignores it.

**Yields**

- `(timestamp, record)` tuples -- the timestamp in nanoseconds since the Unix epoch, and a dictionary of the record's requested fields.

**Returns**

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

#### TopicReader.get_data_as_df()

```python
@abstractmethod
def get_data_as_df(
    message_paths_to_representations: collections.abc.Iterable[roboto.domain.topics.record.MessagePathRepresentationMapping],
    start_time: Optional[int] = None,
    end_time: Optional[int] = None,
    timestamp_message_path_representation_mapping: Optional[roboto.domain.topics.record.MessagePathRepresentationMapping] = None,
) -> tuple[pandas.Series, pandas.DataFrame]
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/topics/topic_reader.py#L78-L103)

Fetch the records `get_data` yields, as a series of timestamps and a data frame.

**Parameters**

- **message_paths_to_representations** (`collections.abc.Iterable[roboto.domain.topics.record.MessagePathRepresentationMapping]`): Message paths to read, as for `get_data`.
- **start_time** (`Optional[int]`): Inclusive start of the time range, in nanoseconds since the Unix epoch. `None` leaves the range unbounded below.
- **end_time** (`Optional[int]`): Exclusive end of the time range, in nanoseconds since the Unix epoch. `None` leaves the range unbounded above.
- **timestamp_message_path_representation_mapping** (`Optional[roboto.domain.topics.record.MessagePathRepresentationMapping]`): Mapping that holds the timestamp message path, as for `get_data`.

**Returns**

- `tuple[pandas.Series, pandas.DataFrame]`: `(timestamps, df)`: the timestamp of each row in nanoseconds since the Unix epoch, and a data frame with one row per record.

**Raises**

- `ImportError`: The `roboto[analytics]` extra is not installed.
