@@ -19,7 +19,7 @@ OAuth2 PKCE authentication and resource-based API interactions.
1919
2020## Installation
2121
22- This package requires Python 3.13 or later.
22+ This package requires Python 3.13 ( or later, when there is a later) .
2323
2424Once published, install like this:
2525
@@ -59,13 +59,13 @@ except Exception as e:
5959```
6060
6161The response will always be the body of the API response, and is almost always a
62- ` Dict ` , ` List ` or ` None ` . ` nutrition.get_activity_tcx ` is the exception. It
63- returns XML (as a ` str ` ).
62+ ` JSONDict ` , ` JSONList ` or ` None ` . ` nutrition.get_activity_tcx ` is the exception.
63+ It returns XML (as a ` str ` ).
6464
6565## Method Aliases
6666
67- All resource methods are available directly from the client instance. This means
68- you can use:
67+ All API methods are available directly from the client instance. This means you
68+ can use:
6969
7070``` python
7171# Short form with method aliases
@@ -87,7 +87,7 @@ Both approaches are equivalent, but aliases provide a more concise syntax.
8787
8888## Authentication
8989
90- Uses a local callback server to automatically handle the OAuth2 flow:
90+ Authentication wses a local callback server to handle the OAuth2 flow:
9191
9292``` python
9393client = FitbitClient(
@@ -97,7 +97,7 @@ client = FitbitClient(
9797 token_cache_path = " /tmp/fb_tokens.json"
9898)
9999
100- # Will open browser and handle callback automatically
100+ # This will open browser and handle callback automatically:
101101client.authenticate()
102102```
103103
@@ -129,7 +129,10 @@ Where secrets.json contains:
129129}
130130```
131131
132- You can also include the optional token_cache_path:
132+ Using this strategy, you can initialize the client with several additional
133+ parameter arguments (such as [ Rate Limiting] ( #rate-limiting ) and language/locale
134+ options; see the [ FitbitClient] ( fitbit_client/client.py ) initializer). Perhaps
135+ the most useful of these is the ` token_cache_path ` :
133136
134137``` json
135138{
@@ -144,18 +147,65 @@ The `token_cache_path` parameter allows you to persist authentication tokens
144147between sessions. If provided, the client will:
145148
1461491 . Load existing tokens from this file if available (avoiding re-authentication)
147-
1481502 . Save new or refreshed tokens to this file automatically
149-
1501513 . Handle token refresh when expired tokens are detected
151152
152153## Setting Up Your Fitbit App
153154
1541551 . Go to dev.fitbit.com and create a new application
155- 2 . Set OAuth 2.0 Application Type to "Personal"
156+ 2 . Set OAuth 2.0 Application Type to "Personal" (or other types, if you know
157+ what you're doing)
1561583 . Set Callback URL to "https://localhost:8080 " (or your preferred local URL)
1571594 . Copy your Client ID and Client Secret
158160
161+ ## Pagination
162+
163+ Some Fitbit API endpoints support pagination for large result sets. With this
164+ client, you can work with paginated endpoints in two ways:
165+
166+ ``` python
167+ # Standard way - get a single page of results
168+ sleep_logs = client.get_sleep_log_list(before_date = " 2025-01-01" )
169+
170+ # Iterator way - get an iterator that fetches all pages automatically
171+ for page in client.get_sleep_log_list(before_date = " 2025-01-01" , as_iterator = True ):
172+ for sleep_entry in page[" sleep" ]:
173+ print (sleep_entry[" logId" ])
174+ ```
175+
176+ Endpoints that support pagination:
177+
178+ - ` get_sleep_log_list() `
179+ - ` get_activity_log_list() `
180+ - ` get_ecg_log_list() `
181+ - ` get_irn_alerts_list() `
182+
183+ For more details, see [ PAGINATION.md] ( docs/PAGINATION.md ) .
184+
185+ ## Rate Limiting
186+
187+ The client includes automatic retry handling for rate-limited requests. When a
188+ rate limit is encountered, the client will:
189+
190+ 1 . Log the rate limit event
191+ 2 . Wait using an exponential backoff strategy
192+ 3 . Automatically retry the request
193+
194+ You can configure rate limiting behavior:
195+
196+ ``` python
197+ client = FitbitClient(
198+ client_id = " YOUR_CLIENT_ID" ,
199+ client_secret = " YOUR_CLIENT_SECRET" ,
200+ redirect_uri = " https://localhost:8080" ,
201+ max_retries = 5 , # Maximum number of retry attempts (default: 3)
202+ retry_after_seconds = 30 , # Base wait time in seconds (default: 60)
203+ retry_backoff_factor = 2.0 # Multiplier for successive waits (default: 1.5)
204+ )
205+ ```
206+
207+ For more details, see [ RATE_LIMITING.md] ( docs/RATE_LIMITING.md ) .
208+
159209## Additional Documentation
160210
161211### For API Library Users
@@ -165,6 +215,9 @@ between sessions. If provided, the client will:
165215- [ NAMING.md] ( docs/NAMING.md ) : API method naming conventions
166216- [ VALIDATIONS.md] ( docs/VALIDATIONS.md ) : Input parameter validation
167217- [ ERROR_HANDLING.md] ( docs/ERROR_HANDLING.md ) : Exception hierarchy and handling
218+ - [ PAGINATION.md] ( docs/PAGINATION.md ) : Working with paginated endpoints
219+ - [ RATE_LIMITING.md] ( docs/RATE_LIMITING.md ) : Rate limit handling and
220+ configuration
168221
169222It's also worth reviewing
170223[ Fitbit's Best Practices] ( https://dev.fitbit.com/build/reference/web-api/developer-guide/best-practices/ )
0 commit comments