Overview¶
This is a complete python implementation of the Fitbit API.
It uses oAuth for authentication, it supports both us and si measurements
Quickstart¶
Here is some example usage:
import fitbit
unauth_client = fitbit.Fitbit('<consumer_key>', '<consumer_secret>')
# certain methods do not require user keys
unauth_client.activities()
# You'll have to gather the user keys on your own, or try ./fitbit/gather_keys_cli.py <con_key> <con_sec> for development
authd_client = fitbit.Fitbit('<consumer_key>', '<consumer_secret>', resource_owner_key='<user_key>', resource_owner_secret='<user_secret>')
authd_client.sleep()
Fitbit API¶
Some assumptions you should note. Anywhere it says user_id=None,
it assumes the current user_id from the credentials given, and passes
a -
through the API. Anywhere it says date=None, it should accept
either None
or a date
or datetime
object
(anything with proper strftime will do), or a string formatted
as %Y-%m-%d
.
-
class
fitbit.
Fitbit
(client_key, client_secret, system='en_US', **kwargs)¶ -
_COLLECTION_RESOURCE
(resource, date=None, user_id=None, data=None)¶ Retrieving and logging of each type of collection data.
- Arguments:
- resource, defined automatically via curry [date] defaults to today [user_id] defaults to current logged in user [data] optional, include for creating a record, exclude for access
This implements the following methods:
body(date=None, user_id=None, data=None) activities(date=None, user_id=None, data=None) foods_log(date=None, user_id=None, data=None) water(date=None, user_id=None, data=None) sleep(date=None, user_id=None, data=None) heart(date=None, user_id=None, data=None) bp(date=None, user_id=None, data=None)
-
_DELETE_COLLECTION_RESOURCE
(resource, log_id)¶ deleting each type of collection data
- Arguments:
- resource, defined automatically via curry log_id, required, log entry to delete
This builds the following methods:
delete_body(log_id) delete_activities(log_id) delete_foods(log_id) delete_water(log_id) delete_sleep(log_id) delete_heart(log_id) delete_bp(log_id)
-
_food_stats
(user_id=None, qualifier='')¶ This builds the convenience methods on initialization:
recent_foods(user_id=None, qualifier='') favorite_foods(user_id=None, qualifier='') frequent_foods(user_id=None, qualifier='')
-
accept_invite
(other_user_id)¶ Convenience method for respond_to_invite
-
activities_list
()¶
-
activity_detail
(activity_id)¶
-
activity_stats
(user_id=None, qualifier='')¶ - https://wiki.fitbit.com/display/API/API-Get-Activity-Stats
- https://wiki.fitbit.com/display/API/API-Get-Favorite-Activities
- https://wiki.fitbit.com/display/API/API-Get-Recent-Activities
- https://wiki.fitbit.com/display/API/API-Get-Frequent-Activities
This implements the following methods:
recent_activities(user_id=None, qualifier='') favorite_activities(user_id=None, qualifier='') frequent_activities(user_id=None, qualifier='')
-
add_alarm
(device_id, alarm_time, week_days, recurring=False, enabled=True, label=None, snooze_length=None, snooze_count=None, vibe='DEFAULT')¶ https://wiki.fitbit.com/display/API/API-Devices-Add-Alarm alarm_time should be a timezone aware datetime object.
-
add_favorite_activity
(activity_id)¶ https://wiki.fitbit.com/display/API/API-Add-Favorite-Activity
-
add_favorite_food
(food_id)¶
-
create_food
(data)¶
-
delete_alarm
(device_id, alarm_id)¶ https://wiki.fitbit.com/display/API/API-Devices-Delete-Alarm
-
delete_favorite_activity
(activity_id)¶ https://wiki.fitbit.com/display/API/API-Delete-Favorite-Activity
-
delete_favorite_food
(food_id)¶ https://wiki.fitbit.com/display/API/API-Delete-Favorite-Food
-
food_detail
(food_id)¶
-
get_alarms
(device_id)¶
-
get_badges
(user_id=None)¶
-
get_bodyfat
(base_date=None, user_id=None, period=None, end_date=None)¶ https://wiki.fitbit.com/display/API/API-Get-Body-fat base_date should be a datetime.date object (defaults to today), period can be ‘1d’, ‘7d’, ‘30d’, ‘1w’, ‘1m’, ‘3m’, ‘6m’, ‘1y’, ‘max’ or None end_date should be a datetime.date object, or None.
You can specify period or end_date, or neither, but not both.
-
get_bodyweight
(base_date=None, user_id=None, period=None, end_date=None)¶ https://wiki.fitbit.com/display/API/API-Get-Body-Weight base_date should be a datetime.date object (defaults to today), period can be ‘1d’, ‘7d’, ‘30d’, ‘1w’, ‘1m’, ‘3m’, ‘6m’, ‘1y’, ‘max’ or None end_date should be a datetime.date object, or None.
You can specify period or end_date, or neither, but not both.
-
get_devices
()¶
-
get_friends
(user_id=None)¶
-
get_friends_leaderboard
(period)¶ https://wiki.fitbit.com/display/API/API-Get-Friends-Leaderboard
-
get_sleep
(date)¶ https://wiki.fitbit.com/display/API/API-Get-Sleep date should be a datetime.date object.
-
intraday_time_series
(resource, base_date='today', detail_level='1min', start_time=None, end_time=None)¶ The intraday time series extends the functionality of the regular time series, but returning data at a more granular level for a single day, defaulting to 1 minute intervals. To access this feature, one must send an email to api@fitbit.com and request to have access to the Partner API (see https://wiki.fitbit.com/display/API/Fitbit+Partner+API). For details on the resources available, see:
https://wiki.fitbit.com/display/API/API-Get-Intraday-Time-Series
-
invite_friend
(data)¶
-
invite_friend_by_email
(email)¶ Convenience Method for https://wiki.fitbit.com/display/API/API-Create-Invite
-
invite_friend_by_userid
(user_id)¶ Convenience Method for https://wiki.fitbit.com/display/API/API-Create-Invite
-
list_subscriptions
(collection='')¶ https://wiki.fitbit.com/display/API/Fitbit+Subscriptions+API
-
log_activity
(data)¶
-
log_sleep
(start_time, duration)¶ https://wiki.fitbit.com/display/API/API-Log-Sleep start time should be a datetime object. We will be using the year, month, day, hour, and minute.
-
reject_invite
(other_user_id)¶ Convenience method for respond_to_invite
-
respond_to_invite
(other_user_id, accept=True)¶
-
search_foods
(query)¶
-
subscription
(subscription_id, subscriber_id, collection=None, method='POST')¶ https://wiki.fitbit.com/display/API/Fitbit+Subscriptions+API
-
time_series
(resource, user_id=None, base_date='today', period=None, end_date=None)¶ The time series is a LOT of methods, (documented at url below) so they don’t get their own method. They all follow the same patterns, and return similar formats.
Taking liberty, this assumes a base_date of today, the current user, and a 1d period.
-
update_alarm
(device_id, alarm_id, alarm_time, week_days, recurring=False, enabled=True, label=None, snooze_length=None, snooze_count=None, vibe='DEFAULT')¶ https://wiki.fitbit.com/display/API/API-Devices-Update-Alarm alarm_time should be a timezone aware datetime object.
-
user_profile_get
(user_id=None)¶ Get a user profile. You can get other user’s profile information by passing user_id, or you can get the current user’s by not passing a user_id
-
user_profile_update
(data)¶ Set a user profile. You can set your user profile information by passing a dictionary of attributes that will be updated.
-