Python Strava API library

989 views
Skip to first unread message

Hans Lellelid

unread,
Mar 14, 2014, 12:53:47 PM3/14/14
to strav...@googlegroups.com
Hi folks -

Didn't know about this forum earlier, but figured I would post a link to my hobby project from this past winter.  I updated stravalib to support the new v3 API (more of a rewrite given how different the API is):  https://github.com/hozn/stravalib


Obviously things like documentation need to be further improved, but there's some there to get started.  Also some features like streams still to be added.  The new API really is pretty simple (good!), but the library helps with things like seamless resultset paging, connection/error handling, and simplifies working with the various speed/distance units and timezones that are returned by API calls.  Eager for any feedback, of course.

Cheers,
Hans

Greg Stupp

unread,
Mar 16, 2014, 1:35:33 AM3/16/14
to strav...@googlegroups.com
This didn't work at all for me, but I figured out what was wrong. On line 112 in protocl.py: os.path.join(self.api_base, url.strip('/'))
On windows this inserts a '\' instead of the intended '/', which causes the following error for any request.
requests.exceptions.HTTPError: 404 Client Error: Not Found [None]

I changed _resolve_url to:
def _resolve_url(self, url):

    if not url.startswith('http'):

        url = urlparse.urljoin('https://{0}'.format(self.server), self.api_base + '/' + url.strip('/'))

    return url


Now it works! (so far ;) ). 

One other thing,
athlete = client.get_athlete()
prints out 'No handlers could be found for logger "stravalib.model.Athlete"' in red text, but it is not an error. Should it do this?

-Greg

Hans Lellelid

unread,
Mar 16, 2014, 10:34:40 AM3/16/14
to Greg Stupp, strav...@googlegroups.com

Thanks, very helpful! I will get that fixed and push out a patch.

The loggers message is just because your application that uses the library did not setup logging (uses python standard logging), so that is expected. (But not an error per se.)

Hans

--
You received this message because you are subscribed to a topic in the Google Groups "Strava API" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/strava-api/foslbe-WQNY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to strava-api+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hans Lellelid

unread,
Mar 16, 2014, 6:41:04 PM3/16/14
to Greg Stupp, strav...@googlegroups.com
I pushed out a 0.2.2 release with this fix.  Thanks again.

Hans


--

Anthony Wu

unread,
Apr 28, 2014, 5:23:44 AM4/28/14
to strav...@googlegroups.com
Hi Hans - your stravalib is excellent, it gave me a headstart in exploring the new v3 API.

While experimenting with the API, I found it useful to:

1) build an easy way to get a write-permission access_token for myself
2) launch into an interactive shell to play with the api via your client

So I put together my workspace and posted it on GitHub: https://github.com/anthonywu/strava-api-experiment

If you think some of my work could be bundled with your library, I'd be happy to fork your lib, make my additions and make a pull request.

– Anthony

Hans Lellelid

unread,
Apr 28, 2014, 8:54:16 AM4/28/14
to Anthony Wu, strav...@googlegroups.com
Hi Anthony -- I'm glad you found this helpful!  And yes, I'd be more than happy to merge pull requests in -- whether in an "examples" directory, or wherever most appropriate.  Stravalib is, of course, designed to be a library, so the only concern would be making sure that we don't pull in non-library dependencies by default (e.g. for those simply including this in their own larger projects).  Of course, it may also be more appropriate to keep this as a separate project -- up to you.  I am not doing much development with stravalib currently, but I do want to get back to it this summer to add support for the streams, etc.  I also probably need to tweak the model a bit, as the API seems to be constantly evolving (at least as far as the attributes being returned).

Cheers,
Hans


--

Sam Lalonde

unread,
Jun 23, 2014, 3:47:16 PM6/23/14
to strav...@googlegroups.com
Hey, just checking this out.  I'm a bit new to all this.

I'm mostly interested in retrieving activities, and I've got it all working fine except that I am unable to figure out how to retrieve "laps" (not splits) from an activity.  Is this possible?


Thanks,
Sam

Hans Lellelid

unread,
Jun 24, 2014, 11:42:16 AM6/24/14
to Sam Lalonde, strav...@googlegroups.com
Hi Sam -- this has not been implemented yet; I think this was added relatively recently. I can expose that -- I've been needing to sit down and make a few updates to the library, so that would be a good time to do that.  I'm really trying to find time to do that this week (or weekend).


--
Reply all
Reply to author
Forward
0 new messages