# ovok_sdk.resources.session

Canonical page: https://docs.ovok.com/python-sdk/reference/resources/session

The `ovok.session` namespace: the current user session and the accounts saved on this client.

## SavedAccountsResource [#savedaccountsresource]

```python
SavedAccountsResource(http: HttpClient, session: UserSession | None)
```

The accounts signed in to on this client; access it as `ovok.session.saved_accounts`.

Every sign-in saves its account under `ovok:<tenant_code>:saved-accounts` in `storage`.

**Parameters**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `http` | `HttpClient` |  | The client's HTTP client. |
| `session` | `UserSession \| None` |  | The user session; None for a machine client. |

### list() [#list]

```python
list() -> list[SavedAccount]
```

List the saved accounts, newest first.

**Returns**

- `list[SavedAccount]`: The accounts, with the signed-in one marked `active`.

**Raises**

- `OvokConfigError`: The client signs in with `client_secret`.

### switch() [#switch]

```python
switch(account_id: str) -> None
```

Make a saved account the signed-in one.

**Parameters**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `account_id` | `str` |  | The account's `id`, its profile reference. |

**Raises**

- `OvokAccountError`: The account is not saved, or its session expired.
- `OvokConfigError`: The client signs in with `client_secret`.

### remove() [#remove]

```python
remove(account_id: str, *, options: RequestOptions | None = None) -> None
```

Sign a saved account out on the server and forget it.

Removing the signed-in account switches to the next live one, or signs out.

**Parameters**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `account_id` | `str` |  | The account's `id`, its profile reference. |
| `options` | `RequestOptions \| None` | `None` | Per-request options; `timeout` overrides the client's. |

**Raises**

- `OvokAccountError`: The account is not saved.
- `OvokConfigError`: The client signs in with `client_secret`.
- `OvokError`: The server could not end the account's session.

## SessionResource [#sessionresource]

```python
SessionResource(http: HttpClient, session: UserSession | None)
```

The current user session and the accounts saved on this client.

Created by `Ovok`; access it as `ovok.session`.

**Parameters**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `http` | `HttpClient` |  | The client's HTTP client. |
| `session` | `UserSession \| None` |  | The user session; None for a machine client. |

### current() [#current]

```python
current() -> Session | None
```

Return the stored session.

**Returns**

- `Session | None`: The session, or None when no user is signed in or the client is a machine client.

### on_change() [#on_change]

```python
on_change(listener: SessionChangeListener) -> Callable[[], None]
```

Call `listener` with the new session, or None, on sign-in, account switch and sign-out.

**Parameters**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `listener` | `SessionChangeListener` |  | Called with the session that is now current. |

**Returns**

- `Callable[[], None]`: A function that stops the calls; for a machine client it does nothing.
