---
sidebar:
  label: roboto.association
  order: 4
title: roboto.association
---
## Module Contents

### Association

```python
class roboto.association.Association(/, **data: Any)
```

`from roboto import Association`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/association.py#L47-L378)

Bases: `pydantic.BaseModel`

A reference to one Roboto entity, such as a dataset, file, or topic, by its type and ID.

SDK methods take associations to name the entities they act on or annotate, such as the datasets and files an event annotates or the file whose topic to fetch. Build one with a class method such as `dataset` or `from_id`.

**Parameters**

- **data** (`Any`)

**Attributes**

- **Association.URL_ENCODING_SEP** (`ClassVar[str]`) = `':'`: Separator between the type, ID, and version in an encoded association.

- **Association.association_id** (`str`): ID of the entity the association refers to.

- **Association.association_type** (`AssociationType`): Kind of entity `association_id` identifies.

- **Association.association_version** (`int | None`) = `None`: Version of the entity, or `None` if the association names no version. Only files have versions.

- **Association.parent** (`Association | None`) = `None`: Association with the entity one level up: a message path's topic, a topic's file, or a file's dataset.

  `None` does not mean the entity has no parent. Roboto sets `parent` only in some responses, such as the `associations` of an event.

**Properties**

- **Association.dataset_id** (`str | None`): ID of the dataset the association refers to or its `parent` chain reaches, or `None` if neither.

  Return type: `Optional[str]`

- **Association.file_id** (`str | None`): ID of the file the association refers to or its `parent` chain reaches, or `None` if neither.

  Return type: `Optional[str]`

- **Association.is_dataset** (`bool`): Whether the association is with a dataset.

- **Association.is_device** (`bool`): Whether the association is with a device.

- **Association.is_device_type** (`bool`): Whether the association is with a device type.

- **Association.is_file** (`bool`): Whether the association is with a file.

- **Association.is_msgpath** (`bool`): Whether the association is with a message path.

- **Association.is_org** (`bool`): Whether the association is with an organization.

- **Association.is_topic** (`bool`): Whether the association is with a topic.

- **Association.message_path_id** (`str | None`): ID of the message path the association refers to, or `None` if it refers to another kind of entity.

  Return type: `Optional[str]`

- **Association.topic_id** (`str | None`): ID of the topic the association refers to or its `parent` chain reaches, or `None` if neither.

  Return type: `Optional[str]`

#### Association.coalesce()

```python
@classmethod
def coalesce(
    associations: Optional[collections.abc.Collection[Association]] = None,
    dataset_ids: Optional[collections.abc.Collection[str]] = None,
    file_ids: Optional[collections.abc.Collection[str]] = None,
    topic_ids: Optional[collections.abc.Collection[str]] = None,
    message_path_ids: Optional[collections.abc.Collection[str]] = None,
    throw_on_empty: bool = False,
) -> list[Association]
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/association.py#L111-L159)

Combine associations and lists of entity IDs into one list of associations.

Duplicates are kept.

**Parameters**

- **associations** (`Optional[collections.abc.Collection[Association]]`): Associations to include as given. `None` includes none.
- **dataset_ids** (`Optional[collections.abc.Collection[str]]`): IDs of datasets to include. `None` includes none.
- **file_ids** (`Optional[collections.abc.Collection[str]]`): IDs of files to include, each with no version. `None` includes none.
- **topic_ids** (`Optional[collections.abc.Collection[str]]`): IDs of topics to include. `None` includes none.
- **message_path_ids** (`Optional[collections.abc.Collection[str]]`): IDs of message paths to include. `None` includes none.
- **throw_on_empty** (`bool`): Whether to raise `RobotoInvalidRequestException` when the result would be empty.

**Returns**

- `list[Association]`: `associations`, then one association for each dataset ID, file ID, message path ID, and topic ID, in that order.

**Raises**

- [`RobotoInvalidRequestException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoInvalidRequestException): `throw_on_empty` is true and every other argument is empty or `None`.

#### Association.dataset()

```python
@classmethod
def dataset(dataset_id: str) -> Association
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/association.py#L201-L207)

Build an association with a dataset.

**Parameters**

- **dataset_id** (`str`): ID of the dataset, beginning with `ds_`.

**Returns**

- `Association`

#### Association.device()

```python
@classmethod
def device(universal_device_id: str) -> Association
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/association.py#L210-L218)

Build an association with a device.

**Parameters**

