Streamlit¶
SweatStack provides a Streamlit integration for building interactive web applications.
This requires installing the optional streamlit dependency group:
uv pip install "sweatstack[streamlit]"
Register a new API application in your SweatStack account: app.sweatstack.no/settings/api and create a secret for it.
Now you can use the StreamlitAuth component to authenticate your users:
import streamlit as st
from sweatstack.streamlit import StreamlitAuth
# Initialize the authentication component
auth = StreamlitAuth(
    client_id="YOUR_APPLICATION_ID",
    client_secret="YOUR_APPLICATION_SECRET",
    redirect_uri="http://localhost:8501",
)
# Add authentication component (to the sidebar in this case)
with st.sidebar:
    auth.authenticate()
# Check if user is authenticated
if not auth.is_authenticated():
    st.write("Please log in to continue")
    st.stop()
# User is authenticated - use the client
st.write("Welcome to SweatStack")
latest_activity = auth.client.get_latest_activity()
st.write(f"Latest activity: {latest_activity.sport} on {latest_activity.start}")
# Show a Streamlit selectbox to switch between accessible users
with st.sidebar:
    auth.select_user()
Streamlit
When using Streamlit, you cannot use the "singleton" interface (i.e. ss.get_activities(), ss.get_sports(), etc.) as this will not work with how Streamlit manages (Python) sessions:
You have to use the Client instance returned by StreamlitAuth.client (see example above) or one of the methods listed below to make requests to SweatStack.
Available methods are:
auth.is_authenticated()auth.logout()auth.select_user()auth.select_activity()auth.select_sport()auth.select_tag()auth.select_metric()auth.client.get_authorization_url()
redirect_uri
The redirect_uri is the URL of your Streamlit application.
For local development, this is probably http://localhost:8501.
Make sure to update this when deploying your application and don't forget to add the application URI to your API application in your SweatStack account.