---
sidebar:
  label: roboto.principal
  order: 19
title: roboto.principal
---
## Module Contents

### RobotoPrincipal

```python
class roboto.principal.RobotoPrincipal(/, **data: Any)
```

`from roboto.principal import RobotoPrincipal`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/principal.py#L33-L131)

Bases: `pydantic.BaseModel`

A principal: an identity that acts in Roboto or owns a resource, such as a user, a device, or an organization.

Fields such as a dataset's `created_by` hold a principal in its string form, `<type>:<id>`, which `from_string` parses. Creating a principal, directly or with any method of this class, raises `pydantic.ValidationError` when its ID contains a colon.

**Parameters**

- **data** (`Any`)

**Attributes**

- **RobotoPrincipal.id** (`str`): ID of the principal, unique among principals of its type.

  For users, organizations, invocations and integrations, this is the resource's own ID. A device's ID is unique only within its organization, so a device principal's ID is `<device_id>@<org_id>`: device `sn001` in organization `og_12345` has the ID `sn001@og_12345`.

- **RobotoPrincipal.ptype** (`RobotoPrincipalType`): Type of the principal, such as user or device.

#### RobotoPrincipal.for_device()

```python
@classmethod
def for_device(device_id: str, org_id: str) -> RobotoPrincipal
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/principal.py#L64-L71)

Build the principal of a device, whose ID is `<device_id>@<org_id>`.

**Parameters**

- **device_id** (`str`): ID the organization gave the device, such as a serial number.
- **org_id** (`str`): ID of the organization that owns the device.

**Returns**

- `RobotoPrincipal`

#### RobotoPrincipal.for_integration()

```python
@classmethod
def for_integration(integration_id: str) -> RobotoPrincipal
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/principal.py#L74-L80)

Build the principal of an integration.

**Parameters**

- **integration_id** (`str`): ID of the integration, such as `slack`.

**Returns**

- `RobotoPrincipal`

#### RobotoPrincipal.for_invocation()

```python
@classmethod
def for_invocation(invocation_id: str) -> RobotoPrincipal
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/principal.py#L83-L89)

Build the principal of an invocation of an action.

**Parameters**

- **invocation_id** (`str`): ID of the invocation, beginning with `iv_`.

**Returns**

- `RobotoPrincipal`

#### RobotoPrincipal.for_org()

```python
@classmethod
def for_org(org_id: str) -> RobotoPrincipal
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/principal.py#L92-L98)

Build the principal of an organization.

**Parameters**

- **org_id** (`str`): ID of the organization.

**Returns**

- `RobotoPrincipal`

#### RobotoPrincipal.for_user()

```python
@classmethod
def for_user(user_id: str) -> RobotoPrincipal
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/principal.py#L101-L107)

Build the principal of a user.

**Parameters**

- **user_id** (`str`): ID of the user, which for a person is their email address.

**Returns**

- `RobotoPrincipal`

#### RobotoPrincipal.from_string()

```python
@classmethod
def from_string(serialized_principal: str) -> RobotoPrincipal
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/principal.py#L110-L127)

Parse a principal from its `<type>:<id>` string form, as `str()` of a principal returns it.

Text after a second colon is dropped: `user:a:b` parses as user `a`.

**Parameters**

- **serialized_principal** (`str`): Principal in its string form, such as `user:<user_id>` or `device:<device_id>@<org_id>`.

**Raises**

- `ValueError`: The text before the first colon, or the whole string when it has none, is not a `RobotoPrincipalType` value.
- `IndexError`: The string is a type with no colon after it, such as `user`.

**Returns**

- `RobotoPrincipal`

#### RobotoPrincipal.validate_id()

```python
def validate_id(value: str) -> str
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/principal.py#L53-L61)

Reject an ID that contains a colon, which separates the type from the ID in the string form.

Pydantic calls this while it builds a principal.

**Parameters**

- **value** (`str`)

**Returns**

- `str`

### RobotoPrincipalType

```python
class roboto.principal.RobotoPrincipalType
```

`from roboto.principal import RobotoPrincipalType`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/principal.py#L14-L30)

Bases: `roboto.compat.StrEnum`

Type of a principal: the kind of identity a `RobotoPrincipal` names.

**Attributes**

- **RobotoPrincipalType.Device** = `'device'`: Devices ([`Device`](/docs/reference/python-sdk/roboto/domain/devices/device#roboto.domain.devices.device.Device)).
- **RobotoPrincipalType.Integration** (`Integrations`) = `'integration'`: Roboto features, such as the Slack app, that record changes under their own identity.
- **RobotoPrincipalType.Invocation** = `'invocation'`: Invocations of actions ([`Invocation`](/docs/reference/python-sdk/roboto/domain/actions/invocation#roboto.domain.actions.invocation.Invocation)).
- **RobotoPrincipalType.Org** = `'org'`: Organizations ([`Org`](/docs/reference/python-sdk/roboto/domain/orgs/org#roboto.domain.orgs.org.Org)).
- **RobotoPrincipalType.User** = `'user'`: Users ([`User`](/docs/reference/python-sdk/roboto/domain/users/user#roboto.domain.users.user.User)).
