Overview
This guide explains how to build custom provider integrations for new health devices or platforms. The provider system is designed to make adding new integrations straightforward while maintaining security and data quality.If you’re looking to use existing providers like Garmin or Whoop, see Using Providers instead.
Prerequisites
Before integrating a new provider, ensure you have:Technical Requirements
Technical Requirements
- Python 3.12+ environment
- Access to the target device/service API documentation
- OAuth credentials (OAuth 1.0 or OAuth 2.0) from the device vendor
- Understanding of async/await patterns in Python
- Familiarity with REST APIs and JSON data formats
OAuth Credentials
OAuth Credentials
Obtain OAuth credentials from the health device vendor:
- Client ID / Consumer Key
- Client Secret / Consumer Secret
- API endpoints for authentication and data access
- OAuth scopes required for health data access
Database Setup
Database Setup
Your provider needs a dedicated table for raw data storage:
Provider Architecture
Directory Structure
Class Hierarchy
Quick Start
1
Create provider module
Create a new directory for your provider:
2
Implement provider class
Create your provider class inheriting from
BaseThetaProvider:provider_yourprovider.py
3
Configure OAuth
Add configuration to
config.yaml:4
Test your provider
Test the OAuth flow and data fetching:
Implementation Checklist
Required Methods
Required Methods
Your provider must implement:
- ✅
factory()- Provider instantiation - ✅
info()- Provider metadata - ✅
link()- Initiate OAuth flow - ✅
callback()- Handle OAuth callback - ✅
unlink()- Disconnect provider - ✅
pull_from_vendor_api()- Fetch data from API - ✅
format_data()- Transform to standard format - ✅
save_raw_data_to_db()- Persist raw data - ✅
is_data_already_processed()- Check for duplicates
OAuth Implementation
OAuth Implementation
Choose OAuth version based on provider requirements:OAuth 1.0 (e.g., Garmin):
- Request token
- User authorization
- Access token exchange
- Authorization code
- Token exchange
- Token refresh handling
Data Mapping
Data Mapping
Testing
Testing
Test your provider thoroughly:
- Unit tests for each method
- OAuth flow integration tests
- Data transformation tests
- Error handling tests
Key Concepts
Provider Lifecycle
Data Flow
- Raw Data Fetch: Pull data from vendor API
- Raw Data Storage: Save to provider-specific table
- Transformation: Convert to standard indicators
- Standard Storage: Save to
th_series_datatable - Deduplication: Skip already-processed records
Configuration
Add provider configuration toconfig.yaml:
config.yaml
Example: Minimal Provider
Here’s a minimal provider implementation:Detailed Documentation
For comprehensive implementation details, refer to these guides:OAuth Implementation
Implement OAuth 1.0 or 2.0 flows
Data Mapping
Transform vendor data to standard format
Provider Testing
Test your provider integration
Full Integration Guide
Complete guide in repository
Standard Health Indicators
Map your provider’s data to these standard indicators:| Indicator | Description | Unit |
|---|---|---|
DAILY_STEPS | Daily step count | steps |
DAILY_SLEEP_DURATION | Total sleep time | milliseconds |
HEART_RATE | Heart rate measurement | bpm |
DAILY_HEART_RATE_RESTING | Resting heart rate | bpm |
HRV | Heart rate variability | ms |
WEIGHT | Body weight | grams |
DAILY_CALORIES_ACTIVE | Active calories burned | kcal |
SLEEP_EFFICIENCY | Sleep efficiency | percentage |
Contributing Your Provider
Once you’ve built a provider, consider contributing it back:1
Test thoroughly
Ensure all OAuth flows work and data transforms correctly
2
Document your provider
Add configuration instructions and supported metrics
3
Submit pull request
Follow the Contributing Guide
See the complete Provider Integration Guide in the repository for detailed implementation instructions, including all required methods, OAuth patterns, data transformation examples, and best practices.