garmin-connect-api 0.2.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 (66) hide show
  1. garmin_connect_api-0.2.0/.gitignore +13 -0
  2. garmin_connect_api-0.2.0/CHANGELOG.md +40 -0
  3. garmin_connect_api-0.2.0/CITATION.cff +17 -0
  4. garmin_connect_api-0.2.0/LICENSE +21 -0
  5. garmin_connect_api-0.2.0/PKG-INFO +292 -0
  6. garmin_connect_api-0.2.0/README.md +258 -0
  7. garmin_connect_api-0.2.0/SECURITY.md +12 -0
  8. garmin_connect_api-0.2.0/examples/session.json +23 -0
  9. garmin_connect_api-0.2.0/examples/workout.json +23 -0
  10. garmin_connect_api-0.2.0/pyproject.toml +92 -0
  11. garmin_connect_api-0.2.0/server.json +33 -0
  12. garmin_connect_api-0.2.0/src/garmin_api/__init__.py +13 -0
  13. garmin_connect_api-0.2.0/src/garmin_api/auth.py +296 -0
  14. garmin_connect_api-0.2.0/src/garmin_api/catalogue.py +187 -0
  15. garmin_connect_api-0.2.0/src/garmin_api/cli.py +357 -0
  16. garmin_connect_api-0.2.0/src/garmin_api/errors.py +70 -0
  17. garmin_connect_api-0.2.0/src/garmin_api/fit/__init__.py +12 -0
  18. garmin_connect_api-0.2.0/src/garmin_api/fit/body.py +112 -0
  19. garmin_connect_api-0.2.0/src/garmin_api/fit/decode.py +153 -0
  20. garmin_connect_api-0.2.0/src/garmin_api/fit/encode.py +219 -0
  21. garmin_connect_api-0.2.0/src/garmin_api/fit/exercises.py +95 -0
  22. garmin_connect_api-0.2.0/src/garmin_api/http/__init__.py +5 -0
  23. garmin_connect_api-0.2.0/src/garmin_api/http/app.py +119 -0
  24. garmin_connect_api-0.2.0/src/garmin_api/http/routers/__init__.py +1 -0
  25. garmin_connect_api-0.2.0/src/garmin_api/http/routers/activities.py +142 -0
  26. garmin_connect_api-0.2.0/src/garmin_api/http/routers/exercises.py +44 -0
  27. garmin_connect_api-0.2.0/src/garmin_api/http/routers/health.py +159 -0
  28. garmin_connect_api-0.2.0/src/garmin_api/http/routers/sessions.py +92 -0
  29. garmin_connect_api-0.2.0/src/garmin_api/http/routers/workouts.py +124 -0
  30. garmin_connect_api-0.2.0/src/garmin_api/mcp/__init__.py +5 -0
  31. garmin_connect_api-0.2.0/src/garmin_api/mcp/server.py +283 -0
  32. garmin_connect_api-0.2.0/src/garmin_api/models/__init__.py +50 -0
  33. garmin_connect_api-0.2.0/src/garmin_api/models/activities.py +237 -0
  34. garmin_connect_api-0.2.0/src/garmin_api/models/common.py +102 -0
  35. garmin_connect_api-0.2.0/src/garmin_api/models/health.py +399 -0
  36. garmin_connect_api-0.2.0/src/garmin_api/models/laps.py +272 -0
  37. garmin_connect_api-0.2.0/src/garmin_api/models/records.py +140 -0
  38. garmin_connect_api-0.2.0/src/garmin_api/models/trends.py +134 -0
  39. garmin_connect_api-0.2.0/src/garmin_api/models/workouts.py +293 -0
  40. garmin_connect_api-0.2.0/src/garmin_api/py.typed +0 -0
  41. garmin_connect_api-0.2.0/src/garmin_api/services/__init__.py +10 -0
  42. garmin_connect_api-0.2.0/src/garmin_api/services/activities.py +285 -0
  43. garmin_connect_api-0.2.0/src/garmin_api/services/health.py +198 -0
  44. garmin_connect_api-0.2.0/src/garmin_api/services/trends.py +182 -0
  45. garmin_connect_api-0.2.0/src/garmin_api/services/uploads.py +198 -0
  46. garmin_connect_api-0.2.0/src/garmin_api/services/weight.py +77 -0
  47. garmin_connect_api-0.2.0/src/garmin_api/services/workouts.py +402 -0
  48. garmin_connect_api-0.2.0/tests/conftest.py +112 -0
  49. garmin_connect_api-0.2.0/tests/live/__init__.py +0 -0
  50. garmin_connect_api-0.2.0/tests/live/conftest.py +38 -0
  51. garmin_connect_api-0.2.0/tests/live/test_live_read.py +45 -0
  52. garmin_connect_api-0.2.0/tests/live/test_live_write.py +191 -0
  53. garmin_connect_api-0.2.0/tests/test_auth.py +43 -0
  54. garmin_connect_api-0.2.0/tests/test_catalogue.py +51 -0
  55. garmin_connect_api-0.2.0/tests/test_error_translation.py +67 -0
  56. garmin_connect_api-0.2.0/tests/test_fit_codec.py +172 -0
  57. garmin_connect_api-0.2.0/tests/test_http.py +144 -0
  58. garmin_connect_api-0.2.0/tests/test_mcp.py +122 -0
  59. garmin_connect_api-0.2.0/tests/test_mcp_output_schemas.py +230 -0
  60. garmin_connect_api-0.2.0/tests/test_prerelease.py +93 -0
  61. garmin_connect_api-0.2.0/tests/test_real_shapes.py +275 -0
  62. garmin_connect_api-0.2.0/tests/test_release.py +44 -0
  63. garmin_connect_api-0.2.0/tests/test_review_fixes.py +223 -0
  64. garmin_connect_api-0.2.0/tests/test_round_two.py +103 -0
  65. garmin_connect_api-0.2.0/tests/test_services.py +630 -0
  66. garmin_connect_api-0.2.0/tests/test_v02_features.py +439 -0
