---
sidebar:
  hidden: true
title: roboto.domain.comments.comment
---
## Module Contents

### Comment

```python
class roboto.domain.comments.comment.Comment(
    record: roboto.domain.comments.record.CommentRecord,
    roboto_client: Optional[roboto.http.RobotoClient] = None,
)
```

`from roboto import Comment`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/comments/comment.py#L23-L444)

A comment: text a user writes on an action, collection, dataset, file, invocation, or trigger.

A comment belongs to the organization it was created in. Its text can mention other users of that organization, each written `@[<display_name>](<user_id>)`, and Roboto notifies the users it mentions.

Get a `Comment` from `create` or `from_id`, or list comments with `for_entity`, `for_entity_type`, `for_user`, and `recent_for_org`. To wrap a [`CommentRecord`](/docs/reference/python-sdk/roboto/domain/comments/record#roboto.domain.comments.record.CommentRecord) already fetched from Roboto, build a `Comment` from it directly. Each instance holds a copy of the comment's record, which `update_comment` replaces with Roboto's response.

**Parameters**

- **record** (`roboto.domain.comments.record.CommentRecord`): Record of the comment.
- **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).

**Properties**

- **Comment.comment_id** (`str`): Unique ID of the comment, beginning with `cm_`.

- **Comment.created** (`datetime.datetime`): Time the comment was created.

- **Comment.created_by** (`str`): ID of the user who wrote the comment.

- **Comment.modified** (`datetime.datetime`): Time the comment was last modified.

- **Comment.modified_by** (`str`): ID of the user who wrote the comment.

  [`modified_by`](/docs/reference/python-sdk/roboto/domain/comments/record#roboto.domain.comments.record.CommentRecord.modified_by) describes how Roboto sets it.

- **Comment.record** (`roboto.domain.comments.record.CommentRecord`): Record of the comment that this instance holds.

  `update_comment` replaces it with the edited one.

#### Comment.create()

```python
@classmethod
def create(
    comment_text: str,
    entity_id: str,
    entity_type: roboto.domain.comments.record.CommentEntityType,
    roboto_client: Optional[roboto.http.RobotoClient] = None,
    caller_org_id: Optional[str] = None,
) -> Comment
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/comments/comment.py#L44-L101)

Create a comment on an action, collection, dataset, file, invocation, or trigger.

A mention in `comment_text`, written `@[<display_name>](<user_id>)`, adds that user to the comment's [`mentions`](/docs/reference/python-sdk/roboto/domain/comments/record#roboto.domain.comments.record.CommentRecord.mentions) and notifies them, by email unless their settings turn off comment-mention emails. The caller may mention themselves; Roboto does not notify them.

**Parameters**

- **comment_text** (`str`): Text of the comment.
- **entity_id** (`str`): ID of the resource to comment on, such as a dataset's `ds_` ID.
- **entity_type** (`roboto.domain.comments.record.CommentEntityType`): Kind of resource `entity_id` names.
- **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).
- **caller_org_id** (`Optional[str]`): Organization to create the comment in. Required when the caller belongs to more than one organization; otherwise the caller's only organization.

**Returns**

- `Comment`: The new comment.

**Raises**

- [`RobotoUnauthorizedException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoUnauthorizedException): `comment_text` mentions a user outside the organization. Roboto has already saved the comment.

**Usage**

Comment on a dataset:

```python
comment = Comment.create(
    comment_text="This dataset looks good!",
    entity_id="ds_12345",
    entity_type=CommentEntityType.Dataset,
)
```

Comment on a file and mention a user, which notifies them:

```python
comment = Comment.create(
    comment_text="@[Alex Kim](alex@example.com) please review this",
    entity_id="fl_12345",
    entity_type=CommentEntityType.File,
)
```

#### Comment.delete_comment()

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

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/comments/comment.py#L393-L406)

Delete the comment. This cannot be undone.

Only the comment's author or a Roboto administrator can delete it. Deleting a comment that no longer exists succeeds and changes nothing.

**Raises**

