Exercises Endpoint
polar_flow.endpoints.exercises.ExercisesEndpoint
Exercises endpoint handler.
This class provides methods for accessing training session data from the Polar AccessLink API. Note: Only last 30 days of exercises are available.
__init__(client)
Initialize exercises endpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
PolarFlow
|
Parent PolarFlow client instance |
required |
export_gpx(exercise_id)
async
Export exercise as GPX (GPS Exchange Format).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exercise_id
|
str
|
Unique exercise identifier |
required |
Returns:
| Type | Description |
|---|---|
str
|
GPX XML content as string |
Raises:
| Type | Description |
|---|---|
NotFoundError
|
If exercise not found |
AuthenticationError
|
If access token is invalid |
Example
async with PolarFlow(access_token="token") as client:
gpx_xml = await client.exercises.export_gpx(exercise_id="123")
with open("exercise.gpx", "w") as f:
f.write(gpx_xml)
export_tcx(exercise_id)
async
Export exercise as TCX (Training Center XML) format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exercise_id
|
str
|
Unique exercise identifier |
required |
Returns:
| Type | Description |
|---|---|
str
|
TCX XML content as string |
Raises:
| Type | Description |
|---|---|
NotFoundError
|
If exercise not found |
AuthenticationError
|
If access token is invalid |
Example
async with PolarFlow(access_token="token") as client:
tcx_xml = await client.exercises.export_tcx(exercise_id="123")
with open("exercise.tcx", "w") as f:
f.write(tcx_xml)
get(exercise_id)
async
Get detailed exercise data by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exercise_id
|
str
|
Unique exercise identifier |
required |
Returns:
| Type | Description |
|---|---|
Exercise
|
Detailed exercise data |
Raises:
| Type | Description |
|---|---|
NotFoundError
|
If exercise not found |
AuthenticationError
|
If access token is invalid |
Example
async with PolarFlow(access_token="token") as client:
exercise = await client.exercises.get(exercise_id="123")
print(f"Calories: {exercise.calories}")
print(f"Distance: {exercise.distance_km} km")
get_samples(exercise_id)
async
Get exercise samples (HR, speed, cadence, altitude, etc.).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exercise_id
|
str
|
Unique exercise identifier |
required |
Returns:
| Type | Description |
|---|---|
ExerciseSamples
|
Exercise samples data |
Raises:
| Type | Description |
|---|---|
NotFoundError
|
If exercise not found |
AuthenticationError
|
If access token is invalid |
Example
async with PolarFlow(access_token="token") as client:
samples = await client.exercises.get_samples(exercise_id="123")
hr_sample = samples.get_sample_by_type("HEARTRATE")
if hr_sample:
print(f"HR values: {hr_sample.values[:5]}...") # First 5 values
get_zones(exercise_id)
async
Get heart rate zones for exercise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exercise_id
|
str
|
Unique exercise identifier |
required |
Returns:
| Type | Description |
|---|---|
ExerciseZones
|
Heart rate zones data |
Raises:
| Type | Description |
|---|---|
NotFoundError
|
If exercise not found |
AuthenticationError
|
If access token is invalid |
Example
async with PolarFlow(access_token="token") as client:
zones = await client.exercises.get_zones(exercise_id="123")
for zone in zones.zones:
print(f"Zone {zone.index}: {zone.in_zone_minutes} minutes "
f"({zone.lower_limit}-{zone.upper_limit} BPM)")
list()
async
List all available exercises (last 30 days).
Returns:
| Type | Description |
|---|---|
list[Exercise]
|
List of exercises from the last 30 days |
Raises:
| Type | Description |
|---|---|
AuthenticationError
|
If access token is invalid |
Example
async with PolarFlow(access_token="token") as client:
exercises = await client.exercises.list()
for ex in exercises:
print(f"{ex.start_time}: {ex.sport} - {ex.duration_minutes} min")