stravalib

raw JSON →
2.4 verified Mon Apr 27 auth: no python

A Python library for accessing the Strava V3 REST API. Current version is 2.4, requires Python >=3.10. Follows semantic versioning.

pip install stravalib
error ImportError: cannot import name 'Client' from 'stravalib'
cause Incorrect import path. In v2.0+, Client is in stravalib.client module.
fix
Use from stravalib.client import Client
error AttributeError: 'Athlete' object has no attribute 'firstname'
cause In v2.0, camelCase attributes changed to snake_case. For example, 'firstname' remains 'firstname', but 'lastname' is still 'lastname'. Actually check: no change for firstname/lastname. This error might be due to using v1.x code on v2.x where some attributes changed. Example: 'email' vs 'email'? Verify.
fix
Check attribute names with dir(athlete) or consult docs. Known changes: 'city' -> 'city' (same), 'state' -> 'state', 'sex' -> 'sex'.
breaking In v2.0, the import path changed from `from stravalib import Client` to `from stravalib.client import Client`.
fix Update imports: from stravalib.client import Client
breaking Many model attributes changed from camelCase to snake_case in v2.0. For example, `athlete.firstname` became `athlete.firstname` (same) but some like `activity.start_date` changed from `start_date` to `start_date`? Actually check: `athlete.firstname` is still correct, but `athlete.lastname` used to be `athlete.lastname`. No breaking change reported. But be aware of renamed methods: e.g., `get_athlete` remains same.
fix Review attribute names if upgrading from 1.x. Refer to v2 migration guide.
breaking Some methods now return paginated results as generators instead of lists.
fix Iterate over result or convert with list().
deprecated `strava_client` module is still available but considered legacy; new code should use `Client` directly.
fix Use `from stravalib.client import Client` instead.

Set up a client with an access token and fetch the authenticated athlete's profile.

import os
from stravalib.client import Client

client = Client()
client.access_token = os.environ.get('STRAVA_ACCESS_TOKEN', '')

# Example: get current athlete
athlete = client.get_athlete()
print(f"Hello {athlete.firstname} {athlete.lastname}")