# Session

> User sessions: a short-lived token for one user, safe to hand to a browser.

```python
session = user.session(scopes=["agents", "humans"], ttl_s=3600)
token = session.token                       # your frontend uses it as its API key

client = noclick.Client.for_session(session)     # or act as that user from Python
```

## noclick.Session

```python
class Session
```

A token pinned to one user with a subset of the minting key's scopes.
Its `repr` never shows the token.

| Attribute | Type | Description |
| --- | --- | --- |
| `token` | `str` |  |
| `id` | `str | None` |  |
| `user_id` | `str | None` |  |
| `scopes` | `list[str]` |  |
| `expires_at` | `Any` |  |
| `raw` | `dict[str, Any]` | The response JSON exactly as the API sent it. |
| `base_url` | `str | None` |  |
| `expired` | `bool` | Whether `expires_at` has passed (by this machine's clock). |

### Session.client

```python
session.client(**kwargs) -> Any
```

A client that acts as this session: `noclick.Agent.list(client=session.client())`.

Parameters:

- `kwargs` (`Any`)

Returns: `Any` A client holding the session's token, pointed at the API the session came from. Every
call it makes acts as the session's user, with the session's scopes.

Usage:

```python
user = noclick.User.from_id("user_42")
session = user.session(["agents"], ttl_s=600)
as_ana = session.client()
noclick.Agent.list(client=as_ana)   # Ana's agents and the shared ones, nothing else
```
