nolito.client module¶
- class nolito.client.NolioApiClient(settings=None, oauth=None, session=None)[source]¶
Bases:
objectHTTP client for the Nolio API
- Parameters:
settings (
NolitoSettings|None) – Settings for this instance of the API. Create withNolitoSettings.from_env()ifNone. Defaults toNone.oauth (
OAuthManager|None) – OAuthManager to use for the API. Created automatically from settings and system keyring ifNone. Defaults toNone.session (
Session|None) – requests.Session object to attach to the client. Plain session is created from scratch ifNone. Defaults toNone.
- create_training(training)[source]¶
Create a training and register its Nolio and partner identifiers.
A missing
Training.id_partneris 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.
- 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:
Noneafter Nolio’s empty successful response.- Raises:
NolioApiError – If Nolio returns an unexpected response format.
- get(endpoint, params=None)[source]¶
Send a
GETrequest to any Nolio API endpointThe list of endpoints is available on the Nolio API wiki.
- Parameters:
endpoint (
str) – The name of the endpoint (everything that comes afterget/).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 whenNone.- Return type:
- 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 toNone)end (
date|str|None) – End date (defaults toNone)limit (
int|None) – Maximum number of trainings (API default is 30)
- Return type:
- 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:
- list_registered_trainings()[source]¶
Return all registered trainings in ascending partner-ID order.
- Return type:
- post(endpoint, params=None, payload=None)[source]¶
Send a
POSTrequest to any Nolio API endpointThe list of endpoints is available on the Nolio API wiki.
- Parameters:
endpoint (
str) – The full name of the endpointparams (
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 anid_partner.- Raises:
ValueError – If
training.id_partneris missing or invalid.NolioApiError – If the partner ID is already registered.
- Return type:
None