A Python wrapper for the MapMyFitness API
This is a work in progress. Current endpoints implemented are:
See Contributing
Install via pip:
pip install mapmyfitness
or from local sources:
python setup.py install
- Python 2.7, 3.2 or 3.3
- Requests takes care of our HTTP chatting, and is automatically installed when using the steps above.
Instantiate an instance of MapMyFitness
with your API key and an access token representing a user:
from mapmyfitness import MapMyFitness
mmf = MapMyFitness(api_key='not-so-secret', access_token='super-secret')
Optionally pass True
for cache_finds
. This will cache instances of objects fetched through the find
method. This is helpful for objects that aren't likely to change, like Activity Types.
from mapmyfitness import MapMyFitness
mmf = MapMyFitness(api_key='not-so-secret', access_token='super-secret', cache_finds=True)
Implements behaviors: find, search, create, delete, update
user
- integer - A user id to find routes forusers
- list or tuple - a collection of user ids to find routes forclose_to_location
- list or tuple - A 2-list or 2-tuple containing a latitude and longitude to search for routes nearminimum_distance
- int or float - The minimum distance, in meters, of routes to search for - only for use withclose_to_location
maximum_distance
- int or float - The maximum distance, in meters, of routes to search for - only for use withclose_to_location
* One of user
, users
or close_to_location
parameters must be passed.
id
- int - The unique id of the routename
- str - The name of the routedescription
- str - A description of the routeprivacy
- str - The privacy setting of the route - one of 'Private', 'Friends' or 'Public'distance
- float - The distance of the route in metersascent
- float - The total ascent of the route in metersdescent
- float - The total descent of the route in metersmin_elevation
- float - The minimum elevation of the route in metersmax_elevation
- float - The maximum elevation of the route in meterscity
- str - The city of the start point of the routestate
- str - The state of the start point of the routecountry
- str - The country of the start point of the routecreated_datetime
- datetime - The date and time the route was createdupdated_datetime
- datetime - The date and time the route was updated
points()
- Returns a list of points (dicts) containinglat
,lng
andele
keys representing latitude, longitude and elevation.points(geojson=True)
- Returns a GeoJSON LineString representation of a route.
Search for routes created by a user:
routes_paginator = mmf.route.search(user=9118466)
Search for 10k routes near a specific location:
routes_paginator = mmf.route.search(close_to_location=[35.555, -80.934], minimum_distance=9000, maximum_distance=11000)
Implements behaviors: find, search, create, delete, update
user
- integer - A user id to find routes foractivity_type
- integer - The id of the activity type to find workouts forupdated_before
- datetime - A datetime to find workouts that were updated beforeupdated_after
- datetime - A datetime to find workouts that were updated aftercreated_before
- datetime - A datetime to find workouts that were created beforecreated_after
- datetime - A datetime to find workouts that were created afterstarted_before
- datetime - A datetime to find workouts that were started beforestarted_after
- datetime - A datetime to find workouts that were started after
id
- int - The unique id of the workoutname
- str - The name of the routeprivacy
- str - The privacy setting of the route - one of 'Private', 'Friends' or 'Pulic'distance
- float - The distance of the route in metersstart_locale_timezone
- str - The timezone where the workout startedsource
- str - The source where the workout was createdhas_time_series
- bool - Whether the workout has time series datastart_datetime
- datetime - The datetime of the start of the workoutcreated_datetime
- datetime - The datetime the workout was createdupdated_datetime
- datetime - The datetime the workout was updatedtime_series
- list - Time series information for this workoutactive_time_total
- int - The total active time (moving time) for the workout in secondsdistance_total
- int - The total distance of the workout in meterssteps_total
- int - The total number of steps for the workoutelapsed_time_total
- int - The total elapsed time (stopped and moving) for the workoutmetabolic_energy_total
- int - The total number of calories burned for the workoutspeed_max
- float - The max speed for the workout in meters/secondspeed_avg
- float - The average speed for the workout in meters/secondroute_id
- int - The id of the route of the workout if it is associated with a routeroute
- Route - A route object for the route assocated with this workout, if one existsactivity_type_id
- int - The id of the activity type for this workoutactivity_type
- Activity Type - An activity type object for the activity type of the workout
Find all workouts for a user in the year 2013
start_datetime = datetime.datetime(2013, 1, 1)
end_datetime = datetime.datetime(2014, 1, 1)
workouts_paginator = mmf.workout.search(user=9118466, per_page=40, started_after=start_datetime, started_before=end_datetime)
for page_num in workouts_paginator.page_range:
the_page = workouts_paginator.page(page_num)
for workout in the_page:
print(workout.start_datetime)
Implements behaviors: find, search
friends_with
- integer - A user id to find users that are friends with
id
- int - The unique id of the userfirst_name
- str - The first name of the userlast_name
- str - The last name of the userusername
- str - The username of the usertime_zone
- str - The time zone of the usergender
- str - The gender of the userlocation
- str - The location of the userlast_login_datetime
- datetime - The datetime of the last time the user logged injoin_datetime
- datetime - The datetime of the user joining MapMyFitnessbirthdate
- date - The birthdate of the useremail
- str - The email address of the userdisplay_measurement_system
- str - The preferred measurement system of the user - Either 'metric' or 'imperial'weight
- float - The weight of the user in kilogramsheight
- float - The height of the user in meters
get_profile_photo(size='medium')
- str - Returns a url to the profile photo of the user - Size is one of 'small', 'medium' or 'large'get_friends()
- Paginator - A pagination object containing friends (users) of the user
Implements behaviors: find
id
- int - The unique id of the activity typename
- str - The name of the activity typehas_parent
- bool - Whether the activity type has a parent activity typeroot_activity_type_id
- int - The unique id of the root activity type of this activity typeroot_activity_type
- Activity Type - The root activity type of this activity type
Find a single object by its unique id. Returns a object or raises mapmyfitness.exceptions.NotFoundException
if no object is found.
route = mmf.route.find(348949363)
print(route.name) # '4 Mile Lunch Run'
Search for objects. Returns a Paginator object to easily page through large result sets.
See this gist for implementation details.
count
- returns the total number of objects on all pages.num_pages
- returns the number of pagees in the paginator.page_range
- returns a range of page numbers to allow for iteration of pages.
page(<page_number>)
- returns a Page object containing objects on a specific page.
start_datetime = datetime.datetime(2014, 1, 1)
end_datetime = datetime.datetime(2015, 1, 1)
workouts_paginator = mmf.workout.search(user=9118466, per_page=40, started_after=start_datetime, started_before=end_datetime)
page_count = workouts_paginator.num_pages # 2
page_range = workouts_paginator.page_range # [1, 2]
total_count = workouts_paginator.count # 58
for page_num in page_range:
the_page = workouts_paginator.page(page_num)
print(the_page) # <Page 1 of 2>
for workout in the_page:
print(workout.start_datetime) # 2014-01-02 02:59:53+00:00
Create an object.
Delete an object.
mmf.route.delete(348949363)
Returns None
on success or raises mapmyfitness.exceptions.NotFoundException
if the object doesn't exist.
Update an object.