@@ -0,0 +1,13 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ .venv/
4
+ .pytest_cache/
5
+ .ruff_cache/
6
+ .mypy_cache/
7
+ dist/
8
+ build/
9
+ *.egg-info/
10
+ .env
11
+ tokens/
12
+ *.fit
13
+ !tests/fixtures/*.fit
@@ -0,0 +1,40 @@
1
+ # Changelog
2
+
3
+ ## 0.2.0 (2026-10-19)
4
+
5
+ First public release. 0.1.0 was prepared but never published; its contents are listed below
6
+ under "Foundations".
7
+
8
+ ### Added
9
+
10
+ Five features, each checked against a real account.
11
+
12
+ - **Laps and lengths.** `get_activity_laps` gives a run's or ride's laps, and a pool swim's pace
13
+ per 100 of the pool's own unit (yards in a yard pool), with first half against second half and
14
+ the fastest and slowest stretch. Ride averages use moving time, as Garmin's own do.
15
+ - **Swim, run and ride workouts.** `create_endurance_workout` builds steps that end on a time, a
16
+ distance or the lap button, with repeats; runs and rides take pace, speed, heart-rate, power or
17
+ cadence targets; swims take a stroke, equipment, a pool length and rests on the wall.
18
+ - **Trends.** `get_trend` follows one of twelve metrics (steps, resting heart rate, sleep and sleep
19
+ score, HRV, readiness, stress, body battery, weight, body fat, running and cycling VO2 max) over
20
+ up to two years, daily, weekly or monthly, usually in one request.
21
+ - **Editing sets.** `edit_activity_sets` corrects the exercise, reps or weight of a strength
22
+ activity's sets, or deletes sets, for when a watch guesses the exercise wrong.
23
+ - **Named records.** Personal records now carry a name, a unit and a readable value, such as
24
+ "Fastest 1 km run, 4:47.5", instead of Garmin's bare type number.
25
+
26
+ ### Foundations
27
+
28
+ - **Library, HTTP service and MCP server over one core.** The MCP tools are generated from the
29
+ FastAPI routes, so every endpoint is a tool with the same name and description.
30
+ - **Read:** activities with per-set strength detail and training volume; daily health (steps,
31
+ heart rate, stress as minutes per band, body battery, sleep with stages, HRV, training readiness
32
+ and status); every weigh-in with body composition; original activity files.
33
+ - **Write:** strength workouts onto the calendar, scheduled and pushed to a watch; completed
34
+ strength sessions as FIT activities with their sets; weigh-ins with full body composition as
35
+ FIT weight-scale files; activity renames and deletions.
36
+ - **Every MCP tool is annotated** with a title and whether it reads, adds, or deletes and
37
+ overwrites, so clients can ask before the destructive ones.
38
+ - **Safety:** passwords are typed only at `garmin login`; rate limits stop every call path instead
39
+ of retrying; the local service refuses cross-origin writes and foreign host names, and needs a
40
+ key beyond localhost.
@@ -0,0 +1,17 @@
1
+ cff-version: 1.2.0
2
+ message: "If you use garmin-connect-api in research, please cite it as below."
3
+ title: "garmin-connect-api: read and write Garmin Connect from Python, HTTP or an MCP client"
4
+ type: software
5
+ authors:
6
+ - name: "garmin-connect-api contributors"
7
+ repository-code: "https://github.com/happyc0der/garmin-connect-api"
8
+ url: "https://github.com/happyc0der/garmin-connect-api"
9
+ license: MIT
10
+ version: 0.2.0
11
+ date-released: 2026-10-19
12
+ keywords:
13
+ - Garmin Connect
14
+ - fitness
15
+ - strength training
16
+ - Model Context Protocol
17
+ - FIT
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 happyc0der
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,292 @@
1
+ Metadata-Version: 2.5
2
+ Name: garmin-connect-api
3
+ Version: 0.2.0
4
+ Summary: Read and write Garmin Connect from Python, HTTP or an MCP client: activities, strength sets, health data, workouts, weigh-ins
5
+ Project-URL: Homepage, https://github.com/happyc0der/garmin-connect-api
6
+ Project-URL: Repository, https://github.com/happyc0der/garmin-connect-api
7
+ Project-URL: Issues, https://github.com/happyc0der/garmin-connect-api/issues
8
+ Project-URL: Changelog, https://github.com/happyc0der/garmin-connect-api/blob/main/CHANGELOG.md
9
+ Author: happyc0der
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Keywords: fastapi,fit,fitness,garmin,garmin-connect,mcp,model-context-protocol,strength-training
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Environment :: Console
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Intended Audience :: End Users/Desktop
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Programming Language :: Python :: 3.14
22
+ Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
23
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
24
+ Classifier: Typing :: Typed
25
+ Requires-Python: >=3.12
26
+ Requires-Dist: fastapi>=0.115
27
+ Requires-Dist: fastmcp<5,>=4.0
28
+ Requires-Dist: fit-tool<1,>=0.9.13
29
+ Requires-Dist: garminconnect<0.4,>=0.3.19
30
+ Requires-Dist: pydantic<3,>=2.9
31
+ Requires-Dist: typer>=0.15
32
+ Requires-Dist: uvicorn>=0.32
33
+ Description-Content-Type: text/markdown
34
+
35
+ # garmin-connect-api
36
+
37
+ Read and write Garmin Connect from an MCP client such as Claude, from Python, or over a local HTTP
38
+ API: activities with per-set strength detail, daily health data, planned workouts, completed
39
+ strength sessions, and weigh-ins with full body composition.
40
+
41
+ <!-- mcp-name: io.github.happyc0der/garmin-connect-api -->
42
+
43
+ > **Unofficial.** Not affiliated with or endorsed by Garmin. It uses the same private endpoints as
44
+ > the Garmin Connect website, through [python-garminconnect](https://github.com/cyberjunky/python-garminconnect),
45
+ > because Garmin offers no public API for individuals. Those endpoints can change without notice,
46
+ > and using them is not sanctioned by Garmin's terms. It is meant for your own account and your
47
+ > own data.
48
+
49
+ ## Status
50
+
51
+ v0.2. Reads activities with per-set strength detail, laps and pool-swim lengths, daily health,
52
+ trends over up to two years and named personal records; writes strength, run, ride and swim
53
+ workouts, completed strength sessions, set corrections and weigh-ins with body composition. 41
54
+ tools, every one checked against a real account. Bug reports and feature requests go to
55
+ [GitHub Issues](https://github.com/happyc0der/garmin-connect-api/issues).
56
+
57
+ ## Quick start
58
+
59
+ You need [uv](https://docs.astral.sh/uv/) and Python 3.12 or newer.
60
+
61
+ **1. Log in once**, at a terminal:
62
+
63
+ ```bash
64
+ uvx --from garmin-connect-api garmin login
65
+ ```
66
+
67
+ This is the only place a password is ever typed. It asks for your Garmin email, password and any
68
+ multi-factor code, then stores tokens in `~/.garmin-api/default`, readable by your user only.
69
+ Nothing else ever prompts for a password; without tokens, every tool says to run this.
70
+
71
+ **2. Add the server to your MCP client.**
72
+
73
+ Claude Code:
74
+
75
+ ```bash
76
+ claude mcp add --scope user --transport stdio garmin -- uvx garmin-connect-api
77
+ ```
78
+
79
+ Claude Desktop, in `claude_desktop_config.json` (in `~/Library/Application Support/Claude/` on
80
+ macOS, `%APPDATA%\Claude\` on Windows):
81
+
82
+ ```json
83
+ {
84
+ "mcpServers": {
85
+ "garmin": {
86
+ "command": "uvx",
87
+ "args": ["garmin-connect-api"]
88
+ }
89
+ }
90
+ }
91
+ ```
92
+
93
+ **3. Ask.** "How did I sleep this week?", "Did my pace hold up in yesterday's swim?",
94
+ "How has my resting heart rate moved since summer?", "Show my last strength session's sets, and
95
+ change sets 3 to 5 to dumbbell rows", "Schedule a swim for Thursday: 200 easy, then 8 x 100 free
96
+ on 20 seconds rest, in a 25-yard pool".
97
+
98
+ ## What it can do
99
+
100
+ 41 tools, each annotated so your client knows which only read (27), which add something (8) and
101
+ which delete or overwrite (6), and can ask before running those.
102
+
103
+ | Read | Write |
104
+ | --- | --- |
105
+ | Activities, filtered by type and date | Create a strength workout, schedule it, push it to a watch |
106
+ | Per-set strength detail: exercise, reps, weight | Create a run, ride or pool swim workout, with targets |
107
+ | Laps for runs and rides; pace per 100 for pool swims | Log a completed strength session, with every set |
108
+ | A day in one answer: steps, heart rate, stress, body battery, sleep, HRV, readiness | Correct a session's sets: exercise, reps, weight |
109
+ | Trends over up to two years: twelve metrics, daily, weekly or monthly | Record a weigh-in, or a full body composition reading |
110
+ | Personal records, named and in units | Rename an activity or change its description |
111
+ | Every weigh-in with body composition | Delete an activity, workout or weigh-in |
112
+ | Planned workouts and the calendar | |
113
+ | Garmin's 1,527-exercise catalogue, offline | |
114
+
115
+ Four tools are written for a model rather than mirrored from an endpoint: `garmin_status` checks
116
+ the login without calling Garmin, `find_exercise` finds Garmin's name for a lift, and
117
+ `recent_strength_sessions` and `week_summary` answer common questions in one call.
118
+
119
+ **Logging a finished workout** is the write Garmin's own developer programme has never offered. A
120
+ session is encoded as a FIT activity file with set messages and uploaded, so it appears in Garmin
121
+ Connect as a Strength Training activity, exercise by exercise.
122
+
123
+ **Body composition** from a smart scale (fat, water, skeletal muscle, bone, BMI, basal metabolic
124
+ rate, visceral fat) is written as a FIT weight-scale file, the way Garmin's own Index scales do it.
125
+ A plain weigh-in carries weight alone.
126
+
127
+ ## Example output
128
+
129
+ Answers come back compact, summarised the way a person would read them. These are from made-up
130
+ data in the shapes Garmin returns.
131
+
132
+ "Did my pace hold up in yesterday's swim?" calls `get_activity_laps`:
133
+
134
+ ```json
135
+ {
136
+ "sport": "lap_swimming",
137
+ "pool_length": 25.0,
138
+ "pool_unit": "m",
139
+ "summary": {
140
+ "lengths": 80,
141
+ "distance": 2000.0,
142
+ "average_pace": "1:52/100m",
143
+ "first_half_pace": "1:50/100m",
144
+ "second_half_pace": "1:54/100m",
145
+ "by_stroke": {"FREESTYLE": 1800.0, "BACKSTROKE": 200.0},
146
+ "fastest_segment": {"lengths": "5-8", "pace": "1:44/100m"},
147
+ "slowest_segment": {"lengths": "77-80", "pace": "2:01/100m"}
148
+ }
149
+ }
150
+ ```
151
+
152
+ "How has my resting heart rate moved since summer?" calls `get_trend`, which rolls a long range
153
+ into weeks:
154
+
155
+ ```json
156
+ {
157
+ "metric": "resting_hr",
158
+ "unit": "bpm",
159
+ "aggregation": "week",
160
+ "summary": {
161
+ "days_with_data": 88,
162
+ "average": 54.2,
163
+ "min": 49.0,
164
+ "max": 61.0,
165
+ "first_period_average": 57.3,
166
+ "last_period_average": 51.6,
167
+ "change": -6.0
168
+ }
169
+ }
170
+ ```
171
+
172
+ ## Before you write anything
173
+
174
+ - **Activities you log may be shared automatically.** If your Garmin account is connected to Strava
175
+ or another app, an uploaded session can be posted there too, and deleting it from Garmin does not
176
+ delete it there.
177
+ - **Rate limits are taken seriously.** Garmin puts Cloudflare and per-account rate limits in front
178
+ of its login, and a run of failed logins can lock an account out for a day or more. Nothing here
179
+ retries a login, and a rate limit stops every call path rather than being retried. If you see
180
+ one, wait.
181
+ - **Exercises need Garmin's own names**, such as `BENCH_PRESS` / `BARBELL_BENCH_PRESS`. Every write
182
+ checks them against the catalogue first and suggests near misses, so a typo fails with a useful
183
+ message rather than Garmin's bare 400. Common gym names work in search: "rdl", "ohp", "pull ups".
184
+ - **Sessions and body-composition readings need a timezone offset**, or a 7am reading would land
185
+ hours out. They are refused without one.
186
+
187
+ ## Command line
188
+
189
+ ```bash
190
+ garmin doctor # setup check, no network
191
+ garmin activities --type strength_training --limit 5
192
+ garmin sets <activity-id> # per-set detail
193
+ garmin day 2026-10-18 # one day of health data
194
+ garmin exercises "lat pulldown" # search the catalogue, offline
195
+ garmin workout create workout.json # plan a strength workout
196
+ garmin log-session session.json # log a completed one
197
+ garmin encode-session session.json # build its FIT file without uploading
198
+ garmin decode-fit activity.zip # read sets out of a Garmin export
199
+ garmin serve # the HTTP API on 127.0.0.1:8765
200
+ ```
201
+
202
+ Run them with `uvx --from garmin-connect-api garmin ...`, or install with
203
+ `uv tool install garmin-connect-api`. Example specs:
204
+ [session.json](https://github.com/happyc0der/garmin-connect-api/blob/main/examples/session.json),
205
+ [workout.json](https://github.com/happyc0der/garmin-connect-api/blob/main/examples/workout.json).
206
+
207
+ An encoded session file can also be imported by hand on the Garmin Connect website, if you would
208
+ rather nothing logged in on your behalf.
209
+
210
+ ## Python library
211
+
212
+ ```python
213
+ from datetime import datetime, timedelta, timezone
214
+ from garmin_api.services import activities, health, uploads
215
+ from garmin_api.models.workouts import (
216
+ StrengthSessionSpec, StrengthSessionExercise, StrengthSessionSet,
217
+ )
218
+
219
+ for activity in activities.list_activities(limit=5, activity_type="strength_training"):
220
+ sets = activities.get_sets(activity.activity_id)
221
+ print(activity.name, sets.total_volume_kg, "kg")
222
+
223
+ print(health.day("2026-10-18").steps)
224
+
225
+ uploads.log_strength_session(StrengthSessionSpec(
226
+ name="Push A",
227
+ start_time=datetime(2026, 10, 18, 7, 0, tzinfo=timezone(timedelta(hours=-4))),
228
+ exercises=[StrengthSessionExercise(
229
+ category="BENCH_PRESS",
230
+ exercise_name="BARBELL_BENCH_PRESS",
231
+ sets=[StrengthSessionSet(reps=10, weight_kg=60.0, rest_s=120)],
232
+ )],
233
+ ))
234
+ ```
235
+
236
+ Responses are pydantic models with Garmin's inconsistencies ironed out: kilograms rather than
237
+ grams, timezone-aware instants, snake_case throughout. Garmin's own payload is still on `raw` when
238
+ something is not mapped.
239
+
240
+ ## HTTP API
241
+
242
+ `garmin serve` runs the same API on `127.0.0.1:8765`, with interactive docs at `/docs`. The MCP
243
+ tools are generated from these routes, so the two cannot drift apart. Because it can write to your
244
+ account, the service refuses writes from web pages open in your browser and requests naming any
245
+ host but `localhost`, which defeats DNS rebinding. Binding beyond localhost requires
246
+ `GARMIN_API_KEY`.
247
+
248
+ ## Configuration
249
+
250
+ | Variable | Purpose |
251
+ | --- | --- |
252
+ | `GARMINTOKENS` | Where tokens are stored. Defaults to `~/.garmin-api/default`. |
253
+ | `GARMIN_API_KEY` | Required to bind the HTTP service beyond localhost. |
254
+ | `GARMIN_API_HOSTS` | Extra host names the HTTP service answers to, comma-separated. |
255
+
256
+ ## Development
257
+
258
+ ```bash
259
+ git clone https://github.com/happyc0der/garmin-connect-api
260
+ cd garmin-connect-api
261
+ uv sync
262
+ uv run pytest
263
+ ```
264
+
265
+ 231 offline tests, needing no network and no account, run on Linux, macOS and Windows. They cover the models against real Garmin
266
+ response shapes, the FIT codec's round trip, every one of the 1,527 catalogue exercises against
267
+ the FIT profile, the HTTP routes, and every MCP tool's output against its own advertised schema,
268
+ which strict clients enforce.
269
+
270
+ Tests against a real account are opt-in, and the ones that create data need a second opt-in:
271
+
272
+ ```bash
273
+ GARMIN_LIVE=1 uv run pytest tests/live # read only
274
+ GARMIN_LIVE=1 GARMIN_LIVE_WRITE=1 uv run pytest tests/live # creates, then deletes
275
+ ```
276
+
277
+ ## Why the unofficial route
278
+
279
+ Garmin's official Connect Developer Program is for businesses, has no endpoint that uploads a
280
+ completed activity, and was closed to new applicants in 2026. The aggregators that wrap it cost
281
+ hundreds of dollars a month and are read-only or plans-only. So this uses the endpoints Garmin's
282
+ own website uses, gently: no polling, no retries on a rate limit.
283
+
284
+ ## Citing
285
+
286
+ If you use this in research, cite it with the metadata in [CITATION.cff](https://github.com/happyc0der/garmin-connect-api/blob/main/CITATION.cff);
287
+ GitHub's "Cite this repository" button formats it.
288
+
289
+ ## Licence
290
+
291
+ MIT. Garmin and Garmin Connect are trademarks of Garmin Ltd., used here only to say what this
292
+ works with.
@@ -0,0 +1,258 @@
1
+ # garmin-connect-api
2
+
3
+ Read and write Garmin Connect from an MCP client such as Claude, from Python, or over a local HTTP
4
+ API: activities with per-set strength detail, daily health data, planned workouts, completed
5
+ strength sessions, and weigh-ins with full body composition.
6
+
7
+ <!-- mcp-name: io.github.happyc0der/garmin-connect-api -->
8
+
9
+ > **Unofficial.** Not affiliated with or endorsed by Garmin. It uses the same private endpoints as
10
+ > the Garmin Connect website, through [python-garminconnect](https://github.com/cyberjunky/python-garminconnect),
11
+ > because Garmin offers no public API for individuals. Those endpoints can change without notice,
12
+ > and using them is not sanctioned by Garmin's terms. It is meant for your own account and your
13
+ > own data.
14
+
15
+ ## Status
16
+
17
+ v0.2. Reads activities with per-set strength detail, laps and pool-swim lengths, daily health,
18
+ trends over up to two years and named personal records; writes strength, run, ride and swim
19
+ workouts, completed strength sessions, set corrections and weigh-ins with body composition. 41
20
+ tools, every one checked against a real account. Bug reports and feature requests go to
21
+ [GitHub Issues](https://github.com/happyc0der/garmin-connect-api/issues).
22
+
23
+ ## Quick start
24
+
25
+ You need [uv](https://docs.astral.sh/uv/) and Python 3.12 or newer.
26
+
27
+ **1. Log in once**, at a terminal:
28
+
29
+ ```bash
30
+ uvx --from garmin-connect-api garmin login
31
+ ```
32
+
33
+ This is the only place a password is ever typed. It asks for your Garmin email, password and any
34
+ multi-factor code, then stores tokens in `~/.garmin-api/default`, readable by your user only.
35
+ Nothing else ever prompts for a password; without tokens, every tool says to run this.
36
+
37
+ **2. Add the server to your MCP client.**
38
+
39
+ Claude Code:
40
+
41
+ ```bash
42
+ claude mcp add --scope user --transport stdio garmin -- uvx garmin-connect-api
43
+ ```
44
+
45
+ Claude Desktop, in `claude_desktop_config.json` (in `~/Library/Application Support/Claude/` on
46
+ macOS, `%APPDATA%\Claude\` on Windows):
47
+
48
+ ```json
49
+ {
50
+ "mcpServers": {
51
+ "garmin": {
52
+ "command": "uvx",
53
+ "args": ["garmin-connect-api"]
54
+ }
55
+ }
56
+ }
57
+ ```
58
+
59
+ **3. Ask.** "How did I sleep this week?", "Did my pace hold up in yesterday's swim?",
60
+ "How has my resting heart rate moved since summer?", "Show my last strength session's sets, and
61
+ change sets 3 to 5 to dumbbell rows", "Schedule a swim for Thursday: 200 easy, then 8 x 100 free
62
+ on 20 seconds rest, in a 25-yard pool".
63
+
64
+ ## What it can do
65
+
66
+ 41 tools, each annotated so your client knows which only read (27), which add something (8) and
67
+ which delete or overwrite (6), and can ask before running those.
68
+
69
+ | Read | Write |
70
+ | --- | --- |
71
+ | Activities, filtered by type and date | Create a strength workout, schedule it, push it to a watch |
72
+ | Per-set strength detail: exercise, reps, weight | Create a run, ride or pool swim workout, with targets |
73
+ | Laps for runs and rides; pace per 100 for pool swims | Log a completed strength session, with every set |
74
+ | A day in one answer: steps, heart rate, stress, body battery, sleep, HRV, readiness | Correct a session's sets: exercise, reps, weight |
75
+ | Trends over up to two years: twelve metrics, daily, weekly or monthly | Record a weigh-in, or a full body composition reading |
76
+ | Personal records, named and in units | Rename an activity or change its description |
77
+ | Every weigh-in with body composition | Delete an activity, workout or weigh-in |
78
+ | Planned workouts and the calendar | |
79
+ | Garmin's 1,527-exercise catalogue, offline | |
80
+
81
+ Four tools are written for a model rather than mirrored from an endpoint: `garmin_status` checks
82
+ the login without calling Garmin, `find_exercise` finds Garmin's name for a lift, and
83
+ `recent_strength_sessions` and `week_summary` answer common questions in one call.
84
+
85
+ **Logging a finished workout** is the write Garmin's own developer programme has never offered. A
86
+ session is encoded as a FIT activity file with set messages and uploaded, so it appears in Garmin
87
+ Connect as a Strength Training activity, exercise by exercise.
88
+
89
+ **Body composition** from a smart scale (fat, water, skeletal muscle, bone, BMI, basal metabolic
90
+ rate, visceral fat) is written as a FIT weight-scale file, the way Garmin's own Index scales do it.
91
+ A plain weigh-in carries weight alone.
92
+
93
+ ## Example output
94
+
95
+ Answers come back compact, summarised the way a person would read them. These are from made-up
96
+ data in the shapes Garmin returns.
97
+
98
+ "Did my pace hold up in yesterday's swim?" calls `get_activity_laps`:
99
+
100
+ ```json
101
+ {
102
+ "sport": "lap_swimming",
103
+ "pool_length": 25.0,
104
+ "pool_unit": "m",
105
+ "summary": {
106
+ "lengths": 80,
107
+ "distance": 2000.0,
108
+ "average_pace": "1:52/100m",
109
+ "first_half_pace": "1:50/100m",
110
+ "second_half_pace": "1:54/100m",
111
+ "by_stroke": {"FREESTYLE": 1800.0, "BACKSTROKE": 200.0},
112
+ "fastest_segment": {"lengths": "5-8", "pace": "1:44/100m"},
113
+ "slowest_segment": {"lengths": "77-80", "pace": "2:01/100m"}
114
+ }
115
+ }
116
+ ```
117
+
118
+ "How has my resting heart rate moved since summer?" calls `get_trend`, which rolls a long range
119
+ into weeks:
120
+
121
+ ```json
122
+ {
123
+ "metric": "resting_hr",
124
+ "unit": "bpm",
125
+ "aggregation": "week",
126
+ "summary": {
127
+ "days_with_data": 88,
128
+ "average": 54.2,
129
+ "min": 49.0,
130
+ "max": 61.0,
131
+ "first_period_average": 57.3,
132
+ "last_period_average": 51.6,
133
+ "change": -6.0
134
+ }
135
+ }
136
+ ```
137
+
138
+ ## Before you write anything
139
+
140
+ - **Activities you log may be shared automatically.** If your Garmin account is connected to Strava
141
+ or another app, an uploaded session can be posted there too, and deleting it from Garmin does not
142
+ delete it there.
143
+ - **Rate limits are taken seriously.** Garmin puts Cloudflare and per-account rate limits in front
144
+ of its login, and a run of failed logins can lock an account out for a day or more. Nothing here
145
+ retries a login, and a rate limit stops every call path rather than being retried. If you see
146
+ one, wait.
147
+ - **Exercises need Garmin's own names**, such as `BENCH_PRESS` / `BARBELL_BENCH_PRESS`. Every write
148
+ checks them against the catalogue first and suggests near misses, so a typo fails with a useful
149
+ message rather than Garmin's bare 400. Common gym names work in search: "rdl", "ohp", "pull ups".
150
+ - **Sessions and body-composition readings need a timezone offset**, or a 7am reading would land
151
+ hours out. They are refused without one.
152
+
153
+ ## Command line
154
+
155
+ ```bash
156
+ garmin doctor # setup check, no network
157
+ garmin activities --type strength_training --limit 5
158
+ garmin sets <activity-id> # per-set detail
159
+ garmin day 2026-10-18 # one day of health data
160
+ garmin exercises "lat pulldown" # search the catalogue, offline
161
+ garmin workout create workout.json # plan a strength workout
162
+ garmin log-session session.json # log a completed one
163
+ garmin encode-session session.json # build its FIT file without uploading
164
+ garmin decode-fit activity.zip # read sets out of a Garmin export
165
+ garmin serve # the HTTP API on 127.0.0.1:8765
166
+ ```
167
+
168
+ Run them with `uvx --from garmin-connect-api garmin ...`, or install with
169
+ `uv tool install garmin-connect-api`. Example specs:
170
+ [session.json](https://github.com/happyc0der/garmin-connect-api/blob/main/examples/session.json),
171
+ [workout.json](https://github.com/happyc0der/garmin-connect-api/blob/main/examples/workout.json).
172
+
173
+ An encoded session file can also be imported by hand on the Garmin Connect website, if you would
174
+ rather nothing logged in on your behalf.
175
+
176
+ ## Python library
177
+
178
+ ```python
179
+ from datetime import datetime, timedelta, timezone
180
+ from garmin_api.services import activities, health, uploads
181
+ from garmin_api.models.workouts import (
182
+ StrengthSessionSpec, StrengthSessionExercise, StrengthSessionSet,
183
+ )
184
+
185
+ for activity in activities.list_activities(limit=5, activity_type="strength_training"):
186
+ sets = activities.get_sets(activity.activity_id)
187
+ print(activity.name, sets.total_volume_kg, "kg")
188
+
189
+ print(health.day("2026-10-18").steps)
190
+
191
+ uploads.log_strength_session(StrengthSessionSpec(
192
+ name="Push A",
193
+ start_time=datetime(2026, 10, 18, 7, 0, tzinfo=timezone(timedelta(hours=-4))),
194
+ exercises=[StrengthSessionExercise(
195
+ category="BENCH_PRESS",
196
+ exercise_name="BARBELL_BENCH_PRESS",
197
+ sets=[StrengthSessionSet(reps=10, weight_kg=60.0, rest_s=120)],
198
+ )],
199
+ ))
200
+ ```
201
+
202
+ Responses are pydantic models with Garmin's inconsistencies ironed out: kilograms rather than
203
+ grams, timezone-aware instants, snake_case throughout. Garmin's own payload is still on `raw` when
204
+ something is not mapped.
205
+
206
+ ## HTTP API
207
+
208
+ `garmin serve` runs the same API on `127.0.0.1:8765`, with interactive docs at `/docs`. The MCP
209
+ tools are generated from these routes, so the two cannot drift apart. Because it can write to your
210
+ account, the service refuses writes from web pages open in your browser and requests naming any
211
+ host but `localhost`, which defeats DNS rebinding. Binding beyond localhost requires
212
+ `GARMIN_API_KEY`.
213
+
214
+ ## Configuration
215
+
216
+ | Variable | Purpose |
217
+ | --- | --- |
218
+ | `GARMINTOKENS` | Where tokens are stored. Defaults to `~/.garmin-api/default`. |
219
+ | `GARMIN_API_KEY` | Required to bind the HTTP service beyond localhost. |
220
+ | `GARMIN_API_HOSTS` | Extra host names the HTTP service answers to, comma-separated. |
221
+
222
+ ## Development
223
+
224
+ ```bash
225
+ git clone https://github.com/happyc0der/garmin-connect-api
226
+ cd garmin-connect-api
227
+ uv sync
228
+ uv run pytest
229
+ ```
230
+
231
+ 231 offline tests, needing no network and no account, run on Linux, macOS and Windows. They cover the models against real Garmin
232
+ response shapes, the FIT codec's round trip, every one of the 1,527 catalogue exercises against
233
+ the FIT profile, the HTTP routes, and every MCP tool's output against its own advertised schema,
234
+ which strict clients enforce.
235
+
236
+ Tests against a real account are opt-in, and the ones that create data need a second opt-in:
237
+
238
+ ```bash
239
+ GARMIN_LIVE=1 uv run pytest tests/live # read only
240
+ GARMIN_LIVE=1 GARMIN_LIVE_WRITE=1 uv run pytest tests/live # creates, then deletes
241
+ ```
242
+
243
+ ## Why the unofficial route
244
+
245
+ Garmin's official Connect Developer Program is for businesses, has no endpoint that uploads a
246
+ completed activity, and was closed to new applicants in 2026. The aggregators that wrap it cost
247
+ hundreds of dollars a month and are read-only or plans-only. So this uses the endpoints Garmin's
248
+ own website uses, gently: no polling, no retries on a rate limit.
249
+
250
+ ## Citing
251
+
252
+ If you use this in research, cite it with the metadata in [CITATION.cff](https://github.com/happyc0der/garmin-connect-api/blob/main/CITATION.cff);
253
+ GitHub's "Cite this repository" button formats it.
254
+
255
+ ## Licence
256
+
257
+ MIT. Garmin and Garmin Connect are trademarks of Garmin Ltd., used here only to say what this
258
+ works with.
@@ -0,0 +1,12 @@
1
+ # Security
2
+
3
+ This package holds tokens that can read and change a Garmin Connect account, so please report
4
+ security problems privately rather than in a public issue: use GitHub's
5
+ [private vulnerability reporting](https://github.com/happyc0der/garmin-connect-api/security/advisories/new).
6
+
7
+ What is in scope: anything that could expose stored tokens, let something other than the owner
8
+ reach the local HTTP service or the MCP server's write tools, or write to Garmin without the
9
+ owner asking.
10
+
11
+ Tokens live in `~/.garmin-api/default` (or `GARMINTOKENS`), readable by your user only. If you
12
+ think they have leaked, run `garmin logout` and then `garmin login` to replace them.
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "Push A",
3
+ "start_time": "2026-09-21T07:00:00+02:00",
4
+ "exercises": [
5
+ {
6
+ "category": "BENCH_PRESS",
7
+ "exercise_name": "BARBELL_BENCH_PRESS",
8
+ "sets": [
9
+ { "reps": 10, "weight_kg": 60.0, "rest_s": 120 },
10
+ { "reps": 8, "weight_kg": 65.0, "rest_s": 120 },
11
+ { "reps": 6, "weight_kg": 70.0, "rest_s": 120 }
12
+ ]
13
+ },
14
+ {
15
+ "category": "SHOULDER_PRESS",
16
+ "exercise_name": "DUMBBELL_SHOULDER_PRESS",
17
+ "sets": [
18
+ { "reps": 12, "weight_kg": 20.0, "rest_s": 90 },
19
+ { "reps": 12, "weight_kg": 20.0, "rest_s": 90 }
20
+ ]
21
+ }
22
+ ]
23
+ }