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

### Topic

```python
class roboto.domain.topics.topic.Topic(
    record: roboto.domain.topics.record.TopicRecord,
    roboto_client: Optional[roboto.http.RobotoClient] = None,
    topic_data_service: Optional[roboto.domain.topics.topic_data_service.TopicDataService] = None,
)
```

`from roboto import Topic`

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

A topic: a sequence of structured time-series data, called messages, linked to a source file.

Each message follows the topic's schema, whose fields or signals are the topic's message paths. Data under one topic name in one file forms one topic, so a recording split across several files has one topic per file for each topic name. Ingestion usually creates topics. A `Topic` reads their data, with `get_data` and `get_data_as_df`, and manages their message paths, representations, and metadata. Access to a topic follows access to its file.

Get a `Topic` from `from_id`, `from_name_and_file`, `get_by_file`, or [`get_topics()`](/docs/reference/python-sdk/roboto/domain/files/file#roboto.domain.files.file.File.get_topics). Each instance holds a copy of the topic's record: methods that change the topic update that copy from Roboto's response, and `refresh` fetches changes made elsewhere.

**Parameters**

- **record** (`roboto.domain.topics.record.TopicRecord`)
- **roboto_client** (`Optional[roboto.http.RobotoClient]`)
- **topic_data_service** (`Optional[roboto.domain.topics.topic_data_service.TopicDataService]`)

**Properties**

- **Topic.association** (`roboto.association.Association`): Resource the topic belongs to, usually the file its data came from.

- **Topic.created** (`datetime.datetime`): Time the topic was created.

- **Topic.created_by** (`str`): ID of the user who created the topic.

- **Topic.dataset_id** (`str | None`): ID of the dataset the topic or its file belongs to, or `None` if the topic belongs to neither.

  When the topic belongs to a file, each access makes a request to Roboto for the file's record.

  Return type: `Optional[str]`

- **Topic.default_representation** (`roboto.domain.topics.record.RepresentationRecord | None`): Record of the representation that holds the data of each message path without one of its own.

  `None` if the topic has no default representation, in which case only message paths with representations of their own can be read.

  Return type: `Optional[roboto.domain.topics.record.RepresentationRecord]`

- **Topic.end_time** (`int | None`): Timestamp of the topic's latest message, in nanoseconds since the Unix epoch, or `None` if unknown.

  Return type: `Optional[int]`

- **Topic.file_id** (`str | None`): ID of the file the topic belongs to, or `None` if the topic belongs to something other than a file.

  Return type: `Optional[str]`

- **Topic.message_count** (`int | None`): Number of messages in the topic, or `None` if unknown.

  Return type: `Optional[int]`

- **Topic.message_paths** (`collections.abc.Sequence[roboto.domain.topics.record.MessagePathRecord]`): Message paths of the topic.

  Empty for a topic listed by `get_by_dataset`, which leaves them out.

- **Topic.metadata** (`dict[str, Any]`): Key-value metadata on the topic.

  Each access returns a copy, so changing it does not change the topic.

- **Topic.modified** (`datetime.datetime`): Time the topic was last modified.

- **Topic.modified_by** (`str`): ID of the user who last modified the topic.

- **Topic.name** (`str`): Name of the topic, such as `"/imu/data"`.

  Unique within its file. Same as `topic_name`.

- **Topic.org_id** (`str`): ID of the organization that owns the topic.

- **Topic.record** (`roboto.domain.topics.record.TopicRecord`): Record of the topic that this instance holds.

  Each of its fields is also a property of `Topic`. `refresh` replaces it with the current one.

- **Topic.schema_checksum** (`str | None`): Checksum of the topic's schema, or `None` if the topic has no known schema.

  Return type: `Optional[str]`

- **Topic.schema_id** (`str | None`): ID of the topic's schema, or `None` if the topic has no schema or Roboto has not yet recorded it.

  Return type: `Optional[str]`

- **Topic.schema_name** (`str | None`): Name of the topic's message type, such as `"sensor_msgs/PointCloud2"`, or `None` if it is unknown.

  Return type: `Optional[str]`

- **Topic.start_time** (`int | None`): Timestamp of the topic's earliest message, in nanoseconds since the Unix epoch, or `None` if unknown.

  Return type: `Optional[int]`

- **Topic.topic_id** (`str`): Unique ID of the topic, beginning with `tp_`.

- **Topic.topic_name** (`str`): Name of the topic, such as `"/imu/data"`.

  Unique within its file.

#### Topic.add_message_path()

```python
def add_message_path(
    message_path: str,
    data_type: str,
    canonical_data_type: roboto.domain.topics.record.CanonicalDataType,
    path_in_schema: Optional[list[str]] = None,
    metadata: Optional[dict[str, Any]] = None,
) -> roboto.domain.topics.record.MessagePathRecord
```

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

Add a message path to the topic.

Fetches the topic's record afterwards, so `message_paths` includes the new message path.

**Parameters**

- **message_path** (`str`): Dot-delimited path to a field within the topic's messages, such as `"pose.position.x"`. Unique within the topic.
- **data_type** (`str`): Native data type of the field, as the source data's framework names it, such as `"float32"`, `"uint8[]"` or `"geometry_msgs/Pose"`.
- **canonical_data_type** (`roboto.domain.topics.record.CanonicalDataType`): Framework-independent data type of the field, which Roboto uses to choose how to display its data, such as on a map or as an image.
- **path_in_schema** (`Optional[list[str]]`): Components of the field's path in the source data's schema, in order from the schema root. Unlike `message_path`, it keeps a field name that contains a dot as one component. `None` splits `message_path` at each dot.
- **metadata** (`Optional[dict[str, Any]]`): Key-value metadata to set on the message path. `None` sets none.

**Returns**

- `roboto.domain.topics.record.MessagePathRecord`: Record of the new message path.

**Raises**

- [`RobotoConflictException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoConflictException): The topic already has a message path at `message_path`.

**Usage**

```python
from roboto.domain.topics import CanonicalDataType
topic = Topic.from_id("tp_12345")
message_path = topic.add_message_path(
    message_path="pose.position.x",
    data_type="float64",
    canonical_data_type=CanonicalDataType.Number,
    metadata={"frame": "map"},
)
print(message_path.message_path)
# pose.position.x
```

#### Topic.add_message_path_representation()

```python
def add_message_path_representation(
    message_path_id: str,
    association: roboto.association.Association,
    storage_format: roboto.domain.topics.record.RepresentationStorageFormat,
    version: int,
    format: Optional[str] = None,
    transformations: Optional[list[str]] = None,
) -> roboto.domain.topics.record.RepresentationRecord
```

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

Register a representation of one of the topic's message paths.

A representation is a stored copy of the data, in one file format and possibly transformed, such as encoded as JPEG. Within the topic, `association`, `storage_format` and `version` together identify a representation, so registering a combination the topic already has updates that representation's `format` and `transformations` instead of adding another. Fetches the topic's record afterwards.

**Parameters**

- **message_path_id** (`str`): ID of the message path the representation holds data for, beginning with `mp_`.
- **association** (`roboto.association.Association`): File, or other entity, that holds the representation's data. It must exist.
- **storage_format** (`roboto.domain.topics.record.RepresentationStorageFormat`): File format the representation's data is stored in.
- **version** (`int`): Version number of the representation.
- **format** (`Optional[str]`): Content format of the data, such as an image encoding (`"jpeg"`) or a message schema name (`"sensor_msgs/Image"`). `None` keeps the stored format when the representation already exists.
- **transformations** (`Optional[list[str]]`): Transformations applied to produce the representation, in order, as `"<kind>:<param>"` strings such as `"downsample:0.5"` (see [`TransformationKind`](/docs/reference/python-sdk/roboto/domain/topics/record#roboto.domain.topics.record.TransformationKind)). `None` keeps the stored list when the representation already exists, and records none otherwise.

**Returns**

- `roboto.domain.topics.record.RepresentationRecord`: Record of the registered representation.

**Raises**

- [`RobotoNotFoundException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoNotFoundException): The topic has no message path with ID `message_path_id`.

**Usage**

```python
from roboto.association import Association
from roboto.domain.topics import RepresentationStorageFormat
topic = Topic.from_id("tp_12345")
representation = topic.add_message_path_representation(
    message_path_id="mp_12345",
    association=Association.file("fl_12345"),
    storage_format=RepresentationStorageFormat.MCAP,
    version=1,
)
```

#### Topic.create()

```python
@classmethod
def create(
    file_id: str,
    topic_name: str,
    end_time: Optional[int] = None,
    message_count: Optional[int] = None,
    metadata: Optional[collections.abc.Mapping[str, Any]] = None,
    schema_checksum: Optional[str] = None,
    schema_name: Optional[str] = None,
    start_time: Optional[int] = None,
    message_paths: Optional[collections.abc.Sequence[roboto.domain.topics.operations.AddMessagePathRequest]] = None,
    caller_org_id: Optional[str] = None,
    roboto_client: Optional[roboto.http.RobotoClient] = None,
) -> Topic
```

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

Create a topic in a file.

Ingestion actions usually create topics. A new topic describes its data but holds none: it cannot be read with `get_data` or visualized until a representation of its data is registered, with `set_default_representation` or `add_message_path_representation`. To create a topic and store its data from a pandas DataFrame in one call, use [`add_topic()`](/docs/reference/python-sdk/roboto/domain/files/file#roboto.domain.files.file.File.add_topic).

**Parameters**

- **file_id** (`str`): ID of the file the topic belongs to.
- **topic_name** (`str`): Name of the topic, such as `"/imu/data"`. Unique within the file.
- **end_time** (`Optional[int]`): End of the topic's data, in nanoseconds since the Unix epoch. Must not be negative.
- **message_count** (`Optional[int]`): Number of messages in the topic. Must not be negative.
- **metadata** (`Optional[collections.abc.Mapping[str, Any]]`): Key-value metadata to set on the topic. `None` sets none.
- **schema_checksum** (`Optional[str]`): Checksum of the topic's message schema.
- **schema_name** (`Optional[str]`): Name of the topic's message schema, such as `"sensor_msgs/Imu"`.
- **start_time** (`Optional[int]`): Start of the topic's data, in nanoseconds since the Unix epoch. Must not be negative.
- **message_paths** (`Optional[collections.abc.Sequence[roboto.domain.topics.operations.AddMessagePathRequest]]`): Message paths to create with the topic. No two may have the same `message_path`. `None` creates none.
- **caller_org_id** (`Optional[str]`): Organization to create the topic in. Required when the caller belongs to more than one organization; otherwise the caller's only organization.
- **roboto_client** (`Optional[roboto.http.RobotoClient]`): Client to make requests to Roboto with. Defaults to one configured from the environment, by [`from_env()`](/docs/reference/python-sdk/roboto/http/roboto_client#roboto.http.roboto_client.RobotoClient.from_env).

**Returns**

- `Topic`: The new topic.

**Raises**

- [`RobotoConflictException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoConflictException): The file already has a topic named `topic_name`.
- [`RobotoInvalidRequestException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoInvalidRequestException): `topic_name` is blank, a time or `message_count` is negative, or two of `message_paths` have the same `message_path`.

**Usage**

Create a topic for camera data:

```python
topic = Topic.create(
    file_id="fl_12345",
    topic_name="/camera/image",
    schema_name="sensor_msgs/Image",
    start_time=1722870127699468923,
    end_time=1722870127799468923,
    message_count=100,
)
```

Create a topic with metadata and message paths:

```python
from roboto.domain.topics import AddMessagePathRequest, CanonicalDataType
message_paths = [
    AddMessagePathRequest(
        message_path="header.stamp.sec",
        data_type="uint32",
        canonical_data_type=CanonicalDataType.Timestamp,
        path_in_schema=["header", "stamp", "sec"],
        metadata={"unit": "s"},
    )
]
topic = Topic.create(
    file_id="fl_12345",
    topic_name="/imu/data",
    schema_name="sensor_msgs/Imu",
    metadata={"sensor_type": "IMU", "frequency": 100},
    message_paths=message_paths,
)
```

#### Topic.create_from_df()

```python
@classmethod
def create_from_df(
    file_id: str,
    dataset_id: str,
    topic_name: str,
    df: pandas.DataFrame,
    timestamp_column: Optional[str] = None,
    timestamp_unit: Optional[Union[str, roboto.time.TimeUnit]] = None,
    caller_org_id: Optional[str] = None,
    roboto_client: Optional[roboto.http.RobotoClient] = None,
) -> Topic
```

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

Create a topic in a file from a pandas DataFrame, or replace the data of the file's topic of that name.

[`add_topic()`](/docs/reference/python-sdk/roboto/domain/files/file#roboto.domain.files.file.File.add_topic) does the same and needs only the file. Each row of `df` is one message. The method:

1. Writes `df` to a Parquet file.
2. Creates the topic, with message paths, a message count, and a time range read from that file. When the file already has a topic named `topic_name`, it replaces that topic's message paths, message count, time range, and schema name instead.
3. Uploads the Parquet file to the dataset's `.VISUALIZATION_ASSETS` directory and makes it the topic's default representation, so the data can be read and visualized.

If the upload fails, the topic keeps the message paths from step 2 without the data to match them.

**Parameters**

- **file_id** (`str`): ID of the file the topic belongs to.
- **dataset_id** (`str`): ID of the dataset that contains the file. The Parquet file is uploaded to it.
- **topic_name** (`str`): Name of the topic, unique within the file. Also set as the topic's schema name.
- **df** (`pandas.DataFrame`): Data of the topic, one row per message. It must have a timestamp column, named by `timestamp_column` or found automatically.
- **timestamp_column** (`Optional[str]`): Name of the column that holds each message's timestamp. `None` uses the first column of a timezone-aware timestamp type.
- **timestamp_unit** (`Optional[Union[str, roboto.time.TimeUnit]]`): Unit of the timestamp column's values: `"s"`, `"ms"`, `"us"` or `"ns"`, or a [`TimeUnit`](/docs/reference/python-sdk/roboto/time#roboto.time.TimeUnit). Required when the column is numeric. A timestamp-typed column carries its own unit, which this overrides.
- **caller_org_id** (`Optional[str]`): Organization to create the topic in. Required when the caller belongs to more than one organization; otherwise the caller's only organization.
- **roboto_client** (`Optional[roboto.http.RobotoClient]`): Client to make requests to Roboto with. Defaults to one configured from the environment, by [`from_env()`](/docs/reference/python-sdk/roboto/http/roboto_client#roboto.http.roboto_client.RobotoClient.from_env).

**Returns**

- `Topic`: The created or updated topic.

**Raises**

- [`IngestionException`](/docs/reference/python-sdk/roboto/exceptions/ingestion#roboto.exceptions.ingestion.IngestionException): The timestamp column is not in `df`, cannot be found automatically, is neither numeric nor a timezone-aware timestamp type, or is numeric with no `timestamp_unit`; or the upload finished without Roboto returning an ID for the Parquet file.
- `ImportError`: The `roboto[ingestion]` extra is not installed.

**Usage**

Create a topic from a DataFrame with a timestamp column in seconds:

```python
import pandas as pd
from roboto.domain.topics import Topic
df = pd.DataFrame(
    {
        "timestamp": [1763947309.4198897, 1763947316.7686195, 1763947335.0095527],
        "temperature": [20.5, 21.0, 20.8],
        "humidity": [45.2, 46.1, 45.8],
    }
)
topic = Topic.create_from_df(
    file_id="fl_12345",
    dataset_id="ds_12345",
    topic_name="sensor_data",
    df=df,
    timestamp_column="timestamp",
    timestamp_unit="s",
)
print(f"Created topic: {topic.name}")
# Created topic: sensor_data
```

Do the same with [`add_topic()`](/docs/reference/python-sdk/roboto/domain/files/file#roboto.domain.files.file.File.add_topic), which finds the dataset itself:

```python
from roboto import File
file = File.from_id("fl_12345")
topic = file.add_topic("sensor_data", df, timestamp_column="timestamp", timestamp_unit="s")
```

#### Topic.delete()

```python
def delete() -> None
```

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

Delete the topic. This cannot be undone.

Also deletes the topic's message paths and representations, the MCAP files that hold its representations, and each event linked to nothing but this topic and its message paths. Deleting a topic that no longer exists succeeds and changes nothing.

**Usage**

```python
topic = Topic.from_id("tp_12345")
topic.delete()
```

**Returns**

- `None`

#### Topic.from_id()

```python
@classmethod
def from_id(
    topic_id: str,
    roboto_client: Optional[roboto.http.RobotoClient] = None,
) -> Topic
```

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

Fetch a topic by its ID.

**Parameters**

- **topic_id** (`str`): Unique ID of the topic, beginning with `tp_`.
- **roboto_client** (`Optional[roboto.http.RobotoClient]`): Client to make requests to Roboto with. Defaults to one configured from the environment, by [`from_env()`](/docs/reference/python-sdk/roboto/http/roboto_client#roboto.http.roboto_client.RobotoClient.from_env).

**Raises**

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

**Returns**

- `Topic`

**Usage**

```python
topic = Topic.from_id("tp_12345")
print(topic.name, topic.message_count)
```

#### Topic.from_name_and_file()

```python
@classmethod
def from_name_and_file(
    topic_name: str,
    file_id: str,
    owner_org_id: Optional[str] = None,
    roboto_client: Optional[roboto.http.RobotoClient] = None,
) -> Topic
```

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

Fetch a topic by its name and the file it belongs to.

Topic names are unique within a file, so a name and a file identify one topic.

**Parameters**

- **topic_name** (`str`): Name of the topic, such as `"/camera/image"`.
- **file_id** (`str`): ID of the file the topic belongs to.
- **owner_org_id** (`Optional[str]`): Organization that owns the file. Defaults to the organization the caller acts in.
- **roboto_client** (`Optional[roboto.http.RobotoClient]`): Client to make requests to Roboto with. Defaults to one configured from the environment, by [`from_env()`](/docs/reference/python-sdk/roboto/http/roboto_client#roboto.http.roboto_client.RobotoClient.from_env).

**Raises**

- [`RobotoNotFoundException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoNotFoundException): The file has no topic with this name.

**Returns**

- `Topic`

**Usage**

```python
topic = Topic.from_name_and_file(topic_name="/camera/image", file_id="fl_12345")
print(topic.topic_id)
```

#### Topic.get_by_dataset()

```python
@classmethod
def get_by_dataset(
    dataset_id: str,
    roboto_client: Optional[roboto.http.RobotoClient] = None,
) -> collections.abc.Generator[Topic, None, None]
```

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

List the topics of a dataset's files.

When several files have a topic with the same name, such as files split from one recording, each file's topic is yielded separately.

> **Note**
>
> The topics come without message paths: each topic's `message_paths` is empty. To get them, use `get_by_file` on each file instead.

**Parameters**

- **dataset_id** (`str`): ID of the dataset.
- **roboto_client** (`Optional[roboto.http.RobotoClient]`): Client to make requests to Roboto with. Defaults to one configured from the environment, by [`from_env()`](/docs/reference/python-sdk/roboto/http/roboto_client#roboto.http.roboto_client.RobotoClient.from_env).

**Yields**

- Each topic of the dataset's files.

**Raises**

- [`RobotoNotFoundException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoNotFoundException): No dataset has this ID. It surfaces on the first iteration.

**Returns**

- `collections.abc.Generator[Topic, None, None]`

**Usage**

Print each topic with the file it belongs to:

```python
for topic in Topic.get_by_dataset("ds_12345"):
    print(topic.name, topic.file_id)
```

Count the files that have each topic name:

```python
from collections import Counter
topic_name_counts = Counter(topic.name for topic in Topic.get_by_dataset("ds_12345"))
```

#### Topic.get_by_file()

```python
@classmethod
def get_by_file(
    file_id: str,
    owner_org_id: Optional[str] = None,
    roboto_client: Optional[roboto.http.RobotoClient] = None,
) -> collections.abc.Generator[Topic, None, None]
```

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

List the topics of a file.

**Parameters**

- **file_id** (`str`): ID of the file.
- **owner_org_id** (`Optional[str]`): Organization that owns the file. Defaults to the organization the caller acts in.
- **roboto_client** (`Optional[roboto.http.RobotoClient]`): Client to make requests to Roboto with. Defaults to one configured from the environment, by [`from_env()`](/docs/reference/python-sdk/roboto/http/roboto_client#roboto.http.roboto_client.RobotoClient.from_env).

**Yields**

- Each topic of the file, with its message paths.

**Returns**

- `collections.abc.Generator[Topic, None, None]`

**Usage**

Print each topic's name and message count:

```python
for topic in Topic.get_by_file("fl_12345"):
    print(topic.name, topic.message_count)
```

Keep only the topics whose names contain `"camera"`:

```python
camera_topics = [topic for topic in Topic.get_by_file("fl_12345") if "camera" in topic.name]
```

#### Topic.get_data()

```python
def get_data(
    message_paths_include: Optional[collections.abc.Iterable[str]] = None,
    message_paths_exclude: Optional[collections.abc.Iterable[str]] = None,
    start_time: Optional[roboto.time.Time] = None,
    end_time: Optional[roboto.time.Time] = None,
    cache_dir: Union[str, pathlib.Path, None] = None,
    representation_selector: roboto.domain.topics.record.RepresentationSelector = RepresentationSelector.raw(),
) -> 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/topic.py#L871-L946)

Yield this topic's messages, optionally limited to some message paths and a time range.

Each yielded item is a `(timestamp, message)` tuple, where `message` is a dictionary that follows the topic's schema.

**Parameters**

- **message_paths_include** (`Optional[collections.abc.Iterable[str]]`): Message paths to include. `None` includes every message path.
- **message_paths_exclude** (`Optional[collections.abc.Iterable[str]]`): Message paths to leave out. `None` leaves out none.
- **start_time** (`Optional[roboto.time.Time]`): Inclusive start of the time range, in nanoseconds since the Unix epoch or any value [`to_epoch_nanoseconds()`](/docs/reference/python-sdk/roboto/time#roboto.time.to_epoch_nanoseconds) accepts.
- **end_time** (`Optional[roboto.time.Time]`): Exclusive end of the time range, in the same form.
- **cache_dir** (`Union[str, pathlib.Path, None]`): Directory to download the topic's data to. `None` uses [`DEFAULT_CACHE_DIR`](/docs/reference/python-sdk/roboto/domain/topics/topic_data_service#roboto.domain.topics.topic_data_service.TopicDataService.DEFAULT_CACHE_DIR).
- **representation_selector** (`roboto.domain.topics.record.RepresentationSelector`): Which of the topic's stored representations to read. Defaults to the raw, untransformed data. A message path with no representation that meets it is left out.

**Yields**

- `(timestamp, message)` tuples, limited by the arguments.

**Returns**

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

**Usage**

Print every message:

```python
topic = Topic.from_name_and_file(topic_name="/imu/data", file_id="fl_12345")
for timestamp, message in topic.get_data():
    print(timestamp, message)
```

Include `angular_velocity` but leave out its `y` axis:

```python
for timestamp, message in topic.get_data(
    message_paths_include=["angular_velocity"],
    message_paths_exclude=["angular_velocity.y"],
):
    print(message)
```

Read only the messages in a time range:

```python
for timestamp, message in topic.get_data(
    start_time=1722870127699468923,
    end_time=1722870127799468923,
):
    print(timestamp)
```

Read the JPEG-encoded representation of an image topic:

```python
from roboto.domain.topics import RepresentationSelector
image_topic = Topic.from_name_and_file(topic_name="/camera/image", file_id="fl_12345")
for timestamp, message in image_topic.get_data(
    representation_selector=RepresentationSelector(content_format="jpeg"),
):
    print(timestamp)
```

Read many topics in parallel with a thread pool:

```python
from concurrent.futures import ThreadPoolExecutor
topics = list(Topic.get_by_file("fl_12345"))
with ThreadPoolExecutor(max_workers=16) as executor:
    messages_by_topic = list(executor.map(lambda t: list(t.get_data()), topics))
```

#### Topic.get_data_as_df()

```python
def get_data_as_df(
    message_paths_include: Optional[collections.abc.Iterable[str]] = None,
    message_paths_exclude: Optional[collections.abc.Iterable[str]] = None,
    start_time: Optional[roboto.time.Time] = None,
    end_time: Optional[roboto.time.Time] = None,
    cache_dir: Union[str, pathlib.Path, None] = None,
    representation_selector: roboto.domain.topics.record.RepresentationSelector = RepresentationSelector.raw(),
) -> pandas.DataFrame
```

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

Fetch this topic's messages as a pandas DataFrame, optionally limited to some message paths and a time range.

Each row is one message. Nested fields become columns with dot-delimited names, such as `angular_velocity.x`. The index, named `_index`, is a UTC `pandas.DatetimeIndex` of each message's timestamp.

**Parameters**

- **message_paths_include** (`Optional[collections.abc.Iterable[str]]`): Message paths to include. `None` includes every message path.
- **message_paths_exclude** (`Optional[collections.abc.Iterable[str]]`): Message paths to leave out. `None` leaves out none.
- **start_time** (`Optional[roboto.time.Time]`): Inclusive start of the time range, in nanoseconds since the Unix epoch or any value [`to_epoch_nanoseconds()`](/docs/reference/python-sdk/roboto/time#roboto.time.to_epoch_nanoseconds) accepts.
- **end_time** (`Optional[roboto.time.Time]`): Exclusive end of the time range, in the same form.
- **cache_dir** (`Union[str, pathlib.Path, None]`): Directory to download the topic's data to. `None` uses [`DEFAULT_CACHE_DIR`](/docs/reference/python-sdk/roboto/domain/topics/topic_data_service#roboto.domain.topics.topic_data_service.TopicDataService.DEFAULT_CACHE_DIR).
- **representation_selector** (`roboto.domain.topics.record.RepresentationSelector`): Which of the topic's stored representations to read. Defaults to the raw, untransformed data. A message path with no representation that meets it is left out.

**Raises**

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

**Returns**

- `pandas.DataFrame`

> **Note**
>
> An array-typed message path, such as a `float32[3]` acceleration, becomes one column whose values are lists. Its elements are not message paths, so neither a column nor `message_paths_include` or `message_paths_exclude` can name one. Select the array's path and unpack the column, as in the last example. `numpy.stack` needs every row to have the same length, so process a variable-length array, such as a point cloud, row by row, for example with `df[column].map(...)`.

**Usage**

Read every message:

```python
topic = Topic.from_name_and_file(topic_name="/imu/data", file_id="fl_12345")
df = topic.get_data_as_df()
print(df.head())
```

Include `angular_velocity` but leave out its `z` axis:

```python
df_filtered = topic.get_data_as_df(
    message_paths_include=["angular_velocity"],
    message_paths_exclude=["angular_velocity.z"],
)
```

Unpack a fixed-length array message path, a column of lists, into a numpy array of shape `(N, 3)`:

```python
import numpy as np
df_accel = topic.get_data_as_df(message_paths_include=["acceleration"])
xyz = np.stack(df_accel["acceleration"].to_numpy())
```

Read many topics in parallel with a thread pool, then combine them in time order:

```python
import pandas as pd
from concurrent.futures import ThreadPoolExecutor
topics = list(Topic.get_by_file("fl_12345"))
with ThreadPoolExecutor(max_workers=16) as executor:
    dfs = list(executor.map(lambda t: t.get_data_as_df(), topics))
combined = pd.concat(dfs).sort_index()
```

#### Topic.get_message_path()

```python
def get_message_path(message_path: str) -> roboto.domain.topics.message_path.MessagePath
```

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

Return the topic's message path at `message_path`.

Looks the path up in this instance's record, without a request to Roboto.

**Parameters**

- **message_path** (`str`): Dot-delimited path to a field within the topic's messages, such as `"pose.position.x"`.

**Returns**

- `roboto.domain.topics.message_path.MessagePath`: The [`MessagePath`](/docs/reference/python-sdk/roboto/domain/topics/message_path#roboto.domain.topics.message_path.MessagePath), which reads that field's data and statistics.

**Raises**

- `ValueError`: The topic has no message path at `message_path`, or this instance's record has no message paths, as for a topic listed by `get_by_dataset`.

**Usage**

```python
topic = Topic.from_name_and_file(topic_name="/imu/data", file_id="fl_12345")
angular_velocity_x = topic.get_message_path("angular_velocity.x")
print(angular_velocity_x.mean, angular_velocity_x.stddev)
```

#### Topic.get_schema()

```python
def get_schema() -> Optional[roboto.domain.topics.topic_schema.TopicSchema]
```

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

Fetch the topic's schema, or return `None` if the topic has no schema.

**Returns**

- `Optional[roboto.domain.topics.topic_schema.TopicSchema]`: The `TopicSchema` that the topic's messages follow, or `None` when `schema_id` is `None`.

**Raises**

- [`RobotoNotFoundException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoNotFoundException): `schema_id` names a schema that no longer exists.

**Usage**

```python
topic = Topic.from_id("tp_12345")
schema = topic.get_schema()
if schema is not None:
    for field in schema.fields:
        print(field.name, field.data_type)
```

#### Topic.get_time_bounds_by_association()

```python
@classmethod
def get_time_bounds_by_association(
    association: roboto.association.Association,
    owner_org_id: Optional[str] = None,
    roboto_client: Optional[roboto.http.RobotoClient] = None,
) -> roboto.domain.topics.record.TopicTimeBounds
```

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

Fetch the earliest start time and latest end time across the topics of a file or other entity.

For a file, returns the same values as taking the minimum `start_time` and maximum `end_time` over `get_by_file`, in one request instead of one per page of topics.

> **Note**
>
> Only topics that belong to `association` itself count. Topics usually belong to files, so a dataset association leaves out the topics of the dataset's files; for those, use [`get_topic_time_bounds()`](/docs/reference/python-sdk/roboto/domain/datasets/dataset#roboto.domain.datasets.dataset.Dataset.get_topic_time_bounds).

**Parameters**

- **association** (`roboto.association.Association`): Entity whose topics to cover, such as `Association.file("fl_12345")`.
- **owner_org_id** (`Optional[str]`): Organization that owns the entity. Defaults to the organization the caller acts in.
- **roboto_client** (`Optional[roboto.http.RobotoClient]`): Client to make requests to Roboto with. Defaults to one configured from the environment, by [`from_env()`](/docs/reference/python-sdk/roboto/http/roboto_client#roboto.http.roboto_client.RobotoClient.from_env).

**Returns**

- `roboto.domain.topics.record.TopicTimeBounds`: Bounds in nanoseconds since the Unix epoch. Both are `None` when the entity has no topics, and either is `None` when no topic has that bound.

**Usage**

```python
from roboto.association import Association
bounds = Topic.get_time_bounds_by_association(Association.file("fl_12345"))
print(bounds.start_time, bounds.end_time)
```

#### Topic.refresh()

```python
def refresh() -> None
```

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

Replace this instance's record with the topic's current record from Roboto.

Use it to see changes that other users or processes made after this instance was loaded.

**Raises**

- [`RobotoNotFoundException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoNotFoundException): The topic no longer exists.

**Returns**

- `None`

**Usage**

```python
topic = Topic.from_id("tp_12345")
topic.refresh()
print(topic.message_count)
```

#### Topic.set_default_representation()

```python
def set_default_representation(
    association: roboto.association.Association,
    storage_format: roboto.domain.topics.record.RepresentationStorageFormat,
    version: int,
    format: Optional[str] = None,
    transformations: Optional[list[str]] = None,
) -> roboto.domain.topics.record.RepresentationRecord
```

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

Register a representation of the topic's data and make it the topic's default.

Roboto reads the default representation for every message path that has no representation of its own, so registering one is what makes a new topic's data readable; ingestion actions do it after uploading the data. The topic's other representations stay registered and stop being the default. Within the topic, `association`, `storage_format` and `version` together identify a representation, so registering a combination the topic already has updates that representation instead of adding another. Fetches the topic's record afterwards, so `default_representation` is the new default.

**Parameters**

- **association** (`roboto.association.Association`): File, or other entity, that holds the representation's data. It must exist.
- **storage_format** (`roboto.domain.topics.record.RepresentationStorageFormat`): File format the representation's data is stored in.
- **version** (`int`): Version number of the representation.
- **format** (`Optional[str]`): Content format of the data, such as an image encoding (`"jpeg"`) or a message schema name (`"sensor_msgs/Image"`). `None` keeps the stored format when the representation already exists.
- **transformations** (`Optional[list[str]]`): Transformations applied to produce the representation, in order, as `"<kind>:<param>"` strings such as `"downsample:0.5"` (see [`TransformationKind`](/docs/reference/python-sdk/roboto/domain/topics/record#roboto.domain.topics.record.TransformationKind)). `None` keeps the stored list when the representation already exists, and records none otherwise.

**Returns**

- `roboto.domain.topics.record.RepresentationRecord`: Record of the registered representation.

**Usage**

```python
from roboto.association import Association
from roboto.domain.topics import RepresentationStorageFormat
topic = Topic.from_id("tp_12345")
representation = topic.set_default_representation(
    association=Association.file("fl_12345"),
    storage_format=RepresentationStorageFormat.MCAP,
    version=2,
)
```

#### Topic.to_association()

```python
def to_association() -> roboto.association.Association
```

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

Return an association that refers to this topic, such as to link an event to it.

**Usage**

```python
topic = Topic.from_id("tp_12345")
association = topic.to_association()
print(association.association_type)
# AssociationType.Topic
print(association.association_id)
# tp_12345
```

**Returns**

- `roboto.association.Association`

#### Topic.update()

```python
def update(
    end_time: Union[Optional[int], roboto.sentinels.NotSetType] = NotSet,
    message_count: Union[int, roboto.sentinels.NotSetType] = NotSet,
    schema_checksum: Union[Optional[str], roboto.sentinels.NotSetType] = NotSet,
    schema_name: Union[Optional[str], roboto.sentinels.NotSetType] = NotSet,
    start_time: Union[Optional[int], roboto.sentinels.NotSetType] = NotSet,
    metadata_changeset: Union[roboto.updates.MetadataChangeset, roboto.sentinels.NotSetType] = NotSet,
    message_path_changeset: Union[roboto.domain.topics.operations.MessagePathChangeset, roboto.sentinels.NotSetType] = NotSet,
) -> Topic
```

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

Update the topic's properties and, optionally, its message paths.

An argument left unset (`NotSet`) leaves that property unchanged. Roboto applies the whole update, or none of it if any part is refused.

**Parameters**

- **end_time** (`Union[Optional[int], roboto.sentinels.NotSetType]`): End of the topic's data, in nanoseconds since the Unix epoch. Must not be negative, and must not be before `start_time` when this call sets both. `None` clears it.
- **message_count** (`Union[int, roboto.sentinels.NotSetType]`): Number of messages in the topic. Must not be negative.
- **schema_checksum** (`Union[Optional[str], roboto.sentinels.NotSetType]`): Checksum of the topic's message schema. Setting it requires a schema name, already on the topic or set by this call. `None` clears it.
- **schema_name** (`Union[Optional[str], roboto.sentinels.NotSetType]`): Name of the topic's message schema, such as `"sensor_msgs/Imu"`. `None` clears it; when the topic has a schema checksum, this call must clear that too.
- **start_time** (`Union[Optional[int], roboto.sentinels.NotSetType]`): Start of the topic's data, in nanoseconds since the Unix epoch. Must not be negative. `None` clears it.
- **metadata_changeset** (`Union[roboto.updates.MetadataChangeset, roboto.sentinels.NotSetType]`): Changes to the topic's metadata. Topics have no tags, so the changeset's tag changes have no effect.
- **message_path_changeset** (`Union[roboto.domain.topics.operations.MessagePathChangeset, roboto.sentinels.NotSetType]`): Message paths to add, update, and delete. Updating or deleting a message path the topic does not have is skipped.

**Returns**

- `Topic`: This instance, with its record updated. When `message_path_changeset` has changes, the method fetches the topic's record afterwards, so `message_paths` shows them.

**Raises**

- [`RobotoInvalidRequestException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoInvalidRequestException): An argument has a value Roboto rejects, such as a negative `message_count`.
- [`RobotoConflictException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoConflictException): `message_path_changeset` adds a message path the topic already has, and its `replace_all` is not set.

**Usage**

Set the message count and a metadata field:

```python
from roboto.updates import MetadataChangeset
topic = Topic.from_id("tp_12345")
topic.update(
    message_count=1500,
    metadata_changeset=MetadataChangeset(put_fields={"sensor": "imu"}),
)
```

Clear the schema name and checksum:

```python
topic.update(schema_name=None, schema_checksum=None)
```

#### Topic.update_message_path()

```python
def update_message_path(
    message_path: str,
    metadata_changeset: Union[roboto.updates.TaglessMetadataChangeset, roboto.sentinels.NotSetType] = NotSet,
    data_type: Union[str, roboto.sentinels.NotSetType] = NotSet,
    canonical_data_type: Union[roboto.domain.topics.record.CanonicalDataType, roboto.sentinels.NotSetType] = NotSet,
    path_in_schema: Union[list[str], roboto.sentinels.NotSetType] = NotSet,
) -> roboto.domain.topics.message_path.MessagePath
```

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

Update one of the topic's message paths.

An argument left unset (`NotSet`) leaves that property of the message path unchanged. Fetches the topic's record afterwards, so `message_paths` shows the change.

**Parameters**

- **message_path** (`str`): Dot-delimited path of the message path to update, such as `"pose.position.x"`.
- **metadata_changeset** (`Union[roboto.updates.TaglessMetadataChangeset, roboto.sentinels.NotSetType]`): Changes to the message path's metadata.
- **data_type** (`Union[str, roboto.sentinels.NotSetType]`): Native data type of the field, as the source data's framework names it, such as `"float32"`.
- **canonical_data_type** (`Union[roboto.domain.topics.record.CanonicalDataType, roboto.sentinels.NotSetType]`): Framework-independent data type of the field. Changing it changes how Roboto displays the field's data.
- **path_in_schema** (`Union[list[str], roboto.sentinels.NotSetType]`): Components of the field's path in the source data's schema, in order from the schema root.

**Returns**

- `roboto.domain.topics.message_path.MessagePath`: The updated message path.

**Raises**

- [`RobotoNotFoundException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoNotFoundException): The topic has no message path at `message_path`.

**Usage**

Set a metadata field on a message path:

```python
from roboto.updates import TaglessMetadataChangeset
topic = Topic.from_id("tp_12345")
changeset = TaglessMetadataChangeset(put_fields={"frame": "map"})
updated_path = topic.update_message_path(message_path="pose.position.x", metadata_changeset=changeset)
print(updated_path.metadata["frame"])
# map
```

Change a message path's data types:

```python
from roboto.domain.topics import CanonicalDataType
updated_path = topic.update_message_path(
    message_path="velocity", data_type="float64", canonical_data_type=CanonicalDataType.Number
)
```

### logger

```python
roboto.domain.topics.topic.logger
```

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

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