Skip to main content

Garmin SSO auth + Connect client

Project description

Garth

CI codecov

Garmin SSO auth + Connect client

Google Colabs

Graph 28-day rolling average of daily stress

Background

Garth is meant for personal use and follows the philosiphy that your data is your data. You should be able to download it and analyze it in the way that you'd like. In my case, that means processing with Google Colab, Pandas, Matplotlib, etc.

There are already a few Garmin Connect libraries. Why write another?

Authentication

The most important reasoning is to build a library with authentication that works on Google Colab and doesn't require tools like Cloudscraper. Garth, in comparison:

  1. Uses the same embedded SSO as the mobile app
  2. Only requires requests and pydantic as dependencies
  3. Supports MFA
  4. Supports saving and resuming sessions to avoid the need to log in each time you run a script, which is particularly useful if you have MFA enabled
  5. Works on Google Colab

Python 3.10+

Google Colab, currently, uses 3.10. We should take advantage of all the goodies that come along with it. If you need to use an earlier version of Python, there are other libraries that will meet your needs. There's no intetion to backport.

JSON vs HTML

Using garth.connectapi() allows you to make requests routed to the Connect API and receive JSON vs needing to parse HTML. You can use the same endpoints the mobile app uses.

This also goes back to authentication. Garth manages the necessary Bearer Authentication (along with auto-refresh) necessary to make requests routed to the Connect API.

Instructions

Install

python -m pip install garth

Authenticate and save session

import garth
from getpass import getpass

email = input("Enter email address: ")
password = getpass("Enter password: ")
# If there's MFA, you'll be prompted during the login
garth.login(email, password)

garth.save("~/.garth")

Configure

Set domain for China

garth.configure(domain="garmin.cn")

Proxy through Charles

garth.configure(proxies={"https": "http://localhost:8888"}, ssl_verify=False)

Attempt to resume session

import garth
from garth import GarthException
from requests import HTTPError

garth.resume("~/.garth")
try:
    garth.client.auth_token.refresh()
except (GarthException, HTTPError):
    # Session is expired. You'll need to log in again

Connect API

Wellness

sleep = garth.connectapi(
    f"/wellness-service/wellness/dailySleepData/{garth.client.username}",
    params={"date": "2023-07-05", "nonSleepBufferMinutes": 60),
)
list(sleep.keys())
[
    "dailySleepDTO",
    "sleepMovement",
    "remSleepData",
    "sleepLevels",
    "sleepRestlessMoments",
    "restlessMomentsCount",
    "wellnessSpO2SleepSummaryDTO",
    "wellnessEpochSPO2DataDTOList",
    "wellnessEpochRespirationDataDTOList",
    "sleepStress"
]

Usersummary

stress =  garth.connectapi(f"/usersummary-service/stats/stress/weekly/2023-07-05/52")
{
    "calendarDate": "2023-07-13",
    "values": {
        "highStressDuration": 2880,
        "lowStressDuration": 10140,
        "overallStressLevel": 33,
        "restStressDuration": 30960,
        "mediumStressDuration": 8760
    }
}

Resources

Stress

Daily stress levels

DailyStress.get("2023-07-23", 2)
[
    DailyStress(
        calendar_date=datetime.date(2023, 7, 22),
        overall_stress_level=31,
        rest_stress_duration=31980,
        low_stress_duration=23820,
        medium_stress_duration=7440,
        high_stress_duration=1500
    ),
    DailyStress(
        calendar_date=datetime.date(2023, 7, 23),
        overall_stress_level=26,
        rest_stress_duration=38220,
        low_stress_duration=22500,
        medium_stress_duration=2520,
        high_stress_duration=300
    )
]

Weekly stress levels

WeeklyStress.get("2023-07-23", 2)
[
    WeeklyStress(calendar_date=datetime.date(2023, 7, 10), value=33),
    WeeklyStress(calendar_date=datetime.date(2023, 7, 17), value=32)
]

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

garth-0.2.7.tar.gz (92.1 kB view details)

Uploaded Source

Built Distribution

garth-0.2.7-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file garth-0.2.7.tar.gz.

File metadata

  • Download URL: garth-0.2.7.tar.gz
  • Upload date:
  • Size: 92.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.11

File hashes

Hashes for garth-0.2.7.tar.gz
Algorithm Hash digest
SHA256 3db6d92504c08d681e694cfbf2d2f5fba1e981a38ff8b0e8955674e080114460
MD5 9ca498d518311182dc0f1db7b8fac588
BLAKE2b-256 ecc444936fcec143c64c2d03b29a1b95267fb340fc6f1b0c85c9a0ac3abf37fb

See more details on using hashes here.

File details

Details for the file garth-0.2.7-py3-none-any.whl.

File metadata

  • Download URL: garth-0.2.7-py3-none-any.whl
  • Upload date:
  • Size: 9.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.11

File hashes

Hashes for garth-0.2.7-py3-none-any.whl
Algorithm Hash digest
SHA256 4d5ed55f9dd8ecfde83c74559910d6774bffc180c27a92fb374df746fd610924
MD5 b4607e39ee1c599f295cc9da721d81f3
BLAKE2b-256 cf00140ef60caf07da6256320b566a5373a67855e7eee82154609cb0a52ae37a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page