Skip to content

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_fit(exercise_id) async

Export exercise as FIT (Flexible and Interoperable Data Transfer) format.

FIT is a binary format, so this returns raw bytes.

Parameters:

Name Type Description Default
exercise_id str

Unique exercise identifier

required

Returns:

Type Description
bytes

FIT file content as bytes

Raises:

Type Description
NotFoundError

If exercise not found

AuthenticationError

If access token is invalid

Example
async with PolarFlow(access_token="token") as client:
    fit_data = await client.exercises.export_fit(exercise_id="123")
    with open("exercise.fit", "wb") as f:
        f.write(fit_data)

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, *, samples=False, zones=False, route=False) async

Get detailed exercise data by ID.

Parameters:

Name Type Description Default
exercise_id str

Unique exercise identifier

required
samples bool

Include raw sample series (HR, speed, cadence, ...)

False
zones bool

Include heart-rate-zone breakdown

False
route bool

Include GPS route points

False

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", samples=True, zones=True, route=True
    )
    print(f"Calories: {exercise.calories}")
    print(f"Route points: {len(exercise.route or [])}")

get_route(exercise_id) async

Get GPS route points for exercise.

Uses the route=true query flag on the exercise endpoint to return the route as structured JSON (see also :meth:export_gpx / :meth:export_tcx for file formats).

Parameters:

Name Type Description Default
exercise_id str

Unique exercise identifier

required

Returns:

Type Description
list[RoutePoint]

List of GPS route points (empty if the exercise has no route)

Raises:

Type Description
NotFoundError

If exercise not found

AuthenticationError

If access token is invalid

Example
async with PolarFlow(access_token="token") as client:
    points = await client.exercises.get_route(exercise_id="123")
    if points:
        print(f"Start: {points[0].latitude}, {points[0].longitude}")

get_samples(exercise_id) async

Get exercise samples (HR, speed, cadence, altitude, etc.).

Uses the samples=true query flag on the exercise endpoint — the /samples sub-path only ever existed on the deprecated transaction flow and 404s for hashed exercise IDs.

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.

Uses the zones=true query flag on the exercise endpoint — the /zones sub-path only ever existed on the deprecated transaction flow and 404s for hashed exercise IDs.

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(*, samples=False, zones=False, route=False) async

List all available exercises (last 30 days).

Parameters:

Name Type Description Default
samples bool

Include raw sample series in each exercise

False
zones bool

Include heart-rate-zone breakdown in each exercise

False
route bool

Include GPS route points in each exercise

False

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")