The official Python library for SweatStack
Project description
SweatStack Python Library
Overview
SweatStack is a powerful Python library designed for athletes, coaches, and sports scientists to analyze and manage athletic performance data. It provides a seamless interface to interact with the SweatStack API, allowing users to retrieve, analyze, and visualize activity data, user information, and performance metrics.
Installation
We recommend using uv
to manage Python and install the library.
Read more about uv
here.
uv pip install sweatstack
You can also install it with pip
(or pipx
) directly.
pip install sweatstack
Quickstart
Get started with analyzing your latest activity:
import sweatstack as ss
ss.login()
latest_activity = ss.get_latest_activity()
print(latest_activity) # `latest_activity` is a pandas DataFrame
Authentication
To be able to access your data in Sweat Stack, you need to authenticate the library with your Sweat Stack account. The easiest way to do this is to use your browser to login:
import sweatstack as ss
ss.login()
This will automaticallyset the appropriate authentication tokens in your Python code.
Alternatively, you can set the SWEAT_STACK_API_KEY
environment variable to your API key.
You can create an API key here.
import os
import sweatstack as ss
os.environ["SWEAT_STACK_API_KEY"] = "your_api_key_here"
# Now you can use the library
Listing activities
To list activities, you can use the list_activities()
function:
for activity in ss.list_activities():
print(activity)
Info: This method returns a summary of the activities, not the actual timeseries data. To get the actual data, you need to use the
get_activity_data()
orget_latest_activity_data()
) methods documented below.
Getting activity summaries
To get the summary of an activity, you can use the get_activity()
function:
activity = ss.get_activity(activity_id)
print(activity)
To quickly the latest activity, you can use the get_latest_activity()
function:
activity = ss.get_latest_activity()
print(activity)
Getting activity data
To get the timeseries data of one activity, you can use the get_activity_data()
method:
data = ss.get_activity_data(activity_id)
print(data)
This method returns a pandas DataFrame. If your are not familiar with pandas and/or DataFrames, start by reading this introduction.
Similar as for the summaries, you can use the get_latest_activity_data()
method to get the timeseries data of the latest activity:
data = ss.get_latest_activity_data()
print(data)
To get the timeseries data of multiple activities, you can use the get_longitudinal_data()
method:
longitudinal_data = ss.get_longitudinal_data(
start=date.today() - timedelta(days=180),
sport="running",
metrics=["power", "heart_rate"],
)
print(longitudinal_data)
Because the result of get_longitudinal_data()
can be very large, the data is retrieved in a compressed format (parquet) that requires the pyarrow
library to be installed. If you intend to use this method, make sure to install the sweatstack
libraryr with uv pip install sweatstack[parquet]
.
Also note that depending on the amount of data that you requested, this might take a while.
Accessing other user's data
By default, the library will give you access to your own data.
You can list all users you have access to with the list_accessible_users()
method:
for user in ss.list_accessible_users():
print(user)
You can switch to another user by using the switch_user()
method:
ss.switch_user(user)
Calling any of the methods above will return the data for the user you switched to.
You can easily switch back to your original user by calling the switch_to_root_user()
method:
ss.switch_to_root_user()
Metrics
The API supports the following metrics:
power
: Power in Wattspeed
: Speed in m/sheart_rate
: Heart rate in BPMsmo2
: Muscle oxygen saturation in %core_temperature
: Core body temperature in °Caltitude
: Altitude in meterscadence
: Cadence in RPMtemperature
: Ambient temperature in °Cdistance
: Distance in mlongitude
: Longitude in degreeslatitude
: Latitude in degrees
Sports
The API supports the following sports:
running
: Runningcycling
: Cycling
More sports will be added in the future.
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
Built Distribution
File details
Details for the file sweatstack-0.1.0.tar.gz
.
File metadata
- Download URL: sweatstack-0.1.0.tar.gz
- Upload date:
- Size: 9.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4a252b888d79cff8bf9975ff24c0f3b31c8ff9f59d94d5ed2ba61dbf24b4aa75 |
|
MD5 | 91297af688295a33444c0cec33593866 |
|
BLAKE2b-256 | 5823758a19faa1e3826003266b6d140ea72a5e9efc1171636098f9f392fad352 |
File details
Details for the file sweatstack-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: sweatstack-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d54df4d6dea7c6eb4f9a91a063514089c7ab91e080ba55c4fc5580b5f0e9a31e |
|
MD5 | 2e6d7b55fb7493e9970857ee0e829452 |
|
BLAKE2b-256 | d638cfe5d62a132bde3b76dd3e929d8002935d3e0e7276e516e7f24d0268bcbe |