Authentication¶
Single-user mode¶
SweatStack supports three authentication methods in order of priority:
1. Browser-Based OAuth2 Authentication¶
This is the recommended authentication method for most users. It opens your default browser for the SweatStack authentication flow:
import sweatstack
sweatstack.login() # Opens your default browser for authentication
2. Direct API Key Authentication¶
Provide your API key directly when creating a client:
from sweatstack import Client
client = Client(api_key="your-api-key")
3. Environment Variable¶
Set the SWEATSTACK_API_KEY environment variable:
export SWEATSTACK_API_KEY="your-api-key"
Then use the library without explicit authentication:
import sweatstack
activities = sweatstack.get_activities() # Uses SWEATSTACK_API_KEY
Authentication Priority:
1. Browser-based OAuth2 (sweatstack.login())
2. Direct API key via Client constructor
3. SWEATSTACK_API_KEY environment variable
Application authentication¶
SweatStack offers application authentication that follows the OAuth2/OpenID Connect specification. This allows third-party applications to request authorization from users without exposing their credentials.
The .well-known endpoints (OpenID configuration, JWKS) are listed in the API reference. To call them against your account, open the API playground.
User Switching¶
Quickly switch between users you have access to:
import sweatstack
# Get all accessible users
users = sweatstack.get_users()
# Switch to a specific user (for coaches/managers)
sweatstack.switch_user(users[0])
# ...or reate a delegated client for a specific user
athlete_client = sweatstack.delegated_client(users[0])
athlete_activities = athlete_client.get_activities()
# Switch back to your principal user (i.e. the logged in user)
sweatstack.switch_back()