Skip to main content

stravatool

The Strava API authentication was a little rough to use, so I developed this module to help.

There are two parts:

  • stravatool.StravaTool: A class to help manage rotating access tokens. A config file is needed to help store the api access information.
  • stravatool-helper.py: A script written to help populate the config file.

More might be added later, but for now, this was all I needed.

StravaTool

from stravatool import StravaTool

# init the class with the path of the config file
strava = StravaTool("myconfig.ini")

# get the current auth token
# if the current one is still valid, it is returned, else, it is refreshed first.
access_token = strava.access_token()

# to get the auth headers
# this is a shortcut wrapper to format the access token in a dictionary that can be passed as the header in a requests call
headers = strava.auth_headers()

By default, the strava api config is pulled from the config section labeled "strava". To override this, set the conf_section parameter when initializing the class.

stravatool-helper.py

First, create a Strava API app: https://developers.strava.com/ You will need both a client_id and a client_secret.

Then, run the script, you will need to specify the location of the config file. You can choose to either pre-populate the client id and secret, or fill them in at the prompt.

$ stravatool-helper.py test.ini

After reading in the client id and secret, the script will spawn a simple http server. You will be prompted for a hostname and port. You may choose any port that is open on your system, but currently, only 127.0.0.1 is an acceptable redirect url from the strava api.

You will be given a url. Just open it in your browser, where you can authorize the app you created. You will then be redirected back to the simple http server you are running via the script. Copy the code that is shown in the browser, then return to the terminal.

Ctrl-C out of the simple http server, where you will see more prompts. First, it will ask for the code out of the browser.

Finally, the access token, refresh token, and expiration date are retrieved, and written to the config file.

By default, the strava api config is pulled from the config section labeled "strava". To override this, use the --section argument when launching the script.

Release files for stravatool 0.1.0

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

Source distribution (sdist)

Source distribution for stravatool 0.1.0
File Size Uploaded
stravatool-0.1.0.tar.gz 4.7 kB Details

Release files / stravatool-0.1.0.tar.gz

Download URL stravatool-0.1.0.tar.gz
Size 4.7 kB
Tags Source
SHA-256 checksum
How to use checksums
ca89d9d8809b90e3b93e1d8d0fc4e695f2be06232aa0ad255f3d62c3e435a712
BLAKE2b-256 checksum
How to use checksums
2478108c1ee6404f228c93506bd412b4901821834958276f1fa255611fd32675
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.3

Release history Release notifications | RSS feed

This release

0.1.0 This release

1 release file

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