---
sidebar:
  hidden: true
title: roboto.domain.tokens.token
---
## Module Contents

### Token

```python
class roboto.domain.tokens.token.Token(
    record: roboto.domain.tokens.record.TokenRecord,
    roboto_client: Optional[roboto.http.RobotoClient] = None,
)
```

`from roboto.domain.tokens import Token`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/tokens/token.py#L17-L107)

A token allows users and devices to authenticate requests to Roboto.

When a token is generated, a secret value is created which is shared with the user exactly once. This value is required for authentication, if lost a token can be deleted and a new token can be generated.

**Parameters**

- **record** (`roboto.domain.tokens.record.TokenRecord`)
- **roboto_client** (`Optional[roboto.http.RobotoClient]`)

**Properties**

- **Token.record** (`roboto.domain.tokens.record.TokenRecord`)
- **Token.token_id** (`str`)
- **Token.user_id** (`str`)

#### Token.create()

```python
@classmethod
def create(
    name: str,
    description: Optional[str] = None,
    expiry_days: int = 30,
    api_scopes: Optional[set[roboto.auth.scope.ApiScope]] = None,
    roboto_client: Optional[roboto.http.RobotoClient] = None,
) -> tuple[Token, str]
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/tokens/token.py#L29-L55)

This returns a tuple of the token and the one-time generated secret. After creation, you'll never be able to retrieve the secret again, so you should save it!

**Parameters**

- **name** (`str`)
- **description** (`Optional[str]`)
- **expiry_days** (`int`)
- **api_scopes** (`Optional[set[roboto.auth.scope.ApiScope]]`)
- **roboto_client** (`Optional[roboto.http.RobotoClient]`)

**Returns**

- `tuple[Token, str]`

#### Token.delete()

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

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/tokens/token.py#L95-L96)

**Returns**

- `None`

#### Token.disable()

```python
def disable() -> Token
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/tokens/token.py#L98-L100)

**Returns**

- `Token`

#### Token.enable()

```python
def enable() -> Token
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/tokens/token.py#L102-L104)

**Returns**

- `Token`

#### Token.for_self()

```python
@classmethod
def for_self(
    roboto_client: Optional[roboto.http.RobotoClient] = None,
) -> collections.abc.Collection[Token]
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/tokens/token.py#L64-L68)

**Parameters**

- **roboto_client** (`Optional[roboto.http.RobotoClient]`)

**Returns**

- `collections.abc.Collection[Token]`

#### Token.from_id()

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

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/tokens/token.py#L58-L61)

**Parameters**

- **token_id** (`str`)
- **roboto_client** (`Optional[roboto.http.RobotoClient]`)

**Returns**

- `Token`

#### Token.to_dict()

```python
def to_dict() -> dict[str, Any]
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/tokens/token.py#L106-L107)

**Returns**

- `dict[str, Any]`
