---
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#L33-L285)

Bases: `pydantic.BaseModel`

Use to declare an association between two Roboto entities.

**Parameters**

- **data** (`Any`)

**Attributes**

- **Association.URL_ENCODING_SEP** (`ClassVar[str]`) = `':'`

- **Association.association_id** (`str`): Roboto identifier

- **Association.association_type** (`AssociationType`): association_type is the Roboto domain entity type of the association.

- **Association.association_version** (`int | None`) = `None`: association_version is the Roboto domain entity version of the association, if it exists.

- **Association.parent** (`Association | None`) = `None`: The next level up in the hierarchy of this association. A message path's parent is its topic, a topic's parent is its file, and a file's parent is its dataset.

  The absense of a parent in an Association object doesn't necessarily mean that a parent doesn't exist; parents are only provided when they're easily computable in the context of a given request.

**Properties**

- **Association.dataset_id** (`str | None`): Return type: `Optional[str]`
- **Association.file_id** (`str | None`): Return type: `Optional[str]`
- **Association.is_dataset** (`bool`)
- **Association.is_device** (`bool`)
- **Association.is_file** (`bool`)
- **Association.is_msgpath** (`bool`)
- **Association.is_org** (`bool`)
- **Association.is_topic** (`bool`)
- **Association.message_path_id** (`str | None`): Return type: `Optional[str]`
- **Association.topic_id** (`str | None`): 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#L71-L100)

**Parameters**

- **associations** (`Optional[collections.abc.Collection[Association]]`)
- **dataset_ids** (`Optional[collections.abc.Collection[str]]`)
- **file_ids** (`Optional[collections.abc.Collection[str]]`)
- **topic_ids** (`Optional[collections.abc.Collection[str]]`)
- **message_path_ids** (`Optional[collections.abc.Collection[str]]`)
- **throw_on_empty** (`bool`)

**Returns**

- `list[Association]`

#### 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#L148-L149)

**Parameters**

- **dataset_id** (`str`)

**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#L152-L164)

Create an association with a device.

**Parameters**

- **universal_device_id** (`str`): The device's Roboto-assigned `dv_` ID ([`universal_device_id`](/reference/python-sdk/roboto/domain/devices/record#roboto.domain.devices.record.DeviceRecord.universal_device_id)), not its customer-chosen `device_id`.

**Returns**

- `Association`

**Usage**

```python
Association.device("dv_abc123")
# Association(association_id='dv_abc123', association_type=<AssociationType.Device: 'device'>, ...)
```

#### 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#L180-L185)

**Parameters**

- **file_id** (`str`)
- **version** (`Optional[int]`)

#### 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#L103-L145)

Infer the association type from the ID prefix.

Roboto IDs follow the pattern `{prefix}_{random_chars}` where the prefix indicates the entity type:

- `ds_` → Dataset
- `fl_` → File
- `tp_` → Topic
- `mp_` → MessagePath
- `dv_` → Device
- `og_` → Org

**Parameters**

- **association_id** (`str`): A Roboto entity ID with a recognized prefix.

**Returns**

- `Association`: An Association with the inferred type.

**Raises**

- [`RobotoIllegalArgumentException`](/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoIllegalArgumentException): If the ID prefix is not recognized.

**Usage**

```python
Association.from_id("ds_abc123")
# Association(association_id='ds_abc123', association_type=AssociationType.Dataset)
```

#### 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#L52-L68)

Reverse of Association::url_encode.

**Parameters**

- **encoded** (`str`)

**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#L39-L49)

**Parameters**

- **associations** (`collections.abc.Collection[Association]`)

**Returns**

- `collections.abc.Mapping[AssociationType, collections.abc.Sequence[Association]]`

#### 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#L192-L193)

**Parameters**

- **msgpath_id** (`str`)

**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#L167-L177)

Create an association with an organization.

**Parameters**

- **org_id** (`str`): The organization's ID.

**Returns**

- `Association`

**Usage**

```python
Association.org("og_abc123")
# Association(association_id='og_abc123', association_type=<AssociationType.Org: 'org'>, ...)
```

#### Association.topic()

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

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

**Parameters**

- **topic_id** (`str`)

#### Association.url_encode()

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

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

Association encoded in a URL path segment ready format.

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

Bases: `enum.Enum`

AssociationType is the Roboto domain entity type of the association.

**Attributes**

- **AssociationType.Dataset** = `'dataset'`
- **AssociationType.Device** = `'device'`
- **AssociationType.File** = `'file'`
- **AssociationType.MessagePath** = `'message_path'`
- **AssociationType.Org** = `'org'`
- **AssociationType.Topic** = `'topic'`