- [`RobotoUnauthorizedException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoUnauthorizedException): The caller may not delete the comment.

**Returns**

- `None`

**Usage**

```python
comment = Comment.from_id("cm_12345")
comment.delete_comment()
```

#### Comment.for_entity()

```python
@classmethod
def for_entity(
    entity_type: roboto.domain.comments.record.CommentEntityType,
    entity_id: str,
    owner_org_id: Optional[str] = None,
    page_token: Optional[str] = None,
    roboto_client: Optional[roboto.http.RobotoClient] = None,
) -> tuple[collections.abc.Sequence[Comment], Optional[str]]
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/comments/comment.py#L136-L193)

List one page of the comments on a resource, newest first.

Each page holds up to 100 comments. A resource that has no comments, or that does not exist, returns an empty page. Listing a resource's comments takes permission to read the resource.

**Parameters**

- **entity_type** (`roboto.domain.comments.record.CommentEntityType`): Kind of resource `entity_id` names.
- **entity_id** (`str`): ID of the resource whose comments to list, such as a dataset's `ds_` ID.
- **owner_org_id** (`Optional[str]`): Organization that owns the comments. Defaults to the organization the caller acts in.
- **page_token** (`Optional[str]`): Token from a previous page's response that resumes the listing after it. `None` starts at the first page.
- **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**

- `tuple[collections.abc.Sequence[Comment], Optional[str]]`: `(comments, next_token)`: the page's comments and the token for the next page. Pass `next_token` as `page_token` to fetch the next page; it is `None` on the last page.

**Usage**

List the first page of comments on a dataset:

```python
page, next_token = Comment.for_entity(entity_type=CommentEntityType.Dataset, entity_id="ds_12345")
```

List every comment on a file, a page at a time:

```python
all_comments = []
page_token = None
while True:
    page, page_token = Comment.for_entity(
        entity_type=CommentEntityType.File,
        entity_id="fl_12345",
        page_token=page_token,
    )
    all_comments.extend(page)
    if page_token is None:
        break
```

#### Comment.for_entity_type()

```python
@classmethod
def for_entity_type(
    entity_type: roboto.domain.comments.record.CommentEntityType,
    owner_org_id: Optional[str] = None,
    page_token: Optional[str] = None,
    roboto_client: Optional[roboto.http.RobotoClient] = None,
) -> tuple[collections.abc.Sequence[Comment], Optional[str]]
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/comments/comment.py#L196-L248)

List one page of an organization's comments on one kind of resource, newest first.

Each page holds up to 100 comments.

Comments on an entity the caller may not read are left out of the page they fall on, so a page can hold fewer comments than usual, or none, and still return a pagination token. Keep requesting pages until the token is None.

**Parameters**

- **entity_type** (`roboto.domain.comments.record.CommentEntityType`): Kind of resource whose comments to list, such as [`Dataset`](/docs/reference/python-sdk/roboto/domain/comments/record#roboto.domain.comments.record.CommentEntityType.Dataset) for every comment on a dataset.
- **owner_org_id** (`Optional[str]`): Organization that owns the comments. Defaults to the organization the caller acts in.
- **page_token** (`Optional[str]`): Token from a previous page's response that resumes the listing after it. `None` starts at the first page.
- **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**

- `tuple[collections.abc.Sequence[Comment], Optional[str]]`: `(comments, next_token)`: the page's comments and the token for the next page. Pass `next_token` as `page_token` to fetch the next page; it is `None` on the last page.

**Usage**

List the first page of comments on datasets:

```python
page, next_token = Comment.for_entity_type(entity_type=CommentEntityType.Dataset)
```

List the first page of comments on invocations, naming the organization:

```python
page, next_token = Comment.for_entity_type(
    entity_type=CommentEntityType.Invocation, owner_org_id="og_12345"
)
```

#### Comment.for_user()

```python
@classmethod
def for_user(
    user_id: str,
    owner_org_id: Optional[str] = None,
    page_token: Optional[str] = None,
    roboto_client: Optional[roboto.http.RobotoClient] = None,
) -> tuple[collections.abc.Sequence[Comment], Optional[str]]
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/comments/comment.py#L251-L301)

List one page of the comments a user wrote in an organization, newest first.

Each page holds up to 100 comments.

Comments on an entity the caller may not read are left out of the page they fall on, so a page can hold fewer comments than usual, or none, and still return a pagination token. Keep requesting pages until the token is None.

**Parameters**

- **user_id** (`str`): ID of the user whose comments to list, which for a person is their email address.
- **owner_org_id** (`Optional[str]`): Organization whose comments to list. Defaults to the organization the caller acts in.
- **page_token** (`Optional[str]`): Token from a previous page's response that resumes the listing after it. `None` starts at the first page.
- **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**

- `tuple[collections.abc.Sequence[Comment], Optional[str]]`: `(comments, next_token)`: the page's comments and the token for the next page. Pass `next_token` as `page_token` to fetch the next page; it is `None` on the last page.

**Usage**

List the first page of a user's comments:

```python
page, next_token = Comment.for_user(user_id="alex@example.com")
```

List the first page of a user's comments, naming the organization:

```python
page, next_token = Comment.for_user(user_id="sam@example.com", owner_org_id="og_12345")
```

#### Comment.from_id()

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

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/comments/comment.py#L104-L133)

Fetch a comment by its ID.

Reading a comment takes permission to read the resource it is on.

**Parameters**

- **comment_id** (`str`): ID of the comment, beginning with `cm_`.
- **owner_org_id** (`Optional[str]`): Organization that owns the comment. 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**

- `Comment`: The comment.

**Raises**

- [`RobotoNotFoundException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoNotFoundException): The organization has no comment with this ID.
- [`RobotoUnauthorizedException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoUnauthorizedException): The caller may not read the resource the comment is on.

**Usage**

```python
comment = Comment.from_id("cm_12345")
print(comment.record.comment_text)
```

#### Comment.recent_for_org()

```python
@classmethod
def recent_for_org(
    owner_org_id: Optional[str] = None,
    page_token: Optional[str] = None,
    roboto_client: Optional[roboto.http.RobotoClient] = None,
) -> tuple[collections.abc.Sequence[Comment], Optional[str]]
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/comments/comment.py#L304-L348)

List one page of an organization's comments on every kind of resource, newest first.

Comments are ordered by the time they were created; editing a comment does not move it. Each page holds up to 100 comments.

Comments on an entity the caller may not read are left out of the page they fall on, so a page can hold fewer comments than usual, or none, and still return a pagination token. Keep requesting pages until the token is None.

**Parameters**

- **owner_org_id** (`Optional[str]`): Organization that owns the comments. Defaults to the organization the caller acts in.
- **page_token** (`Optional[str]`): Token from a previous page's response that resumes the listing after it. `None` starts at the first page.
- **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**

- `tuple[collections.abc.Sequence[Comment], Optional[str]]`: `(comments, next_token)`: the page's comments and the token for the next page. Pass `next_token` as `page_token` to fetch the next page; it is `None` on the last page.

**Usage**

Print the organization's most recent comment:

```python
page, next_token = Comment.recent_for_org()
if page:
    print(page[0].record.comment_text)
```

#### Comment.update_comment()

```python
def update_comment(comment_text: str) -> Comment
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/comments/comment.py#L408-L444)

Replace the comment's text.

Only the comment's author or a Roboto administrator can edit it. Roboto rereads the mentions from the new text and notifies only the users the previous text did not mention.

**Parameters**

- **comment_text** (`str`): New text of the comment, with mentions written `@[<display_name>](<user_id>)`.

**Returns**

- `Comment`: This instance, with its record updated from Roboto's response.

**Raises**

- [`RobotoNotFoundException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoNotFoundException): The comment has been deleted.
- [`RobotoUnauthorizedException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoUnauthorizedException): The caller may not edit the comment, or `comment_text` newly mentions a user outside the organization. In the second case Roboto has already saved the new text.

**Usage**

Replace the text:

```python
comment = Comment.from_id("cm_12345")
updated = comment.update_comment("Updated text content")
print(updated.record.comment_text)
# Updated text content
```

Mention a user in the new text, which notifies them:

```python
comment.update_comment("@[Sam Lee](sam@example.com) please check this")
```
