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

### McapTopicReader

```python
class roboto.domain.topics.mcap_topic_reader.McapTopicReader(
    roboto_client: Optional[roboto.http.RobotoClient] = None,
    signed_url_resolver: Optional[SignedUrlResolver] = None,
)
```

`from roboto.domain.topics.mcap_topic_reader import McapTopicReader`

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

Bases: [`roboto.domain.topics.topic_reader.TopicReader`](/docs/reference/python-sdk/roboto/domain/topics/topic_reader#roboto.domain.topics.topic_reader.TopicReader)

Reader of topic data stored in MCAP files.

The SDK's own code uses it; to read topic data, use the `get_data` or `get_data_as_df` methods 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.

Reads each file with HTTP range requests, so it downloads only the chunks that hold the requested messages rather than the whole file.

**Parameters**

- **roboto_client** (`Optional[roboto.http.RobotoClient]`): Client to make requests to Roboto with, to fetch each file's signed URL from `v1/files/{file_id}/signed-url`. Ignored when `signed_url_resolver` is given.
- **signed_url_resolver** (`Optional[SignedUrlResolver]`): Callable that returns a signed download URL for a file ID. Takes precedence over `roboto_client`.

**Raises**

- `ValueError`: Neither `roboto_client` nor `signed_url_resolver` is given.

#### McapTopicReader.accepts()

```python
@staticmethod
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/mcap_topic_reader.py#L81-L91)

Return whether every mapping's representation is stored as MCAP, and so whether this reader can read it.

An empty iterable returns `True`.

**Parameters**

- **message_paths_to_representations** (`collections.abc.Iterable[roboto.domain.topics.record.MessagePathRepresentationMapping]`)

**Returns**

- `bool`

#### McapTopicReader.get_data()

```python
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,
    topic_name: Optional[str] = None,
) -> collections.abc.Generator[tuple[roboto.domain.topics.topic_reader.Timestamp, dict[str, Any]], None, None]
```

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

Yield `(log_time, record)` pairs from the mappings' MCAP files in log-time order.

Each record merges, from every file whose next message has that log time, that message's fields at the requested message paths.

**Parameters**

- **message_paths_to_representations** (`collections.abc.Iterable[roboto.domain.topics.record.MessagePathRepresentationMapping]`): Message paths to read. Each [`MessagePathRepresentationMapping`](/docs/reference/python-sdk/roboto/domain/topics/record#roboto.domain.topics.record.MessagePathRepresentationMapping) pairs message paths with the representation whose MCAP file stores them. A mapping whose representation does not belong to a file is skipped with a logged warning.
- **start_time** (`Optional[int]`): Inclusive start of the log-time range, in nanoseconds. `None` leaves the range unbounded below.
- **end_time** (`Optional[int]`): Exclusive end of the log-time range, in nanoseconds. `None` leaves the range unbounded above.
- **timestamp_message_path_representation_mapping** (`Optional[roboto.domain.topics.record.MessagePathRepresentationMapping]`): Ignored: each record's timestamp is the log time of the messages it merges.
- **topic_name** (`Optional[str]`): Topic whose MCAP channels to read. `None` reads every channel.

**Yields**

- `(log_time, record)` tuples -- the log time in nanoseconds and the merged record.

**Raises**

- [`RobotoInternalException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoInternalException): `topic_name` is given and a file's summary lists no channel on that topic. It surfaces on the first iteration.

**Returns**

- `collections.abc.Generator[tuple[roboto.domain.topics.topic_reader.Timestamp, dict[str, Any]], None, None]`

#### McapTopicReader.get_data_as_df()

```python
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/mcap_topic_reader.py#L192-L231)

Fetch this reader's records as a series of log times and a data frame of records.

The records are the ones `get_data` yields. Reads every channel of each file. Nested fields become columns with dot-delimited names, such as `pose.position.x`.

**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 log-time range, in nanoseconds. `None` leaves the range unbounded below.
- **end_time** (`Optional[int]`): Exclusive end of the log-time range, in nanoseconds. `None` leaves the range unbounded above.
- **timestamp_message_path_representation_mapping** (`Optional[roboto.domain.topics.record.MessagePathRepresentationMapping]`): Ignored: each row's timestamp is the log time of the messages it merges.

**Returns**

- `tuple[pandas.Series, pandas.DataFrame]`: `(log_times, records)`: the log time of each row in nanoseconds and a data frame with one row per merged record.

**Raises**

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

### RobotoClientUrlResolver

```python
class roboto.domain.topics.mcap_topic_reader.RobotoClientUrlResolver(
    roboto_client: roboto.http.RobotoClient,
)
```

`from roboto.domain.topics.mcap_topic_reader import RobotoClientUrlResolver`

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

`SignedUrlResolver` that fetches each URL from Roboto.

[`get_data()`](/docs/reference/python-sdk/roboto/domain/topics/topic#roboto.domain.topics.topic.Topic.get_data) fetches MCAP files' signed URLs through it, so most code never calls it. `McapTopicReader` builds one when it is given a `roboto_client` and no `signed_url_resolver`.

**Parameters**

- **roboto_client** (`roboto.http.RobotoClient`)

### SignedUrlResolver

```python
class roboto.domain.topics.mcap_topic_reader.SignedUrlResolver
```

`from roboto.domain.topics.mcap_topic_reader import SignedUrlResolver`

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

Bases: `Protocol`

Callable that turns a file's ID into a signed URL its contents can be downloaded from.

### logger

```python
roboto.domain.topics.mcap_topic_reader.logger
```

`from roboto.domain.topics.mcap_topic_reader import logger`

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