nolito.client module

class nolito.client.NolioApiClient(settings=None, oauth=None, session=None)[source]

Bases: object

HTTP client for the Nolio API

Parameters:
  • settings (NolitoSettings | None) – Settings for this instance of the API. Create with NolitoSettings.from_env() if None. Defaults to None.

  • oauth (OAuthManager | None) – OAuthManager to use for the API. Created automatically from settings and system keyring if None. Defaults to None.

  • session (Session | None) – requests.Session object to attach to the client. Plain session is created from scratch if None. Defaults to None.

create_training(training)[source]

Create a training and register its Nolio and partner identifiers.

A missing Training.id_partner is allocated locally and stored in SQLite beside Nolito’s token metadata. Explicit partner IDs are also registered, allowing later updates and deletes to use the same ID.

Parameters:

training (Training) – Training object with all the workout information.

Return type:

Training

Returns:

The created training.

delete_training(training)[source]

Delete a completed training created by this OAuth application.

Parameters:
  • id_partner – Integrator-owned training identifier.

  • athlete_id – Optional athlete owning the training.

Return type:

None

Returns:

None after Nolio’s empty successful response.

Raises:

NolioApiError – If Nolio returns an unexpected response format.

get(endpoint, params=None)[source]

Send a GET request to any Nolio API endpoint

The list of endpoints is available on the Nolio API wiki.

Parameters:
  • endpoint (str) – The name of the endpoint (everything that comes after get/).

  • params (dict[str, Any] | None) – Optional parameters for the request.

Return type:

list | dict

Returns:

The decoded json response.

get_athlete()[source]

Get the user information for the logged-in athlete

Return type:

dict[str, Any]

Returns:

The json dictionary with user information.

get_daily_trainings(day=None)[source]

Get trainings for a given day (today by default)

Parameters:

day (date | str | None) – The day for which trainings are returned. Defaults to today when None.

Return type:

TrainingSet

Returns:

List of trainings planned on the day

get_metrics()[source]

Get health metrics for the logged-in user

These include FTP, VO2 Max, sleep, etc. It retains only the latest for each.

Return type:

dict

Returns:

The dictionary with metrics

get_planned_trainings(training_id=None, start=None, end=None, limit=None)[source]

Get planned trainings for a given time frame.

The returned list is ordered in decreasing order of date.

Front-end for /get/planned/training/.

Parameters:
  • training_id (int | str | None) – Return only the training corresponding to this ID.

  • start (date | str | None) – Start date (defaults to None)

  • end (date | str | None) – End date (defaults to None)

  • limit (int | None) – Maximum number of trainings (API default is 30)

Return type:

TrainingSet

Returns:

Training set

get_registered_training(id_partner)[source]

Return a registered training by its partner ID.

Raises:

KeyError – If the partner ID is not registered.

Return type:

Training

list_registered_trainings()[source]

Return all registered trainings in ascending partner-ID order.

Return type:

TrainingSet

post(endpoint, params=None, payload=None)[source]

Send a POST request to any Nolio API endpoint

The list of endpoints is available on the Nolio API wiki.

Parameters:
  • endpoint (str) – The full name of the endpoint

  • params (dict[str, Any] | None) – Optional parameters for the request.

  • payload (dict | None) – Optional json payload for the request

Return type:

dict | None

Returns:

The response content (dictionary if valid json, None if empty)

register_training(training)[source]

Register a complete local training snapshot.

Parameters:

training (Training) – Training to register. It must have an id_partner.

Raises:
  • ValueError – If training.id_partner is missing or invalid.

  • NolioApiError – If the partner ID is already registered.

Return type:

None

update_training(training)[source]

Create a completed training.

Training can be planned or non-planned. The Training.planned attribute will be used to determine this.

Parameters:

training (Training) – Training object with all the workout information.

Return type:

Training

Returns:

The created training.