garmin-connect-personal-api-python 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. garmin_connect_personal_api_python-1.0.0/LICENSE +201 -0
  2. garmin_connect_personal_api_python-1.0.0/MANIFEST.in +1 -0
  3. garmin_connect_personal_api_python-1.0.0/PKG-INFO +400 -0
  4. garmin_connect_personal_api_python-1.0.0/README.md +373 -0
  5. garmin_connect_personal_api_python-1.0.0/examples/fetch_activities.py +54 -0
  6. garmin_connect_personal_api_python-1.0.0/examples/fetch_sleep.py +48 -0
  7. garmin_connect_personal_api_python-1.0.0/examples/get_token.py +32 -0
  8. garmin_connect_personal_api_python-1.0.0/pyproject.toml +71 -0
  9. garmin_connect_personal_api_python-1.0.0/setup.cfg +4 -0
  10. garmin_connect_personal_api_python-1.0.0/src/garmin_connect_personal_api_python.egg-info/PKG-INFO +400 -0
  11. garmin_connect_personal_api_python-1.0.0/src/garmin_connect_personal_api_python.egg-info/SOURCES.txt +30 -0
  12. garmin_connect_personal_api_python-1.0.0/src/garmin_connect_personal_api_python.egg-info/dependency_links.txt +1 -0
  13. garmin_connect_personal_api_python-1.0.0/src/garmin_connect_personal_api_python.egg-info/entry_points.txt +2 -0
  14. garmin_connect_personal_api_python-1.0.0/src/garmin_connect_personal_api_python.egg-info/requires.txt +11 -0
  15. garmin_connect_personal_api_python-1.0.0/src/garmin_connect_personal_api_python.egg-info/top_level.txt +1 -0
  16. garmin_connect_personal_api_python-1.0.0/src/garmin_personal_api/__init__.py +35 -0
  17. garmin_connect_personal_api_python-1.0.0/src/garmin_personal_api/__main__.py +20 -0
  18. garmin_connect_personal_api_python-1.0.0/src/garmin_personal_api/_credentials.py +41 -0
  19. garmin_connect_personal_api_python-1.0.0/src/garmin_personal_api/_version.py +17 -0
  20. garmin_connect_personal_api_python-1.0.0/src/garmin_personal_api/api_keys.py +64 -0
  21. garmin_connect_personal_api_python-1.0.0/src/garmin_personal_api/auth.py +188 -0
  22. garmin_connect_personal_api_python-1.0.0/src/garmin_personal_api/cli.py +330 -0
  23. garmin_connect_personal_api_python-1.0.0/src/garmin_personal_api/client.py +288 -0
  24. garmin_connect_personal_api_python-1.0.0/src/garmin_personal_api/commands.py +119 -0
  25. garmin_connect_personal_api_python-1.0.0/src/garmin_personal_api/constants.py +25 -0
  26. garmin_connect_personal_api_python-1.0.0/src/garmin_personal_api/downloads.py +48 -0
  27. garmin_connect_personal_api_python-1.0.0/src/garmin_personal_api/errors.py +42 -0
  28. garmin_connect_personal_api_python-1.0.0/src/garmin_personal_api/interactive.py +686 -0
  29. garmin_connect_personal_api_python-1.0.0/src/garmin_personal_api/py.typed +0 -0
  30. garmin_connect_personal_api_python-1.0.0/tests/test_auth.py +341 -0
  31. garmin_connect_personal_api_python-1.0.0/tests/test_cli.py +666 -0
  32. garmin_connect_personal_api_python-1.0.0/tests/test_client.py +354 -0
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1 @@
1
+ recursive-include examples *.py
@@ -0,0 +1,400 @@
1
+ Metadata-Version: 2.4
2
+ Name: garmin-connect-personal-api-python
3
+ Version: 1.0.0
4
+ Summary: Python client for the Garmin Connect Personal API
5
+ Author: Garmin Ltd. or its subsidiaries.
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Repository, https://github.com/garmin/connect-personal-api-python
8
+ Classifier: Development Status :: 4 - Beta
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3.12
11
+ Classifier: Programming Language :: Python :: 3.13
12
+ Classifier: Programming Language :: Python :: 3.14
13
+ Classifier: Typing :: Typed
14
+ Requires-Python: >=3.12
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Requires-Dist: requests<3,>=2.31
18
+ Provides-Extra: interactive
19
+ Requires-Dist: rich<15,>=13.7; extra == "interactive"
20
+ Provides-Extra: dev
21
+ Requires-Dist: garmin-connect-personal-api-python[interactive]; extra == "dev"
22
+ Requires-Dist: pytest<9,>=8; extra == "dev"
23
+ Requires-Dist: pytest-cov<7,>=5; extra == "dev"
24
+ Requires-Dist: pyright<2,>=1.1; extra == "dev"
25
+ Requires-Dist: ruff<1,>=0.9; extra == "dev"
26
+ Dynamic: license-file
27
+
28
+ # Garmin Connect Personal API Client
29
+
30
+ A small Python client for reading data from Garmin's Personal API. It is a
31
+ concrete example of how to query Garmin data using Personal API
32
+ authentication, and other projects can reuse its parts independently:
33
+
34
+ - `PersonalApiAuthenticator` caches bearer tokens and exchanges a Personal API
35
+ key for a new token when needed.
36
+ - `GarminPersonalApiClient` makes authenticated GET requests with any bearer
37
+ token and provides convenience wrappers for Personal API data sets.
38
+ - `gc-personal` is a command-line interface built on those same wrappers. Its
39
+ direct commands work in scripts and one-off queries, and an optional
40
+ interactive menu is included for demonstrating and exploring the data.
41
+
42
+ ## Requirements and installation
43
+
44
+ You need Python 3.12 or newer and a Garmin Connect Personal API key. The
45
+ package installs `requests` automatically.
46
+
47
+ Create a virtual environment, activate it, and install the package:
48
+
49
+ ```shell
50
+ python3 -m venv .venv
51
+ source .venv/bin/activate
52
+ python -m pip install garmin-connect-personal-api-python
53
+ ```
54
+
55
+ On Windows, create and activate the environment with:
56
+
57
+ ```powershell
58
+ py -3 -m venv .venv
59
+ .venv\Scripts\Activate.ps1
60
+ python -m pip install garmin-connect-personal-api-python
61
+ ```
62
+
63
+ The base package supports authentication, data access, and direct CLI
64
+ commands. Install the optional `interactive` extra to add `rich`, which
65
+ interactive mode requires:
66
+
67
+ ```shell
68
+ python -m pip install 'garmin-connect-personal-api-python[interactive]'
69
+ ```
70
+
71
+ ### Install from source
72
+
73
+ To install without PyPI, run one of these commands from a clone of this
74
+ repository:
75
+
76
+ ```shell
77
+ python -m pip install . # library and direct CLI commands
78
+ python -m pip install '.[interactive]' # adds interactive mode
79
+ python -m pip install -e '.[dev]' # editable, with interactive mode and dev tools
80
+ ```
81
+
82
+ ## Authentication
83
+
84
+ The package does not create Personal API keys. Create a key on
85
+ [Garmin Connect](https://connect.garmin.com/app/settings/personalApiToken).
86
+
87
+ ### Command-line key sources
88
+
89
+ `gc-personal` reads the key from one of these sources:
90
+
91
+ 1. **Key file:** `~/.config/garmin/connect-personal-api-key`, or another path
92
+ passed with `--api-key-file`. On Windows, `~` is your user profile folder
93
+ (`%USERPROFILE%`). The file should contain only the API key; surrounding
94
+ whitespace, including a trailing newline, is ignored.
95
+ 2. **Environment variable:** `GARMIN_PERSONAL_API_KEY`.
96
+ 3. **Command-line argument:** `--api-key`.
97
+
98
+ If more than one source is provided, precedence is:
99
+
100
+ 1. Explicit key: `--api-key`.
101
+ 2. Explicit key file: `--api-key-file`, even if it names the default path.
102
+ 3. Environment variable: `GARMIN_PERSONAL_API_KEY`.
103
+ 4. Default key file, when neither explicit option nor the environment variable
104
+ supplies a key.
105
+
106
+ A missing, unreadable, or empty explicitly selected file is an error, not a
107
+ reason to fall back to the environment or default file. An empty explicit key
108
+ or environment variable is also an error. **A key passed with `--api-key` may
109
+ be exposed through shell history or the process list.**
110
+
111
+ ```shell
112
+ # Use the default key file.
113
+ gc-personal profile-settings
114
+
115
+ # Use a key file at another path.
116
+ gc-personal --api-key-file ~/my-garmin-key profile-settings
117
+
118
+ # Use the environment variable.
119
+ export GARMIN_PERSONAL_API_KEY='your-personal-api-key'
120
+ gc-personal profile-settings
121
+
122
+ # Pass the key directly (exposed to shell history and the process list).
123
+ gc-personal --api-key 'your-personal-api-key' profile-settings
124
+ ```
125
+
126
+ ### Python key sources
127
+
128
+ `obtain_token()` requires an explicit key and doesn't discover one itself;
129
+ see [Explicit API key](#explicit-api-key).
130
+ To opt into key discovery, pass the result of `resolve_api_key()` to
131
+ `obtain_token()`; see [Key discovery](#key-discovery).
132
+ An explicit `api_key` takes precedence over `key_file=`, which takes precedence
133
+ over `GARMIN_PERSONAL_API_KEY`. When neither argument is supplied, discovery
134
+ checks the environment variable and then the default key file.
135
+
136
+ ### Bearer-token cache
137
+
138
+ The authenticator exchanges the API key for a bearer token and caches it by
139
+ default in `~/.config/garmin/connect-personal-api-bearer-token.json`. Use
140
+ `--bearer-token-cache-file` in the CLI, or `bearer_token_cache_file` in
141
+ Python, to choose another location:
142
+
143
+ ```shell
144
+ gc-personal --bearer-token-cache-file /path/to/bearer-token-cache.json profile-settings
145
+ ```
146
+
147
+ A cached token is reused only when it was issued for the current API key and
148
+ has more than one hour remaining before expiration, based on the JWT `exp`
149
+ claim. Otherwise, the authenticator obtains and caches a new token. Each
150
+ direct command, interactive session, and `obtain_token()` call checks the
151
+ cache this way, so expired tokens are replaced automatically. The cache can't
152
+ be disabled.
153
+
154
+ Rarely, a token stops working before it expires, for example because it was
155
+ revoked. Requests then fail with `401`, and the client doesn't retry them. To
156
+ recover, obtain a new token:
157
+
158
+ - **Direct commands:** run `gc-personal refresh-token`, or delete the cache
159
+ file, then rerun the command.
160
+ - **Interactive mode:** choose **Reload Bearer Token** from the menu.
161
+ - **Python:** call `obtain_token(api_key, force_refresh=True)`, then pass the
162
+ new token's `access_token` to `client.update_bearer_token()`.
163
+
164
+ ### Protecting credential files
165
+
166
+ The bearer-token cache, and the key file if you use one, hold plain-text
167
+ credentials. Keep them readable only by your user and out of version control.
168
+ On POSIX systems, the package logs a warning, but continues, when either file
169
+ is readable by group or other users. This check isn't performed on Windows.
170
+
171
+ - **Key file:** Applies only when you provide the key through a key file
172
+ rather than the environment variable or an explicit argument. You create
173
+ this file, and it must contain only the key. Restrict its permissions
174
+ yourself, for example with `chmod 600`.
175
+ - **Bearer-token cache:** The authenticator creates this file with `0600`
176
+ permissions on POSIX systems, so you don't need to set them yourself. An
177
+ existing cache file keeps its current permissions.
178
+
179
+ ## Command-line interface
180
+
181
+ Use `--help` to list every command and shared option, or add it after a
182
+ command to see that command's options and defaults:
183
+
184
+ ```shell
185
+ gc-personal --help
186
+ gc-personal steps --help
187
+ ```
188
+
189
+ Run `gc-personal` with a command to retrieve data, download an activity file,
190
+ or replace the cached bearer token:
191
+
192
+ ```shell
193
+ gc-personal profile-settings
194
+ gc-personal sleep --date 2026-08-24
195
+ gc-personal steps --start-date 2026-08-20 --end-date 2026-08-24
196
+ gc-personal activities --start 0 --limit 20 --start-date 2026-08-01
197
+ gc-personal activity 123456789
198
+ gc-personal activity-workouts 123456789
199
+ gc-personal activity-download 123456789
200
+ gc-personal activity-download 123456789 -o ./run.zip
201
+ gc-personal refresh-token
202
+ gc-personal --api-key-file /path/to/key --timeout 20 --quiet profile-settings
203
+ ```
204
+
205
+ Most date options default to today when omitted. Shared options such as `--api-key-file` and `--timeout` go before the command. Use
206
+ `--quiet` to suppress request logs for non-interactive commands; interactive
207
+ status lines remain visible.
208
+
209
+ Data commands print JSON to stdout. Request logs, status messages, and errors
210
+ go to stderr, so output can be piped to other tools, such as `jq`. The command
211
+ exits with a non-zero status on failure.
212
+
213
+ `activity-download` saves a ZIP file as `activity-ID.zip` in the current
214
+ directory unless `-o PATH` is given, and doesn't replace an existing file
215
+ unless you pass `--force`. Use `-o -` to write the ZIP bytes to stdout; the
216
+ command refuses to write them to a terminal.
217
+
218
+ ### Interactive Mode
219
+
220
+ Interactive mode is a demonstration and data-exploration tool. Run
221
+ `gc-personal` without a command to open its menu. Interactive mode requires
222
+ the `interactive` extra. It loads the token through the same
223
+ cache-aware authentication path as direct commands, reuses it for the session,
224
+ and can force a new token to be obtained and cached from the menu.
225
+
226
+ ```shell
227
+ gc-personal
228
+ ```
229
+
230
+ Select an activity in the activity browser to view its details or workouts,
231
+ or choose **download activity file** to save its ZIP file. The menu
232
+ prompts for a destination and confirms before replacing an existing file.
233
+
234
+ ## Library usage
235
+
236
+ The usual flow is to obtain a token, then pass it to the data client.
237
+
238
+ ### Explicit API key
239
+
240
+ Pass your application's API key directly to `obtain_token()`. For example,
241
+ an application with its own secret store can use:
242
+
243
+ ```python
244
+ from garmin_personal_api import (
245
+ GarminPersonalApiClient,
246
+ PersonalApiAuthenticator,
247
+ )
248
+
249
+ api_key = my_app_secret_manager.get("garmin-personal-api-key")
250
+ with PersonalApiAuthenticator() as authenticator:
251
+ token = authenticator.obtain_token(api_key)
252
+
253
+ with GarminPersonalApiClient(token.access_token) as client:
254
+ sleep = client.get_daily_sleep("2026-08-24")
255
+ steps = client.get_daily_steps("2026-08-20", "2026-08-24")
256
+ ```
257
+
258
+ `obtain_token()` returns a `BearerToken` with the token string in
259
+ `access_token` and its expiration, in seconds since the epoch, in `expires_at`.
260
+ Pass `force_refresh=True` to explicitly obtain and cache a new token.
261
+
262
+ ### Key discovery
263
+
264
+ Alternatively, use `resolve_api_key()` to discover the key:
265
+
266
+ ```python
267
+ from garmin_personal_api import PersonalApiAuthenticator, resolve_api_key
268
+
269
+ with PersonalApiAuthenticator() as authenticator:
270
+ token = authenticator.obtain_token(resolve_api_key())
271
+ ```
272
+
273
+ To explicitly select a key file, use
274
+ `resolve_api_key(key_file="~/my-garmin-key")`. This overrides the environment
275
+ variable, including when you explicitly select the default file path. If the
276
+ selected file is missing, unreadable, or empty, discovery raises an error
277
+ instead of trying another source.
278
+
279
+ ### Bearer tokens from another source
280
+
281
+ Applications that already have a bearer token can skip the authenticator and
282
+ use the data client directly:
283
+
284
+ ```python
285
+ from garmin_personal_api import GarminPersonalApiClient
286
+
287
+ with GarminPersonalApiClient(my_app_token_provider.get_token()) as client:
288
+ profile = client.get_user_profile_settings()
289
+ ```
290
+
291
+ ### Configuration
292
+
293
+ Both classes accept an optional `requests.Session` and can be used as context
294
+ managers or closed explicitly.
295
+
296
+ Request activity is logged at `INFO` to the `garmin_personal_api` logger.
297
+ Configure Python logging to see it.
298
+
299
+ ### Downloading activity files
300
+
301
+ `download_activity()` returns ZIP bytes without writing or extracting files:
302
+
303
+ ```python
304
+ from pathlib import Path
305
+
306
+ with GarminPersonalApiClient(token.access_token) as client:
307
+ content = client.download_activity(123456789)
308
+ Path("activity-123456789.zip").write_bytes(content)
309
+ ```
310
+
311
+ The whole ZIP is held in memory; streaming is not currently supported. Unlike the CLI,
312
+ `Path.write_bytes()` overwrites an existing file.
313
+
314
+ ## Endpoint wrappers
315
+
316
+ The table contains every dedicated wrapper on
317
+ `GarminPersonalApiClient`. The CLI column shows the matching `gc-personal`
318
+ command. `activity`, `activity-workouts`, and `activity-download` are direct commands but are not
319
+ listed on the top-level interactive menu; see
320
+ [Interactive Mode](#interactive-mode) for how to reach them interactively.
321
+
322
+ Wrappers are added as a convenience and may lag behind new endpoints available
323
+ through Personal API. Use `get()` for endpoints that don't have a wrapper;
324
+ see [Call an endpoint without a wrapper](#call-an-endpoint-without-a-wrapper).
325
+
326
+ | Python wrapper | CLI command | HTTP request |
327
+ | --- | --- | --- |
328
+ | `get_daily_stress(start_date, end_date)` | `stress` | `GET /usersummary-service/stats/stress/daily/{start_date}/{end_date}` |
329
+ | `get_daily_steps(start_date, end_date)` | `steps` | `GET /usersummary-service/stats/steps/daily/{start_date}/{end_date}` |
330
+ | `get_daily_hydration(start_date, end_date)` | `hydration` | `GET /usersummary-service/stats/hydration/daily/{start_date}/{end_date}` |
331
+ | `get_effective_weight_goals(start_date, end_date)` | `effective-weight-goals` | `GET /goal-service/goal/user/effective/weightgoal/{start_date}/{end_date}` |
332
+ | `get_weight_measurements(start_date, end_date)` | `weight-measurements` | `GET /weight-service/weight/range/{start_date}/{end_date}?includeAll=true` |
333
+ | `get_daily_food_logs(calendar_date)` | `food-logs` | `GET /nutrition-service/food/logs/{calendar_date}` |
334
+ | `get_user_profile_settings()` | `profile-settings` | `GET /userprofile-service/userprofile/settings` |
335
+ | `get_daily_sleep(calendar_date)` | `sleep` | `GET /sleep-service/sleep/dailySleep?date={calendar_date}` |
336
+ | `get_daily_sleep_summaries(start_date, end_date)` | `sleep-summaries` | `GET /sleep-service/sleep/dailySleepSummariesByDate?startDate={start_date}&endDate={end_date}` |
337
+ | `get_daily_body_battery(start_date, end_date, *, chunks=None)` | `body-battery` | `GET /wellness-service/wellness/bodyBattery/reports/daily?startDate={start_date}&endDate={end_date}[&chunks={chunks}]` |
338
+ | `get_daily_summaries(start_date, end_date)` | `daily-summaries` | `GET /usersummary-service/v2/dailysummaries?startDate={start_date}&endDate={end_date}` |
339
+ | `get_daily_heart_rate(calendar_date)` | `heart-rate` | `GET /wellness-service/wellness/dailyHeartRate?date={calendar_date}` |
340
+ | `get_daily_hrv(calendar_date)` | `hrv` | `GET /hrv-service/hrv/{calendar_date}` |
341
+ | `get_daily_hrv_summaries(start_date, end_date)` | `hrv-summaries` | `GET /hrv-service/hrv/daily/{start_date}/{end_date}` |
342
+ | `get_heart_rate_zones()` | `heart-rate-zones` | `GET /biometric-service/heartRateZones/v2` |
343
+ | `get_menstrual_cycle_summary(calendar_date)` | `menstrual-cycle-summary` | `GET /periodichealth-service/menstrualcycle/summary/{calendar_date}` |
344
+ | `get_menstrual_cycle_day_view(calendar_date, today_date)` | `menstrual-cycle-day-view` | `GET /periodichealth-service/menstrualcycle/dayview/{calendar_date}?todayDate={today_date}` |
345
+ | `get_fitness_age(calendar_date)` | `fitness-age` | `GET /fitnessage-service/fitnessage/v2/{calendar_date}` |
346
+ | `get_daily_spo2(calendar_date)` | `spo2` | `GET /wellness-service/wellness/daily/spo2acclimation/{calendar_date}` |
347
+ | `get_wellness_activity_summaries(start_date, end_date)` | `wellness-activity-summaries` | `GET /wellnessactivity-service/activity/summary/range/{start_date}/{end_date}` |
348
+ | `search_activities(*, start=0, limit=20, start_date=None, end_date=None, activity_type=None)` | `activities` | `GET /activitylist-service/activities/search/activities?start={start}&limit={limit}[&startDate={start_date}&endDate={end_date}&activityType={activity_type}]` |
349
+ | `get_activity(activity_id)` | `activity` | `GET /activity-service/activity/{activity_id}` |
350
+ | `get_activity_workouts(activity_id)` | `activity-workouts` | `GET /activity-service/activity/{activity_id}/workouts` |
351
+ | `download_activity(activity_id)` | `activity-download` | `GET /download-service/files/activity/{activity_id}` (ZIP bytes) |
352
+
353
+ Dates accept `datetime.date` objects or `YYYY-MM-DD` strings. Validation of
354
+ dates, ranges, and other arguments is left to the API, except download activity
355
+ IDs, which must be positive integers.
356
+
357
+ ### Call an endpoint without a wrapper
358
+
359
+ Use `GarminPersonalApiClient.get()` for another Personal API GET endpoint:
360
+
361
+ ```python
362
+ with GarminPersonalApiClient(token.access_token) as client:
363
+ custom_data = client.get(
364
+ "/some-service/some-resource",
365
+ params={"calendarDate": "2026-08-24"},
366
+ )
367
+ ```
368
+
369
+ The client adds bearer-token authorization and returns decoded JSON. A
370
+ successful response with no content returns `None`.
371
+
372
+ ## Errors
373
+
374
+ - `GarminPersonalApiError` for missing or empty credentials, invalid local
375
+ settings such as a non-positive timeout or an invalid download activity ID,
376
+ an empty download response, or a token response that is not a JWT with an
377
+ `exp` claim.
378
+ - `HttpError`, a subclass of `GarminPersonalApiError`, for unsuccessful token
379
+ or data responses. It exposes `status_code`, `method`, `url`, and
380
+ `response_text`.
381
+ - `OSError` when an existing key file can't be read, or the bearer-token cache
382
+ can't be read or written, for example because of file permissions.
383
+
384
+ Network failures and invalid JSON responses raise the underlying `requests`
385
+ exceptions.
386
+
387
+ ## Development
388
+
389
+ ```shell
390
+ ruff check .
391
+ pyright
392
+ pytest
393
+ ```
394
+
395
+ Tests use HTTP test doubles and do not require credentials or network access.
396
+
397
+ ## License
398
+
399
+ Copyright 2026 Garmin Ltd. or its subsidiaries. Distributed under the Apache
400
+ 2.0 License. See [LICENSE](LICENSE) for the complete license text.