# Session

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

`ovok.session` holds the signed-in user's session and every account signed in to on this client. Each sign-in saves its account under `ovok:<tenant_code>:saved-accounts` in `storage`, next to the session.

## React to sign-in and sign-out [#react-to-sign-in-and-sign-out]

```python
stop = ovok.session.on_change(lambda session: print(session.profile if session else "signed out"))

stop()
```

- The listener gets the new session on sign-in and account switch, and `None` on sign-out.
- `current` returns the stored session, or `None`.

## Switch accounts [#switch-accounts]

```python
for account in ovok.session.saved_accounts.list():
    print(account.id, account.active, account.expired)

ovok.session.saved_accounts.switch("Patient/123")
```

- `switch` raises `OvokAccountError` with code `account_not_found` or `account_expired`. An account expires when its refresh token is refused; signing in again renews it.
- `remove` ends the account's session on the server with that account's own token, then forgets it. Removing the active account switches to the next live one, or signs out.
- A machine client has no session: `current` returns `None` and `saved_accounts` raises `OvokConfigError`.

## See also [#see-also]

- [Keep users signed in](/python-sdk/guides/keep-users-signed-in)
- [`SessionResource` reference](/python-sdk/reference/resources/session#sessionresource)
