# Migrating from v5.x to v6.x

This document aims to assist you in migrating from analytix v5.x to v6.0.
It does not aim to be entirely comprehensive, but instead cover the biggest changes to users.
All changed classes and methods have change descriptions in their docstrings.

!!! warning
    Version 6 is still in development.
    It is recommended you do not use it production yet.

## Authorisation

### Tokens

Many of the authorisation methods previously bound to the `Client` are now bound to `Tokens` instead:

* `client.token_is_valid()` ➔ `not tokens.expired`
* `client.scopes_are_sufficient()` ➔ `tokens.are_scoped_for()`
* `client.decode_id_token()` ➔ `tokens.decoded_id_token`

Additionally, the `tokens.expires_in` now returns an accurate number of seconds until token expiry instead of being stuck with the value loaded into it.

### Scopes

Some changes have been made to scopes to increase clarity:

* `Scopes.ALL` ➔ `Scopes.ALL_READONLY`
* `Scopes.ALL | Scopes.ALL_JWT` ➔ `Scopes.ALL`

## Sessions

Sessions serve as a much less clunky implementation of shards, allowing authorisation credentials to be reused in multiple requests while also keeping everything contained within the client.

Instead of:
```py
with client.shard() as shard:
    for year in range(2019, 2024):
        shard.fetch_report(
            start_date=dt.date(year, 1, 1),
            end_date=dt.date(year, 12, 31),
        )
```

You should now do:
```py
with client.session():
    for year in range(2019, 2024):
        client.fetch_report(
            start_date=dt.date(year, 1, 1),
            end_date=dt.date(year, 12, 31),
        )
```
