GithubHelp home page GithubHelp logo

sladkovm / stravaio Goto Github PK

View Code? Open in Web Editor NEW
70.0 10.0 30.0 5.69 MB

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

License: MIT License

Makefile 0.04% Python 99.96%
strava-api python-client

stravaio's Introduction

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_activities(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

stravaio's People

Contributors

aartgoossens avatar andreyev avatar sladkovm avatar tylerdave avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

stravaio's Issues

Heart rate data is missing when using client.get_activity_by_id(activity_id)

(Thanks for the API and docs, they are great.)

I am not seeing heart rate data in the return response when using the client.get_activity_by_id(activity_id) call. I have checked that my heart rate data is not restricted by my privacy settings, so I believe it is visible:

  • my activities are visible to Everyone
  • my data permissions do not restrict my HR data

This is with version:

stravaio                 0.0.9

Is this a bug?

'Include_all_efforts' not working :(

Hy,
I am trying to get all the segments inside an activity.
And for that, I am using the get_activity_by_id function.
For that function to return the effort list, I needed to include the 'include_all_efforts' parameters.
Here is my code:

params = {'include_all_efforts':True}
activity = client.get_activity_by_id(some_id ,**params)

I am getting the ERROR:

TypeError: get_activity_by_id() got an unexpected keyword argument 'include_all_efforts'

The strange thing is that I checked the source code here and in line 225 there is the same ERROR but with different text. This means the code is not getting here, I suppose.

Am I doing something wrong?

Can't fetch activities.

Seems to be an issue setting the scope. strava_oauth2 seems to work for setting the read scope, and it opens a window at strava that says "View data about your activities" but when I look on the api page for my app it just has the read scope.

I can fetch basic profile information but activity calls return nothing.

Error when activity_type is different from 'Ride' and 'Run' (e.g. Hike)

Got error when retrieving hiking activity:

File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/swagger_client/models/summary_segment.py", line 196, in activity_type .format(activity_type, allowed_values)
ValueError: Invalid value for activity_type (Hike), must be one of ['Ride', 'Run']

is it possible to add other types of activities?

get_logged_in_athlete_activities(self, after=0, list_activities=None)

Hi @sladkovm

Thanks for putting up this package. This is the only one I am able to use given my level of python knowledge.

If I wanted to use the method get_logged_in_athlete_activities() to pull activity summary of more than 30 activity. How can I return a list of activities with all the my activities.

If I put no after parameter that would return more than 30 activity it only return a list of the last n activities that is the reminder of the division of total activities by 30.

Thanks

Pedro

Is add manual activities to Strava possible?

Hi,

I would like to programmatically add manual activities to my Strava timeline. I can do this using the Gui, but it's tedious because I want to log all my bicycle commutes. I studied the code, but it does not seem to be possible, am I right? (Access level 'read', etc)

Cheers!
AJ

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.