This page was generated from docs/user_guide/4-strava.ipynb. Interactive online version: Binder badge.

Loading your Strava running activities#

Many runners use third-party apps to track running activities. Runpandas supports loading activities directly from Strava Running Web App. In this notebook, we will extract this running data and analyse it locally using runpandas. We also take the opportunity to illustrate the runpandas methods for fetching and parsing data from Strava.

[1]:
%load_ext autoreload
%autoreload 2
import warnings
warnings.filterwarnings('ignore')

import runpandas
import os
import pandas as pd
pd.set_option('display.max_rows', 500)

We load the environment variables from our terminal or use a .env file with the STRAVA social app personal access tokens. You can create your own using the link instructions here: https://developers.strava.com/

[2]:
from dotenv import load_dotenv
load_dotenv()
[2]:
True

Firstly, import the runpandas StravaClient, create a Client instance, and read in the client ID and secret loaded previously. Next the one time authentication. The command client.authenticate_web will open a browser with a URL for the athlete to use to approve access to their data from the app.

The athlete is then prompted to log in to the Strava website and give consent to the requesting application. Once the user authorizes, it will store the access token and refresh token. From this point this access token, which lasts for 6 hours, will be what you need to access data. The client also save it locally so it can be re-read and refreshed as needed.

[3]:
client = runpandas.StravaClient()
client.authenticate_web()

Now we can start to look at our athlete’s activities; at the example below we request the activity with the a specified id.

[4]:
activity = runpandas.read_strava('7329257123')
activity.summary()
Unable to set attribute media_type on entity <ActivityPhotoPrimary id=None>
[4]:
Session                           Running: 18-06-2022 07:08:07
Total distance (meters)                                21389.8
Total ellapsed time                            0 days 02:02:20
Total moving time                              0 days 02:02:19
Average speed (km/h)                                       NaN
Average moving speed (km/h)                                NaN
Average pace (per 1 km)                                    NaN
Average pace moving (per 1 km)                             NaN
Average cadence                                        87.7889
Average moving cadence                                  87.847
Average heart rate                                     155.674
Average moving heart rate                              155.713
Average temperature                                        NaN
dtype: object