Skip to main content

stravaio

Python client for Strava API with a focus on fluent data handling

PyPI version Build Status

Example

Build your own Year in Strava poster Jupyter notebook

Install

pipenv install stravaio

or

pip install stravaio

Latest dev version could be installed as:

pipenv install git+https://github.com/sladkovm/stravaio.git#egg=stravaio

Before use

You need STRAVA_ACCESS_TOKEN with activity level permissions to make use of this package.

The easiest way to get the token is to use the stravaio library itself:

from stravaio import strava_oauth2

strava_oauth2(client_id=STRAVA_CLIENT_ID, client_secret=STRAVA_CLIENT_SECRET)

You will be redirected to the default system browser, where the authorization flow must be completed. In the background the local webserver will be running and listening to the data returned by Strava.

Both STRAVA_CLIENT_ID and STRAVA_CLIENT_SECRET are optional arguments if they are set as the environment variables.

Another way is to head to the strava-oauth library for help. There you will find a link to the public webserver that can be used for completing the Strava authorizatio flow.

When the token is fetched it is handy to store it as an environment variable. Otherwise it should be passed explicitely to the StravaIO constructor.

export STRAVA_ACCESS_TOKEN=<strava_access_token>

Use

from stravaio import StravaIO

# If the token is stored as an environment varible it is not neccessary
# to pass it as an input parameters
client = StravaIO(access_token=STRAVA_ACCESS_TOKEN)

Athlete

# Get logged in athlete (e.g. the owner of the token)
# Returns a stravaio.Athlete object that wraps the
# [Strava DetailedAthlete](https://developers.strava.com/docs/reference/#api-models-DetailedAthlete)
# with few added data-handling methods
athlete = client.get_logged_in_athlete()

# Dump athlete into a JSON friendly dict (e.g. all datetimes are converted into iso8601)
athlete_dict = athlete.to_dict()

# Store athlete infor as a JSON locally (~/.stravadata/athlete_<id>.json)
athlete.store_locally()

# Get locally stored athletes (returns a generator of dicts)
local_athletes = client.local_athletes()

Activities

# Returns a stravaio.Activity object that wraps the 
# [Strava DetailedActivity](https://developers.strava.com/docs/reference/#api-models-DetailedActivity)
activity = client.get_activity_by_id(2033203247)

# Dump activity into a JSON friendly dict
activity_dict = activity.to_dict()

# Store activity locally (~/.stravadata/activities_<athlete_id>/activity_<id>.json)
activity.store_locally()

# Get list of athletes activities since a given date (after) given in a human friendly format.
# Kudos to [Maya: Datetimes for Humans(TM)](https://github.com/kennethreitz/maya)
# Returns a list of [Strava SummaryActivity](https://developers.strava.com/docs/reference/#api-models-SummaryActivity) objects
list_activities = client.get_logged_in_athlete_activities(after='last week')

# Obvious use - store all activities locally
for a in list_activities:
    activity = client.get_activity_by_id(a.id)
    activity.store_locally()

# List local activities (returns a generator of JSON friendly dicts)
activities = client.local_activitis(athlete_id=1202065)

Streams

# Returns a stravaio.Streams object that wraps the 
# [Strava StreamSet](https://developers.strava.com/docs/reference/#api-models-StreamSet)
streams = client.get_activity_streams(2033203247)

# Access streams using the dot notation
watts = streams.watts

# Dump streams into a JSON friendly dict
streams_dict = streams.to_dict()

# Store streams locally (~/.stravadata/streams_<athlete_id>/streams_<id>.parquet) as a .parquet file, that can be loaded later using the
# pandas.read_parquet()
streams.store_locally()

Contributors

Aart Goossens

Release files for stravaio 0.0.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for stravaio 0.0.9
File Size Uploaded
stravaio-0.0.9.tar.gz 79.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for stravaio 0.0.9
File Interpreter ABI Platform
stravaio-0.0.9-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 233.7 kB

Release files / stravaio-0.0.9.tar.gz

Download URL stravaio-0.0.9.tar.gz
Size 79.6 kB
Tags Source
SHA-256 checksum
How to use checksums
0b8f4c3b303a4dfb6458e4a2d2a3fc85d8781743f68802a8b5c8dbe81b746424
BLAKE2b-256 checksum
How to use checksums
f1523a01ba262a8c04a7b96b8da79f9114c7f52db9e19e8e31e4f266b4955538
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.7

Release files / stravaio-0.0.9-py2.py3-none-any.whl

Download URL stravaio-0.0.9-py2.py3-none-any.whl
Size 154.2 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
bb547c31c7639d0763125c52ba32af1ed17495d31831e87aa14aa82270bae632
BLAKE2b-256 checksum
How to use checksums
a7b2a66deb344a459f9db75e323424aa45375e269efdc5af483b4e66def15441
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.7

Release history Release notifications | RSS feed

This release

0.0.9 This release

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page