Skip to content

cyberjunky/python-garminconnect

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Python: Garmin Connect

The Garmin Connect API library comes with two examples:

  • example.py - Simple getting-started example showing authentication, token storage, and basic API calls
  • demo.py - Comprehensive demo providing access to 100+ API methods organized into 11 categories for easy navigation

Note: The demo menu is generated dynamically; exact options may change between releases.

$ ./demo.py
πŸƒβ€β™‚οΈ Full-blown Garmin Connect API Demo - Main Menu
==================================================
Select a category:

  [1] πŸ‘€ User & Profile
  [2] πŸ“Š Daily Health & Activity
  [3] πŸ”¬ Advanced Health Metrics
  [4] πŸ“ˆ Historical Data & Trends
  [5] πŸƒ Activities & Workouts
  [6] βš–οΈ Body Composition & Weight
  [7] πŸ† Goals & Achievements
  [8] ⌚ Device & Technical
  [9] 🎽 Gear & Equipment
  [0] πŸ’§ Hydration & Wellness
  [a] πŸ”§ System & Export

  [q] Exit program

Make your selection:

API Coverage Statistics

  • Total API Methods: 100+ unique endpoints (snapshot)
  • Categories: 11 organized sections
  • User & Profile: 4 methods (basic user info, settings)
  • Daily Health & Activity: 8 methods (today's health data)
  • Advanced Health Metrics: 10 methods (fitness metrics, HRV, VO2)
  • Historical Data & Trends: 6 methods (date range queries)
  • Activities & Workouts: 20 methods (comprehensive activity management)
  • Body Composition & Weight: 8 methods (weight tracking, body composition)
  • Goals & Achievements: 15 methods (challenges, badges, goals)
  • Device & Technical: 7 methods (device info, settings)
  • Gear & Equipment: 6 methods (gear management, tracking)
  • Hydration & Wellness: 9 methods (hydration, blood pressure, menstrual)
  • System & Export: 4 methods (reporting, logout, GraphQL)

Interactive Features

  • Enhanced User Experience: Categorized navigation with emoji indicators
  • Smart Data Management: Interactive weigh-in deletion with search capabilities
  • Comprehensive Coverage: All major Garmin Connect features are accessible
  • Error Handling: Robust error handling with user-friendly prompts
  • Data Export: JSON export functionality for all data types

Donate via PayPal Sponsor on GitHub

A comprehensive Python3 API wrapper for Garmin Connect, providing access to health, fitness, and device data.

πŸ“– About

This library enables developers to programmatically access Garmin Connect data including:

  • Health Metrics: Heart rate, sleep, stress, body composition, SpO2, HRV
  • Activity Data: Workouts, exercises, training status, performance metrics
  • Device Information: Connected devices, settings, alarms, solar data
  • Goals & Achievements: Personal records, badges, challenges, race predictions
  • Historical Data: Trends, progress tracking, date range queries

Compatible with all Garmin Connect accounts. See https://connect.garmin.com/

πŸ“¦ Installation

Install from PyPI:

python3 -m pip install --upgrade pip
python3 -m pip install garminconnect

Run demo software (recommended)

python3 -m venv .venv --copies
source .venv/bin/activate  # On Windows: .venv\Scripts\activate
pip install pdm
pdm install --group :example

# Run the simple example
python3 ./example.py

# Run the comprehensive demo
python3 ./demo.py

πŸ› οΈ Development

Set up a development environment for contributing:

Note: This project uses PDM for modern Python dependency management and task automation. All development tasks are configured as PDM scripts in pyproject.toml. The Python interpreter is automatically configured to use .venv/bin/python when you create the virtual environment.

Environment Setup:

⚠️ Important: On externally-managed Python environments (like Debian/Ubuntu), you must create a virtual environment before installing PDM to avoid system package conflicts.

# 1. Create and activate a virtual environment
python3 -m venv .venv --copies
source .venv/bin/activate  # On Windows: .venv\Scripts\activate

# 2. Install PDM (Python Dependency Manager)
pip install pdm

# 3. Install all development dependencies
pdm install --group :all

# 4. Install optional tools for enhanced development experience
pip install "black[jupyter]" codespell pre-commit

# 5. Setup pre-commit hooks (optional)
pre-commit install --install-hooks

Alternative for System-wide PDM Installation:

# Install PDM via pipx (recommended for system-wide tools)
python3 -m pip install --user pipx
pipx install pdm

# Then proceed with project setup
pdm install --group :all

Available Development Commands:

pdm run format      # Auto-format code (isort, black, ruff --fix)
pdm run lint        # Check code quality (isort, ruff, black, mypy)
pdm run codespell   # Check spelling errors (install codespell if needed)
pdm run test        # Run test suite
pdm run testcov     # Run tests with coverage report
pdm run all         # Run all checks
pdm run clean      # Clean build artifacts and cache files
pdm run build      # Build package for distribution
pdm run publish    # Build and publish to PyPI

View all available commands:

pdm run --list     # Display all available PDM scripts

Code Quality Workflow:

# Before making changes
pdm run lint       # Check current code quality

# After making changes
pdm run format     # Auto-format your code
pdm run lint       # Verify code quality
pdm run codespell  # Check spelling
pdm run test       # Run tests to ensure nothing broke

Run these commands before submitting PRs to ensure code quality standards.

πŸ” Authentication

The library uses the same OAuth authentication as the official Garmin Connect app via Garth.

Key Features:

  • Login credentials valid for one year (no repeated logins)
  • Secure OAuth token storage
  • Same authentication flow as official app

Advanced Configuration:

# Optional: Custom OAuth consumer (before login)
import os
import garth
garth.sso.OAUTH_CONSUMER = {
    'key': os.getenv('GARTH_OAUTH_KEY', '<YOUR_KEY>'),
    'secret': os.getenv('GARTH_OAUTH_SECRET', '<YOUR_SECRET>'),
}
# Note: Set these env vars securely; placeholders are non-sensitive.

Token Storage: Tokens are automatically saved to ~/.garminconnect directory for persistent authentication. For security, ensure restrictive permissions:

chmod 700 ~/.garminconnect
chmod 600 ~/.garminconnect/* 2>/dev/null || true

πŸ§ͺ Testing

Run the test suite to verify functionality:

Prerequisites:

Create tokens in ~/.garminconnect by running the example program.

# Install development dependencies
pdm install --group :all

Run Tests:

pdm run test        # Run all tests
pdm run testcov     # Run tests with coverage report

Optional: keep test tokens isolated

export GARMINTOKENS="$(mktemp -d)"
python3 ./example.py # create fresh tokens for tests
pdm run test

Note: Tests automatically use ~/.garminconnect as the default token file location. You can override this by setting the GARMINTOKENS environment variable. Run example.py first to generate authentication tokens for testing.

For Developers: Tests use VCR cassettes to record/replay HTTP interactions. If tests fail with authentication errors, ensure valid tokens exist in ~/.garminconnect

πŸ“¦ Publishing

For package maintainers:

Setup PyPI credentials:

pip install twine
# Edit with your preferred editor, or create via here-doc:
# cat > ~/.pypirc <<'EOF'
# [pypi]
# username = __token__
# password = <PyPI_API_TOKEN>
# EOF
[pypi]
username = __token__
password = <PyPI_API_TOKEN>

Recommended: use environment variables and restrict file perms

chmod 600 ~/.pypirc
export TWINE_USERNAME="__token__"
export TWINE_PASSWORD="<PyPI_API_TOKEN>"

Publish new version:

pdm run publish    # Build and publish to PyPI

Alternative publishing steps:

pdm run build      # Build package only
pdm publish        # Publish pre-built package

🀝 Contributing

We welcome contributions! Here's how you can help:

  • Report Issues: Bug reports and feature requests via GitHub issues
  • Submit PRs: Code improvements, new features, documentation updates
  • Testing: Help test new features and report compatibility issues
  • Documentation: Improve examples, add use cases, fix typos

Before Contributing:

  1. Set up development environment (pdm install --group :all)
  2. Execute code quality checks (pdm run format && pdm run lint)
  3. Test your changes (pdm run test)
  4. Follow existing code style and patterns

Development Workflow:

# 1. Setup environment (with virtual environment)
python3 -m venv .venv --copies
source .venv/bin/activate
pip install pdm
pdm install --group :all

# 2. Make your changes
# ... edit code ...

# 3. Quality checks
pdm run format     # Auto-format code
pdm run lint       # Check code quality
pdm run test       # Run tests

# 4. Submit PR
git commit -m "Your changes"
git push origin your-branch

Jupyter Notebook

Explore the API interactively with our reference notebook.

Python Code Examples

from garminconnect import Garmin
import os

# Initialize and login
client = Garmin(
    os.getenv("GARMIN_EMAIL", "<YOUR_EMAIL>"),
    os.getenv("GARMIN_PASSWORD", "<YOUR_PASSWORD>")
)
client.login()

# Get today's stats
from datetime import date
_today = date.today().strftime('%Y-%m-%d')
stats = client.get_stats(_today)

# Get heart rate data
hr_data = client.get_heart_rates(_today)
print(f"Resting HR: {hr_data.get('restingHeartRate', 'n/a')}")

Additional Resources

  • Simple Example: example.py - Getting started guide
  • Comprehensive Demo: demo.py - All 101 API methods
  • API Documentation: Comprehensive method documentation in source code
  • Test Cases: Real-world usage examples in tests/ directory

πŸ™ Acknowledgments

Special thanks to all contributors who have helped improve this project:

  • Community Contributors: Bug reports, feature requests, and code improvements
  • Issue Reporters: Helping identify and resolve compatibility issues
  • Feature Developers: Adding new API endpoints and functionality
  • Documentation Authors: Improving examples and user guides

This project thrives thanks to community involvement and feedback.

πŸ’– Support This Project

If you find this library useful for your projects, please consider supporting its continued development and maintenance:

🌟 Ways to Support

  • ⭐ Star this repository - Help others discover the project
  • πŸ’° Financial Support - Contribute to development and hosting costs
  • πŸ› Report Issues - Help improve stability and compatibility
  • πŸ“– Spread the Word - Share with other developers

πŸ’³ Financial Support Options

Donate via PayPal Sponsor on GitHub

Why Support?

  • Keeps the project actively maintained
  • Enables faster bug fixes and new features
  • Supports infrastructure costs (testing, AI, CI/CD)
  • Shows appreciation for hundreds of hours of development

Every contribution, no matter the size, makes a difference and is greatly appreciated! πŸ™

About

Python 3 API wrapper for Garmin Connect to get statistics and set activities

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Contributors 49

Languages