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

### MessagePath

```python
class roboto.domain.topics.message_path.MessagePath(
    record: roboto.domain.topics.record.MessagePathRecord,
    roboto_client: Optional[roboto.http.RobotoClient] = None,
    topic_data_service: Optional[roboto.domain.topics.topic_data_service.TopicDataService] = None,
)
```

`from roboto import MessagePath`

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

A message path: one field or signal of a topic's messages, such as `"pose.position.x"`.

Each instance holds a copy of the message path's record: the field's native and canonical data types, its key-value metadata, and the statistics Roboto's ingestion actions computed for it, which the `min`, `max`, `mean` and similar properties read. A statistic that was not computed reads `None`, not zero. `get_data` and `get_data_as_df` read the field's values from the topic's messages.

Get a `MessagePath` from [`get_message_path()`](/docs/reference/python-sdk/roboto/domain/topics/topic#roboto.domain.topics.topic.Topic.get_message_path) or `from_id`.

**Parameters**

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

**Attributes**

- **MessagePath.DELIMITER** (`ClassVar`) = `'.'`: Separator between the components of a message path.

**Properties**

- **MessagePath.array_length** (`int | None`): Fixed length of the array that `data_type` declares with a trailing `[N]`, or `None`.

  `float64[7]`, `float[4]` and `fixed_size_list<element: double>[3]` read 7, 4 and 3. `None` for a variable-length array (`float64[]`, `list<element: double>`), a ROS 2 bounded one (`float64[<=10]`), a multi-dimensional one (`float64[2][3]`, `fixed_size_list<element: list<element: double>>[3]`) and a scalar, so `None` means the length is unknown, not that the path is not an array. The element type does not matter: `string[8]` reads 8 and `Point[3]` reads 3. Only `data_type` is read; an `array_length` key in `metadata` is not consulted.

  Return type: `Optional[int]`

- **MessagePath.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.

- **MessagePath.count** (`PreComputedStat`): Number of values the message path has, or `None` if it was not computed.

- **MessagePath.created** (`datetime.datetime`): Time the message path was created.

- **MessagePath.created_by** (`str`): ID of the user who created the message path.

- **MessagePath.data_type** (`str`): Native data type of the field, as the source data's framework names it.

  [`data_type`](/docs/reference/python-sdk/roboto/domain/topics/record#roboto.domain.topics.record.MessagePathRecord.data_type) gives examples.

- **MessagePath.max** (`PreComputedStat`): Maximum of the message path's values, or `None` if it was not computed.

- **MessagePath.mean** (`PreComputedStat`): Mean of the message path's values, or `None` if it was not computed.

- **MessagePath.median** (`PreComputedStat`): Median of the message path's values, or `None` if it was not computed.

- **MessagePath.message_path_id** (`str`): Unique ID of the message path, beginning with `mp_`.

- **MessagePath.metadata** (`dict[str, Any]`): Key-value metadata on the message path, such as `{"min": 0.71, "max": 1.77}`.

  It includes the message path's computed statistics. Returns a copy, so changing it does not change this instance. [`metadata`](/docs/reference/python-sdk/roboto/domain/topics/record#roboto.domain.topics.record.MessagePathRecord.metadata) names the keys Roboto gives a meaning to.

- **MessagePath.min** (`PreComputedStat`): Minimum of the message path's values, or `None` if it was not computed.

- **MessagePath.modified** (`datetime.datetime`): Time the message path was last modified.

- **MessagePath.modified_by** (`str`): ID of the user who last modified the message path.

- **MessagePath.org_id** (`str`): ID of the organization that owns the message path, which is the organization that owns its topic.

- **MessagePath.p25** (`PreComputedStat`): 25th percentile of the message path's values, or `None` if it was not computed.

- **MessagePath.p75** (`PreComputedStat`): 75th percentile of the message path's values, or `None` if it was not computed.

- **MessagePath.p95** (`PreComputedStat`): 95th percentile of the message path's values, or `None` if it was not computed.

- **MessagePath.p99** (`PreComputedStat`): 99th percentile of the message path's values, or `None` if it was not computed.

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

- **MessagePath.record** (`roboto.domain.topics.record.MessagePathRecord`): Record of the message path that this instance holds.

- **MessagePath.stddev** (`PreComputedStat`): Standard deviation of the message path's values, or `None` if it was not computed.

- **MessagePath.topic_id** (`str`): ID of the topic this message path belongs to.

#### MessagePath.from_id()

```python
@classmethod
def from_id(
    message_path_id: str,
    roboto_client: Optional[roboto.http.RobotoClient] = None,
    topic_data_service: Optional[roboto.domain.topics.topic_data_service.TopicDataService] = None,
) -> MessagePath
```

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

Fetch a message path by its ID.

**Parameters**

- **message_path_id** (`str`): Unique ID of the message path, beginning with `mp_`.
- **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).
- **topic_data_service** (`Optional[roboto.domain.topics.topic_data_service.TopicDataService]`): Service to read the message path's data with. `None` creates one that uses `roboto_client`.

**Raises**

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

**Returns**

- `MessagePath`

**Usage**

```python
message_path = MessagePath.from_id("mp_12345")
print(message_path.path)
# angular_velocity.x
print(message_path.canonical_data_type)
# CanonicalDataType.Number
```

#### MessagePath.get_data()

```python
def get_data(
    start_time: Optional[roboto.time.Time] = None,
    end_time: Optional[roboto.time.Time] = None,
    cache_dir: Union[str, pathlib.Path, None] = 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/message_path.py#L264-L316)

Yield this message path's values, optionally limited to a time range.

Each yielded item is a `(timestamp, message)` tuple. `timestamp` is in nanoseconds since the Unix epoch, and `message` is a dictionary that holds only this message path's field, nested under its parent fields as in the topic's schema.

**Parameters**

- **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).

**Yields**

- `(timestamp, message)` tuples within the time range.

**Returns**

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

**Usage**

Print every value of `angular_velocity.x`:

```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")
for timestamp, message in angular_velocity_x.get_data():
    print(timestamp, message["angular_velocity"]["x"])
```

Print only the values within a time range:

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

Read several message paths at once with a thread pool:

```python
from concurrent.futures import ThreadPoolExecutor
message_paths = [topic.get_message_path(path) for path in ["angular_velocity.x", "angular_velocity.y"]]
with ThreadPoolExecutor(max_workers=16) as executor:
    results = list(executor.map(lambda mp: list(mp.get_data()), message_paths))
```

#### MessagePath.get_data_as_df()

```python
def get_data_as_df(
    start_time: Optional[roboto.time.Time] = None,
    end_time: Optional[roboto.time.Time] = None,
    cache_dir: Union[str, pathlib.Path, None] = None,
) -> pandas.DataFrame
```

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

Fetch this message path's values as a pandas DataFrame, optionally limited to a time range.

The DataFrame's columns hold this message path's values. Its index, named `_index`, is a `pandas.DatetimeIndex` of each row's timestamp in UTC. Requires the `roboto[analytics]` extra.

**Parameters**

- **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).

**Raises**

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

**Returns**

- `pandas.DataFrame`

**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")
df = angular_velocity_x.get_data_as_df()
print(df.head())
```

Read several message paths at once with a thread pool, and combine them in time order:

```python
import pandas as pd
from concurrent.futures import ThreadPoolExecutor
message_paths = [topic.get_message_path(path) for path in ["angular_velocity.x", "angular_velocity.y"]]
with ThreadPoolExecutor(max_workers=16) as executor:
    dfs = list(executor.map(lambda mp: mp.get_data_as_df(), message_paths))
combined = pd.concat(dfs).sort_index()
```

#### MessagePath.parents()

```python
@staticmethod
def parents(path_in_schema: list[str]) -> list[str]
```

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

Return the paths of a field's ancestors in the source data's schema, nearest first.

Each ancestor's path is leading components of `path_in_schema`, joined with dots.

**Parameters**

- **path_in_schema** (`list[str]`): Components of the field's path in the source data's schema, in order from the schema root, such as [`path_in_schema`](/docs/reference/python-sdk/roboto/domain/topics/record#roboto.domain.topics.record.MessagePathRecord.path_in_schema).

**Returns**

- `list[str]`: The ancestors' paths, or an empty list for a field at the schema root.

**Raises**

- `TypeError`: `path_in_schema` is a string, such as a dot-delimited path, rather than a list.

**Usage**

```python
MessagePath.parents(["pose", "pose", "position", "x"])
# ['pose.pose.position', 'pose.pose', 'pose']
```

A field at the schema root has no ancestors:

```python
MessagePath.parents(["velocity"])
# []
```

#### MessagePath.to_association()

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

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

Return an association that refers to the message path, for APIs that take one.

**Usage**

```python
message_path = MessagePath.from_id("mp_12345")
message_path.to_association().association_id
# 'mp_12345'
```

**Returns**

- `roboto.association.Association`

### PreComputedStat

```python
type roboto.domain.topics.message_path.PreComputedStat = typing.Optional[typing.Union[int, float]]
```

`from roboto.domain.topics.message_path import PreComputedStat`

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

Value of a statistic Roboto computed for a message path, or `None` if it was not computed.
