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

### TopicSchema

```python
class roboto.domain.topics.topic_schema.TopicSchema(
    record: roboto.domain.topics.record.TopicSchemaRecord,
    fields: list[roboto.domain.topics.record.SchemaFieldRecord],
    roboto_client: roboto.http.RobotoClient,
)
```

`from roboto import TopicSchema`

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

A topic schema: the fields that make up a topic's messages, each with its path and data type.

Within an organization, a checksum of its fields identifies a schema, so topics whose messages have identical fields share one schema. The schema's name, such as `"sensor_msgs/Imu"`, is not part of that identity.

Get a `TopicSchema` from `TopicSchema.from_id`, or from `Topic.get_schema` for the schema of a given topic.

**Parameters**

- **record** (`roboto.domain.topics.record.TopicSchemaRecord`)
- **fields** (`list[roboto.domain.topics.record.SchemaFieldRecord]`)
- **roboto_client** (`roboto.http.RobotoClient`)

**Properties**

- **TopicSchema.checksum** (`str`): Checksum computed from the schema's fields; schemas with identical fields have the same checksum.

- **TopicSchema.fields** (`list[roboto.domain.topics.record.SchemaFieldRecord]`): Fields of the schema, one per field path.

- **TopicSchema.name** (`str | None`): Informational name of the schema, such as `"sensor_msgs/PointCloud2"`; not part of its identity.

  `None` if the schema has none. `TopicSchemaRecord` describes when Roboto replaces the name.

  Return type: `Optional[str]`

- **TopicSchema.record** (`roboto.domain.topics.record.TopicSchemaRecord`): Record of the topic schema that this instance holds.

- **TopicSchema.schema_id** (`str`): Unique ID of the schema.

  It begins with `ts_`. See `TopicSchemaRecord.schema_id`.

#### TopicSchema.from_id()

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

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

Fetch a topic schema and its fields by the schema's ID.

**Parameters**

- **schema_id** (`str`): Unique ID of the schema, beginning with `ts_`.
- **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 schema has this ID.

**Returns**

- `TopicSchema`

**Usage**

```python
from roboto.domain.topics import TopicSchema
schema = TopicSchema.from_id("ts_12345")
print(schema.name, schema.checksum)
for field in schema.fields:
    print(field.path_in_schema, field.data_type)
```