- **universal_device_id** (`str`): ID of the device, beginning with `dv_` ([`universal_device_id`](/docs/reference/python-sdk/roboto/domain/devices/record#roboto.domain.devices.record.DeviceRecord.universal_device_id)), not the `device_id` the organization gave it.

**Returns**

- `Association`

#### Association.device_type()

```python
@classmethod
def device_type(device_type_id: str) -> Association
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/association.py#L221-L227)

Build an association with a device type.

**Parameters**

- **device_type_id** (`str`): ID of the device type, beginning with `dt_`, not its name.

**Returns**

- `Association`

#### Association.file()

```python
@classmethod
def file(file_id: str, version: Optional[int] = None)
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/association.py#L239-L250)

Build an association with a file, or with one version of it.

**Parameters**

- **file_id** (`str`): ID of the file, beginning with `fl_`.
- **version** (`Optional[int]`): Version of the file. `None` names no version.

#### Association.from_id()

```python
@classmethod
def from_id(association_id: str) -> Association
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/association.py#L162-L198)

Build an association from an entity's ID, taking its type from the ID's prefix.

The prefixes and the types they map to:

- `ds_`: datasets.
- `fl_`: files, with no version.
- `tp_`: topics.
- `mp_`: message paths.
- `dv_`: devices.
- `og_`: organizations.
- `dt_`: device types.

**Parameters**

- **association_id** (`str`): ID of a dataset, file, topic, message path, device, organization, or device type.

**Raises**

- [`RobotoIllegalArgumentException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoIllegalArgumentException): `association_id` begins with none of these prefixes.

**Returns**

- `Association`

#### Association.from_url_encoded_value()

```python
@classmethod
def from_url_encoded_value(encoded: str) -> Association
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/association.py#L81-L108)

Parse an association from the form `url_encode` returns.

The parsed association has no `parent`.

**Parameters**

- **encoded** (`str`): URL-quoted `<type>:<id>` or `<type>:<id>:<version>`, where `<type>` is an `AssociationType` value such as `file`.

**Raises**

- [`RobotoIllegalArgumentException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoIllegalArgumentException): `<type>` is not an `AssociationType` value.
- `ValueError`: `encoded` has no `:` separator, or its version is not an integer.

**Returns**

- `Association`

#### Association.group_by_type()

```python
@staticmethod
def group_by_type(
    associations: collections.abc.Collection[Association],
) -> collections.abc.Mapping[AssociationType, collections.abc.Sequence[Association]]
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/association.py#L59-L78)

Group associations by their type.

**Parameters**

- **associations** (`collections.abc.Collection[Association]`): Associations to group.

**Returns**

- `collections.abc.Mapping[AssociationType, collections.abc.Sequence[Association]]`: Each type present in `associations`, mapped to its associations in their input order. A type with no associations is absent.

#### Association.msgpath()

```python
@classmethod
def msgpath(msgpath_id: str) -> Association
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/association.py#L262-L268)

Build an association with a message path.

**Parameters**

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

**Returns**

- `Association`

#### Association.org()

```python
@classmethod
def org(org_id: str) -> Association
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/association.py#L230-L236)

Build an association with an organization.

**Parameters**

- **org_id** (`str`): ID of the organization, beginning with `og_`.

**Returns**

- `Association`

#### Association.topic()

```python
@classmethod
def topic(topic_id: str)
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/association.py#L253-L259)

Build an association with a topic.

**Parameters**

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

#### Association.url_encode()

```python
def url_encode() -> str
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/association.py#L362-L378)

Encode the association as one URL path segment.

The segment is `<type>:<id>`, or `<type>:<id>:<version>` when `association_version` is set, where `<type>` is the `AssociationType` value such as `file`. It is quoted with `urllib.parse.quote_plus`, so each `:` becomes `%3A`. `parent` is left out. `from_url_encoded_value` parses it back.

**Returns**

- `str`

### AssociationType

```python
class roboto.association.AssociationType(*args, **kwds)
```

`from roboto import AssociationType`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/association.py#L22-L44)

Bases: `enum.Enum`

Kind of Roboto entity an association refers to.

**Attributes**

- **AssociationType.Dataset** = `'dataset'`: Datasets ([`Dataset`](/docs/reference/python-sdk/roboto/domain/datasets/dataset#roboto.domain.datasets.dataset.Dataset)).
- **AssociationType.Device** = `'device'`: Devices ([`Device`](/docs/reference/python-sdk/roboto/domain/devices/device#roboto.domain.devices.device.Device)).
- **AssociationType.DeviceType** = `'device_type'`: Device types (`roboto.domain.device_types.DeviceType`).
- **AssociationType.File** = `'file'`: Files ([`File`](/docs/reference/python-sdk/roboto/domain/files/file#roboto.domain.files.file.File)).
- **AssociationType.MessagePath** = `'message_path'`: Message paths ([`MessagePath`](/docs/reference/python-sdk/roboto/domain/topics/message_path#roboto.domain.topics.message_path.MessagePath)).
- **AssociationType.Org** = `'org'`: Organizations ([`Org`](/docs/reference/python-sdk/roboto/domain/orgs/org#roboto.domain.orgs.org.Org)).
- **AssociationType.Topic** = `'topic'`: Topics ([`Topic`](/docs/reference/python-sdk/roboto/domain/topics/topic#roboto.domain.topics.topic.Topic)).
