---
sidebar:
  hidden: true
title: roboto.domain.collections.collection
---
## Module Contents

### Collection

```python
class roboto.domain.collections.collection.Collection(
    record: roboto.domain.collections.record.CollectionRecord,
    roboto_client: Optional[roboto.http.RobotoClient] = None,
)
```

`from roboto import Collection`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/collections/collection.py#L54-L970)

A collection: a versioned group of resources of one type, such as datasets or files from several datasets.

A collection belongs to one organization and holds datasets, files, events, or sessions, whichever type it is created with. Each update to a collection creates a new version, and `changes` lists what each update changed.

A collection shows each caller only the datasets and files they may read. Read with [`Full`](/docs/reference/python-sdk/roboto/domain/collections/record#roboto.domain.collections.record.CollectionContentMode.Full), a dataset or file the caller may not read is listed in the record's `missing` resources; read with [`References`](/docs/reference/python-sdk/roboto/domain/collections/record#roboto.domain.collections.record.CollectionContentMode.References), and in `changes`, it is left out. `datasets` and `files` hold only the members shown.

Get a `Collection` from `create`, `from_id`, or `list_all`. To wrap a [`CollectionRecord`](/docs/reference/python-sdk/roboto/domain/collections/record#roboto.domain.collections.record.CollectionRecord) already fetched from Roboto, build a `Collection` from it directly. Each instance holds a copy of the collection's record: methods that change the collection update that copy from Roboto's response.

**Parameters**

- **record** (`roboto.domain.collections.record.CollectionRecord`): Record of the collection.
- **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**

- **Collection.collection_id** (`str`): Unique ID of the collection, beginning with `cl_`.

- **Collection.created** (`datetime.datetime`): Time the collection was created.

- **Collection.created_by** (`str`): ID of the user who created the collection.

- **Collection.custom_fields** (`dict[str, Any]`): Values of the custom fields the organization defines for collections, keyed by field name.

  [`custom_fields`](/docs/reference/python-sdk/roboto/domain/collections/record#roboto.domain.collections.record.CollectionRecord.custom_fields) says which fields appear as keys. A [`Timestamp`](/docs/reference/python-sdk/roboto/domain/custom_fields/record#roboto.domain.custom_fields.record.CustomFieldType.Timestamp) value is an ISO 8601 string.

- **Collection.datasets** (`list[str]`): IDs of the datasets in the collection.

  Empty when the collection was read with [`SummaryOnly`](/docs/reference/python-sdk/roboto/domain/collections/record#roboto.domain.collections.record.CollectionContentMode.SummaryOnly). After a [`Full`](/docs/reference/python-sdk/roboto/domain/collections/record#roboto.domain.collections.record.CollectionContentMode.Full) read, leaves out the members [`missing`](/docs/reference/python-sdk/roboto/domain/collections/record#roboto.domain.collections.record.CollectionRecord.missing) lists.

- **Collection.description** (`str | None`): Human-readable description of the collection, or `None` if it has none.

  Return type: `Optional[str]`

- **Collection.events** (`list[str]`): IDs of the events in the collection.

  Empty when the collection was read with [`SummaryOnly`](/docs/reference/python-sdk/roboto/domain/collections/record#roboto.domain.collections.record.CollectionContentMode.SummaryOnly). Leaves out the events the caller cannot read, and, after a [`Full`](/docs/reference/python-sdk/roboto/domain/collections/record#roboto.domain.collections.record.CollectionContentMode.Full) read, the members `record.missing` lists.

- **Collection.files** (`list[str]`): IDs of the files in the collection.

  Empty when the collection was read with [`SummaryOnly`](/docs/reference/python-sdk/roboto/domain/collections/record#roboto.domain.collections.record.CollectionContentMode.SummaryOnly). After a [`Full`](/docs/reference/python-sdk/roboto/domain/collections/record#roboto.domain.collections.record.CollectionContentMode.Full) read, leaves out the members `record.missing` lists.

- **Collection.name** (`str | None`): Human-readable name of the collection, or `None` if it has none.

  [`name`](/docs/reference/python-sdk/roboto/domain/collections/record#roboto.domain.collections.record.CollectionRecord.name) says whether names must be unique.

  Return type: `Optional[str]`

- **Collection.record** (`roboto.domain.collections.record.CollectionRecord`): Record of the collection that this instance holds.

- **Collection.resource_count** (`int`): Number of members the collection holds, in every content mode.

  [`resource_count`](/docs/reference/python-sdk/roboto/domain/collections/record#roboto.domain.collections.record.CollectionRecord.resource_count) says which members it counts. It can be higher than the number of IDs `datasets` and the other member properties return.

- **Collection.sessions** (`list[str]`): IDs of the sessions in the collection.

  Empty when the collection was read with [`SummaryOnly`](/docs/reference/python-sdk/roboto/domain/collections/record#roboto.domain.collections.record.CollectionContentMode.SummaryOnly). After a [`Full`](/docs/reference/python-sdk/roboto/domain/collections/record#roboto.domain.collections.record.CollectionContentMode.Full) read, leaves out the members `record.missing` lists.

- **Collection.updated** (`datetime.datetime`): Time the collection was last updated, or the time it was created if it has never been updated.

- **Collection.updated_by** (`str`): ID of the user who last updated the collection, or who created it if it has never been updated.

#### Collection.add_dataset()

```python
def add_dataset(dataset_id: str) -> Collection
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/collections/collection.py#L456-L478)

Add a dataset to the collection.

Adding a dataset that is already a member changes nothing but still creates a new version. It calls `update`, whose failures also apply.

**Parameters**

- **dataset_id** (`str`): ID of the dataset to add.

**Returns**

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

**Raises**

- [`RobotoInvalidRequestException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoInvalidRequestException): The collection does not hold datasets.
- [`RobotoNotFoundException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoNotFoundException): No dataset has this ID.

**Usage**

```python
collection = Collection.from_id("cl_12345")
collection.add_dataset("ds_12345")
```

#### Collection.add_event()

```python
def add_event(event_id: str) -> Collection
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/collections/collection.py#L480-L503)

Add an event to the collection.

Adding an event that is already a member changes nothing but still creates a new version. It calls `update`, whose failures also apply.

**Parameters**

- **event_id** (`str`): ID of the event to add.

**Returns**

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

**Raises**

- [`RobotoInvalidRequestException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoInvalidRequestException): The collection does not hold events.
- [`RobotoNotFoundException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoNotFoundException): No event has this ID, or the event belongs to another organization, or the caller cannot read it.

**Usage**

```python
collection = Collection.from_id("cl_12345")
collection.add_event("ev_12345")
```

#### Collection.add_file()

```python
def add_file(file_id: str) -> Collection
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/collections/collection.py#L505-L527)

Add a file to the collection.

Adding a file that is already a member changes nothing but still creates a new version. It calls `update`, whose failures also apply.

**Parameters**

- **file_id** (`str`): ID of the file to add.

**Returns**

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

**Raises**

- [`RobotoInvalidRequestException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoInvalidRequestException): The collection does not hold files.
- [`RobotoNotFoundException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoNotFoundException): No file has this ID.

**Usage**

```python
collection = Collection.from_id("cl_12345")
collection.add_file("fl_12345")
```

#### Collection.add_session()

```python
def add_session(session_id: str) -> Collection
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/collections/collection.py#L529-L551)

Add a session to the collection.

Adding a session that is already a member changes nothing but still creates a new version. It calls `update`, whose failures also apply.

**Parameters**

- **session_id** (`str`): ID of the session to add.

**Returns**

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

**Raises**

- [`RobotoInvalidRequestException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoInvalidRequestException): The collection does not hold sessions.
- [`RobotoNotFoundException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoNotFoundException): No session has this ID, or the session belongs to another organization.

**Usage**

```python
collection = Collection.from_id("cl_12345")
collection.add_session("se_12345")
```

#### Collection.changes()

```python
def changes(
    from_version: Optional[int] = None,
    to_version: Optional[int] = None,
) -> collections.abc.Generator[roboto.domain.collections.record.CollectionChangeRecord, None, None]
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/collections/collection.py#L553-L589)

Yield the collection's revision history, oldest change first.

Each update to the collection is one change, from one version to the next; version `0` is the collection as it was created. Each change leaves out the added and removed datasets, files and events the caller cannot read.

**Parameters**

- **from_version** (`Optional[int]`): Version to start from: yields the changes applied to this version or later. `0` starts at the collection's creation. `None` leaves this end open.
- **to_version** (`Optional[int]`): Version to stop at: yields the changes that produced this version or earlier. `0` yields nothing, because no change produces version `0`. `None` leaves this end open.

**Yields**

- One [`CollectionChangeRecord`](/docs/reference/python-sdk/roboto/domain/collections/record#roboto.domain.collections.record.CollectionChangeRecord) for each update in the range.

**Returns**

- `collections.abc.Generator[roboto.domain.collections.record.CollectionChangeRecord, None, None]`

**Usage**

```python
collection = Collection.from_id("cl_12345")
for change in collection.changes(from_version=2):
    print(change.to_version, change.change_set.added_resources)
```

#### Collection.clear_custom_field()

```python
def clear_custom_field(name: str) -> Collection
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/collections/collection.py#L904-L923)

Clear one custom-field value on the collection, so it reads as `None`.

It calls `update`, whose failures also apply.

**Parameters**

- **name** (`str`): Name of a custom field defined for collections in the collection's organization, with status [`Ready`](/docs/reference/python-sdk/roboto/domain/custom_fields/record#roboto.domain.custom_fields.record.CustomFieldStatus.Ready).

**Returns**

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

**Raises**

- [`RobotoIllegalArgumentException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoIllegalArgumentException): `name` is not a ready custom field for collections.

**Usage**

```python
collection = Collection.from_id("cl_12345")
collection.clear_custom_field("review_status")
```

#### Collection.clear_custom_fields()

```python
def clear_custom_fields(names: collections.abc.Sequence[str]) -> Collection
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/collections/collection.py#L951-L970)

Clear several custom-field values on the collection, so each reads as `None`.

It calls `update`, whose failures also apply.

**Parameters**

- **names** (`collections.abc.Sequence[str]`): Names of custom fields defined for collections in the collection's organization, with status [`Ready`](/docs/reference/python-sdk/roboto/domain/custom_fields/record#roboto.domain.custom_fields.record.CustomFieldStatus.Ready).

**Returns**

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

**Raises**

- [`RobotoIllegalArgumentException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoIllegalArgumentException): A name is not a ready custom field for collections.

**Usage**

```python
collection = Collection.from_id("cl_12345")
collection.clear_custom_fields(["review_status", "reviewer"])
```

#### Collection.create()

```python
@classmethod
def create(
    description: Optional[str] = None,
    name: Optional[str] = None,
    resource_type: roboto.domain.collections.record.CollectionResourceType = CollectionResourceType.File,
    resources: Optional[list[roboto.domain.collections.record.CollectionResourceRef]] = None,
    dataset_ids: Optional[collections.abc.Collection[str]] = None,
    event_ids: Optional[collections.abc.Collection[str]] = None,
    file_ids: Optional[collections.abc.Collection[str]] = None,
    session_ids: Optional[collections.abc.Collection[str]] = None,
    tags: Optional[list[str]] = None,
    custom_fields: Optional[dict[str, Any]] = None,
    roboto_client: Optional[roboto.http.RobotoClient] = None,
    caller_org_id: Optional[str] = None,
) -> Collection
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/collections/collection.py#L128-L246)

Create a collection.

The collection starts with `resources` followed by the resources the `*_ids` arguments name. Every one of them must be of `resource_type`, which defaults to files: to create a collection of datasets, pass `resource_type=CollectionResourceType.Dataset` along with `dataset_ids`.

**Parameters**

- **description** (`Optional[str]`): Human-readable description of the collection.
- **name** (`Optional[str]`): Human-readable name of the collection. Roboto does not require names to be unique.
- **resource_type** (`roboto.domain.collections.record.CollectionResourceType`): Type of resource the collection holds. It cannot change after the collection is created.
- **resources** (`Optional[list[roboto.domain.collections.record.CollectionResourceRef]]`): Resources the collection starts with. `None` adds none.
- **dataset_ids** (`Optional[collections.abc.Collection[str]]`): IDs of datasets the collection starts with.
- **event_ids** (`Optional[collections.abc.Collection[str]]`): IDs of events the collection starts with.
- **file_ids** (`Optional[collections.abc.Collection[str]]`): IDs of files the collection starts with.
- **session_ids** (`Optional[collections.abc.Collection[str]]`): IDs of sessions the collection starts with.
- **tags** (`Optional[list[str]]`): Tags to set on the collection.
- **custom_fields** (`Optional[dict[str, Any]]`): Initial values for the collection's custom fields, keyed by field name. Each name must be a custom field defined for collections in the organization, with status [`Ready`](/docs/reference/python-sdk/roboto/domain/custom_fields/record#roboto.domain.custom_fields.record.CustomFieldStatus.Ready), and each value must match that field's declared type. `None` sets none.
- **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 collection in. Required when the caller belongs to more than one organization; otherwise the caller's only organization.

**Returns**

- `Collection`: The new collection, with each member's full record.

**Raises**

- [`RobotoInvalidRequestException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoInvalidRequestException): A resource is not of `resource_type`.
- [`RobotoNotFoundException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoNotFoundException): A resource does not exist, or is an event or session in another organization.
- [`RobotoIllegalArgumentException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoIllegalArgumentException): A `custom_fields` name is not a ready custom field for collections, or its value does not match the field's type.

**Usage**

Create a collection of two datasets:

```python
from roboto.domain.collections import CollectionResourceType
collection = Collection.create(
    name="Highway test drives",
    resource_type=CollectionResourceType.Dataset,
    dataset_ids=["ds_12345", "ds_67890"],
    tags=["highway"],
)
```

Create a collection of files from different datasets:

```python
collection = Collection.create(
    name="Calibration logs",
    file_ids=["fl_12345", "fl_67890"],
)
```

#### Collection.delete()

```python
def delete()
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/collections/collection.py#L591-L600)

Delete the collection. This cannot be undone.

Deletes none of its members. Deleting a collection that no longer exists succeeds and changes nothing.

**Usage**

```python
collection = Collection.from_id("cl_12345")
collection.delete()
```

#### Collection.edit_access()

```python
def edit_access(edit: roboto.auth.EditAccessRequest) -> roboto.auth.GetAccessResponse
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/collections/collection.py#L622-L653)

Deprecated. Add and remove the tuples that share this collection.

Use `edit_record_access` instead, which takes grants and the collection's restriction. Calling this method issues a `DeprecationWarning`. It sends API version 2026-11-05, the last version whose access route takes tuples. Adding the collection's organization group as `associated_group` unrestricts the collection, and removing it restricts it. Roboto checks every tuple before it changes anything.

**Parameters**

- **edit** (`roboto.auth.EditAccessRequest`): Tuples to add and remove. Each tuple's `obj` must be `collection:<collection_id>` for this collection, and its `relation` one of `viewer`, `editor`, `deleter` or `associated_group`.

**Returns**

- `roboto.auth.GetAccessResponse`: Every tuple on the collection after the edit, as `get_access` returns them.

**Raises**

- [`RobotoInvalidRequestException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoInvalidRequestException): An added tuple names a principal in a form no share takes, the members of another organization, or a group other than the collection's organization group as `associated_group`.
- [`RobotoUnauthorizedException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoUnauthorizedException): A tuple names another resource or a relation outside those listed above.

#### Collection.edit_record_access()

```python
def edit_record_access(
    add: collections.abc.Sequence[roboto.auth.AccessGrant] = (),
    remove: collections.abc.Sequence[roboto.auth.AccessGrant] = (),
    restricted: Optional[bool] = None,
) -> roboto.auth.RecordAccessResponse
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/collections/collection.py#L670-L718)

Change who this collection is shared with.

The change is applied whole or not at all: grants in `add` are added, then grants in `remove` are removed, then the restriction is set. Sharing a collection does not share the datasets in it.

A change requires permission to share the collection, which the [`Editor`](/docs/reference/python-sdk/roboto/auth/record_access#roboto.auth.record_access.AccessRole.Editor) and [`Deleter`](/docs/reference/python-sdk/roboto/auth/record_access#roboto.auth.record_access.AccessRole.Deleter) roles on it give, as does being an admin or owner of its organization or, while the collection is unrestricted, a member. A call that changes nothing requires only permission to read the collection.

**Parameters**

- **add** (`collections.abc.Sequence[roboto.auth.AccessGrant]`): Grants to add. A grant to [`OrgMembers`](/docs/reference/python-sdk/roboto/auth/record_access#roboto.auth.record_access.AccessSubjectKind.OrgMembers) may name only the collection's organization, and [`Everyone`](/docs/reference/python-sdk/roboto/auth/record_access#roboto.auth.record_access.AccessSubjectKind.Everyone) may be given only [`Viewer`](/docs/reference/python-sdk/roboto/auth/record_access#roboto.auth.record_access.AccessRole.Viewer).
- **remove** (`collections.abc.Sequence[roboto.auth.AccessGrant]`): Grants to remove, including a grant to another organization's members. Removing a grant the collection does not hold changes nothing.
- **restricted** (`Optional[bool]`): `True` makes members of the collection's organization need a grant to reach it, `False` lets every member reach it, and `None` leaves it as it is.

**Returns**

- `roboto.auth.RecordAccessResponse`: Who the collection is shared with after the change.

**Raises**

- [`RobotoInvalidRequestException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoInvalidRequestException): A `User`, `Group` or `OrgMembers` subject has no ID, an `Everyone` subject has an ID or a role other than `Viewer`, a grant in `add` names the members of another organization, or, on a deployment that decides access from Roboto's own tables, a grant in `add` names a group that is not one of the collection's organization's groups.

**Usage**

```python
from roboto.auth import AccessGrant, AccessRole, AccessSubject
from roboto.domain.collections import Collection
collection = Collection.from_id("cl_12345")
access = collection.edit_record_access(
    add=[AccessGrant(subject=AccessSubject.user("alex@example.com"), role=AccessRole.Viewer)],
    restricted=True,
)
access.restricted
# True
```

#### Collection.from_id()

```python
@classmethod
def from_id(
    collection_id: str,
    version: Optional[int] = None,
    content_mode: roboto.domain.collections.record.CollectionContentMode = CollectionContentMode.Full,
    roboto_client: Optional[roboto.http.RobotoClient] = None,
) -> Collection
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/collections/collection.py#L81-L125)

Fetch a collection by its ID.

**Parameters**

- **collection_id** (`str`): ID of the collection, beginning with `cl_`.
- **version** (`Optional[int]`): Version of the collection to fetch: `0` is the collection as it was created, and each update adds one. `None` fetches the current version.
- **content_mode** (`roboto.domain.collections.record.CollectionContentMode`): How much of each member to return. Defaults to each member's full record.
- **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 collection has this ID.
- [`RobotoInvalidRequestException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoInvalidRequestException): `content_mode` is [`Full`](/docs/reference/python-sdk/roboto/domain/collections/record#roboto.domain.collections.record.CollectionContentMode.Full) and the response would be too large. Fetch the collection with [`References`](/docs/reference/python-sdk/roboto/domain/collections/record#roboto.domain.collections.record.CollectionContentMode.References) instead.

**Returns**

- `Collection`

**Usage**

Fetch the current version of a collection:

```python
collection = Collection.from_id("cl_12345")
print(collection.name, collection.resource_count)
```

Fetch the collection as it was when it was created, with a reference to each member:

```python
from roboto.domain.collections import CollectionContentMode
original = Collection.from_id("cl_12345", version=0, content_mode=CollectionContentMode.References)
```

#### Collection.get_access()

```python
def get_access() -> roboto.auth.GetAccessResponse
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/collections/collection.py#L602-L620)

Deprecated. Fetch who this collection is shared with, as tuples.

Use `get_record_access` instead, which returns the collection's restriction and grants. Calling this method issues a `DeprecationWarning`. It sends API version 2026-11-05, the last version whose access route returns tuples.

**Returns**

- `roboto.auth.GetAccessResponse`: Every tuple on the collection, as [`relations`](/docs/reference/python-sdk/roboto/auth/fga#roboto.auth.fga.GetAccessResponse.relations) describes.

#### Collection.get_record_access()

```python
def get_record_access() -> roboto.auth.RecordAccessResponse
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/collections/collection.py#L655-L668)

Fetch who this collection is shared with.

**Returns**

- `roboto.auth.RecordAccessResponse`: Whether members of the collection's organization need a grant to reach it, and its grants.

**Usage**

```python
from roboto.domain.collections import Collection
collection = Collection.from_id("cl_12345")
access = collection.get_record_access()
for grant in access.grants:
    print(grant.subject.id, grant.role)
```

#### Collection.list_all()

```python
@classmethod
def list_all(
    roboto_client: Optional[roboto.http.RobotoClient] = None,
    owner_org_id: Optional[str] = None,
    content_mode: roboto.domain.collections.record.CollectionContentMode = CollectionContentMode.SummaryOnly,
    sort_by: Optional[str] = None,
    sort_direction: Optional[roboto.query.SortDirection] = None,
) -> collections.abc.Generator[Collection, None, None]
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/collections/collection.py#L249-L310)

List the collections in an organization.

Fetches one page of results at a time as the generator advances.

**Parameters**

- **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).
- **owner_org_id** (`Optional[str]`): Organization whose collections to list. Defaults to the organization the caller acts in.
- **content_mode** (`roboto.domain.collections.record.CollectionContentMode`): How much of each collection's members to return. Defaults to none, so `datasets` and the other member properties are empty and only `resource_count` describes the members.
- **sort_by** (`Optional[str]`): Collection field to sort by, such as `created`, `name`, `updated` or `resource_count`. `None` uses Roboto's default order.
- **sort_direction** (`Optional[roboto.query.SortDirection]`): Direction to sort in. Used only when `sort_by` is set.

**Yields**

- Collections in the organization.

**Returns**

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

**Usage**

List every collection in the organization:

```python
for collection in Collection.list_all():
    print(collection.collection_id, collection.name, collection.resource_count)
```

List the most recently updated collections first:

```python
from roboto.query import SortDirection
for collection in Collection.list_all(sort_by="updated", sort_direction=SortDirection.Descending):
    print(collection.collection_id, collection.updated)
```

#### Collection.remove_dataset()

```python
def remove_dataset(dataset_id: str) -> Collection
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/collections/collection.py#L720-L740)

Remove a dataset from the collection.

Removing a dataset that is not a member changes nothing but still creates a new version. It calls `update`, whose failures also apply.

**Parameters**

- **dataset_id** (`str`): ID of the dataset to remove.

**Returns**

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

**Usage**

```python
collection = Collection.from_id("cl_12345")
collection.remove_dataset("ds_12345")
```

#### Collection.remove_event()

```python
def remove_event(event_id: str) -> Collection
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/collections/collection.py#L762-L780)

Remove an event from the collection.

Removing an event that is not a member changes nothing but still creates a new version. It calls `update`, whose failures also apply.

**Parameters**

- **event_id** (`str`): ID of the event to remove.

**Returns**

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

**Usage**

```python
collection = Collection.from_id("cl_12345")
collection.remove_event("ev_12345")
```

#### Collection.remove_file()

```python
def remove_file(file_id: str) -> Collection
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/collections/collection.py#L742-L760)

Remove a file from the collection.

Removing a file that is not a member changes nothing but still creates a new version. It calls `update`, whose failures also apply.

**Parameters**

- **file_id** (`str`): ID of the file to remove.

**Returns**

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

**Usage**

```python
collection = Collection.from_id("cl_12345")
collection.remove_file("fl_12345")
```

#### Collection.remove_session()

```python
def remove_session(session_id: str) -> Collection
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/collections/collection.py#L782-L802)

Remove a session from the collection.

Removing a session that is not a member changes nothing but still creates a new version. It calls `update`, whose failures also apply.

**Parameters**

- **session_id** (`str`): ID of the session to remove.

**Returns**

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

**Usage**

```python
collection = Collection.from_id("cl_12345")
collection.remove_session("se_12345")
```

#### Collection.set_custom_field()

```python
def set_custom_field(name: str, value: Any) -> Collection
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/collections/collection.py#L880-L901)

Set one custom-field value on the collection.

It calls `update`, whose failures also apply.

**Parameters**

- **name** (`str`): Name of a custom field defined for collections in the collection's organization, with status [`Ready`](/docs/reference/python-sdk/roboto/domain/custom_fields/record#roboto.domain.custom_fields.record.CustomFieldStatus.Ready).
- **value** (`Any`): Value to set. Must match the field's declared type.

**Returns**

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

**Raises**

- [`RobotoIllegalArgumentException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoIllegalArgumentException): `name` is not a ready custom field for collections, or `value` does not match its type.

**Usage**

```python
collection = Collection.from_id("cl_12345")
collection.set_custom_field("review_status", "approved")
```

#### Collection.set_custom_fields()

```python
def set_custom_fields(fields: dict[str, Any]) -> Collection
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/collections/collection.py#L926-L948)

Set several custom-field values on the collection, replacing any values those fields have.

It calls `update`, whose failures also apply.

**Parameters**

- **fields** (`dict[str, Any]`): Values to set, keyed by field name. Each name must be a custom field defined for collections in the collection's organization, with status [`Ready`](/docs/reference/python-sdk/roboto/domain/custom_fields/record#roboto.domain.custom_fields.record.CustomFieldStatus.Ready), and each value must match that field's declared type.

**Returns**

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

**Raises**

- [`RobotoIllegalArgumentException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoIllegalArgumentException): A name is not a ready custom field for collections, or its value does not match the field's type.

**Usage**

```python
collection = Collection.from_id("cl_12345")
collection.set_custom_fields({"review_status": "approved", "reviewer": "alex"})
```

#### Collection.update()

```python
def update(
    add_resources: Union[list[roboto.domain.collections.record.CollectionResourceRef], roboto.sentinels.NotSetType] = NotSet,
    add_tags: Union[list[str], roboto.sentinels.NotSetType] = NotSet,
    description: Optional[Union[roboto.sentinels.NotSetType, str]] = NotSet,
    name: Optional[Union[roboto.sentinels.NotSetType, str]] = NotSet,
    remove_resources: Union[list[roboto.domain.collections.record.CollectionResourceRef], roboto.sentinels.NotSetType] = NotSet,
    remove_tags: Union[list[str], roboto.sentinels.NotSetType] = NotSet,
    custom_fields_changeset: Optional[roboto.updates.CustomFieldChangeset] = None,
) -> Collection
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/collections/collection.py#L804-L877)

Update the collection's members, tags, name, description, or custom-field values.

An argument left unset (`NotSet`) leaves that property unchanged. Every update creates a new version of the collection, even one that changes nothing.

**Parameters**

- **add_resources** (`Union[list[roboto.domain.collections.record.CollectionResourceRef], roboto.sentinels.NotSetType]`): Resources to add. Each must be of the collection's resource type. A resource also listed in `remove_resources` ends up in the collection.
- **add_tags** (`Union[list[str], roboto.sentinels.NotSetType]`): Tags to add. A tag also listed in `remove_tags` ends up removed.
- **description** (`Optional[Union[roboto.sentinels.NotSetType, str]]`): Human-readable description of the collection. `None` clears it.
- **name** (`Optional[Union[roboto.sentinels.NotSetType, str]]`): Human-readable name of the collection. `None` clears it.
- **remove_resources** (`Union[list[roboto.domain.collections.record.CollectionResourceRef], roboto.sentinels.NotSetType]`): Resources to remove. Resources that are not members are ignored.
- **remove_tags** (`Union[list[str], roboto.sentinels.NotSetType]`): Tags to remove.
- **custom_fields_changeset** (`Optional[roboto.updates.CustomFieldChangeset]`): Changes to the collection's custom-field values. Each field it names must be a custom field defined for collections in the collection's organization, with status [`Ready`](/docs/reference/python-sdk/roboto/domain/custom_fields/record#roboto.domain.custom_fields.record.CustomFieldStatus.Ready). `None` leaves them unchanged.

**Returns**

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

**Raises**

- [`RobotoInvalidRequestException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoInvalidRequestException): A resource in `add_resources` is not of the collection's resource type.
- [`RobotoNotFoundException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoNotFoundException): A resource in `add_resources` does not exist, or is an event or session in another organization.
- [`RobotoUnauthorizedException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoUnauthorizedException): The caller's credential may only add to collections, and the call sets an argument other than `add_resources` or `add_tags`.
- [`RobotoIllegalArgumentException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoIllegalArgumentException): `custom_fields_changeset` names a field that is not a ready custom field for collections, or sets a value that does not match the field's type.

**Usage**

Rename the collection and tag it:

```python
collection = Collection.from_id("cl_12345")
collection.update(name="Highway test drives, 2024", add_tags=["reviewed"])
```

Swap one dataset for another:

```python
from roboto.domain.collections import CollectionResourceRef, CollectionResourceType
collection.update(
    add_resources=[
        CollectionResourceRef(resource_type=CollectionResourceType.Dataset, resource_id="ds_67890")
    ],
    remove_resources=[
        CollectionResourceRef(resource_type=CollectionResourceType.Dataset, resource_id="ds_12345")
    ],
)
```
