sweatstack 0.21.0__py3-none-any.whl → 0.22.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- sweatstack/client.py +21 -1
- sweatstack-0.22.1.dist-info/METADATA +24 -0
- {sweatstack-0.21.0.dist-info → sweatstack-0.22.1.dist-info}/RECORD +5 -5
- sweatstack-0.21.0.dist-info/METADATA +0 -116
- {sweatstack-0.21.0.dist-info → sweatstack-0.22.1.dist-info}/WHEEL +0 -0
- {sweatstack-0.21.0.dist-info → sweatstack-0.22.1.dist-info}/entry_points.txt +0 -0
sweatstack/client.py
CHANGED
|
@@ -540,11 +540,31 @@ class Client(OAuth2Mixin, DelegationMixin):
|
|
|
540
540
|
params["limit"] = min(default_limit, limit - num_returned)
|
|
541
541
|
params["offset"] += default_limit
|
|
542
542
|
|
|
543
|
+
def _prepare_unserialized_data(self, df: pd.DataFrame, column: str) -> pd.DataFrame:
|
|
544
|
+
"""
|
|
545
|
+
pd.json_normalize() only likes to play with lists of records (dicts?), not lists of lists.
|
|
546
|
+
So that's what we're feeding it.
|
|
547
|
+
"""
|
|
548
|
+
unserialized_data = df[column].tolist()
|
|
549
|
+
if column in ["laps", "traces"]:
|
|
550
|
+
result = []
|
|
551
|
+
for sublist in unserialized_data:
|
|
552
|
+
if sublist:
|
|
553
|
+
dict_from_sublist = {i: value for i, value in enumerate(sublist) if sublist}
|
|
554
|
+
else:
|
|
555
|
+
dict_from_sublist = {}
|
|
556
|
+
result.append(dict_from_sublist)
|
|
557
|
+
|
|
558
|
+
unserialized_data = result
|
|
559
|
+
|
|
560
|
+
return unserialized_data
|
|
561
|
+
|
|
543
562
|
def _normalize_dataframe_column(self, df: pd.DataFrame, column: str) -> pd.DataFrame:
|
|
544
563
|
normalized = pd.json_normalize(
|
|
545
|
-
df
|
|
564
|
+
self._prepare_unserialized_data(df, column),
|
|
546
565
|
)
|
|
547
566
|
normalized = normalized.add_prefix(f"{column}.")
|
|
567
|
+
normalized.index = df.index
|
|
548
568
|
if column == "activity":
|
|
549
569
|
normalized = normalized.drop(["activity.traces", "activity.laps"], axis=1, errors="ignore")
|
|
550
570
|
return pd.concat([df.drop(column, axis=1), normalized], axis=1)
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: sweatstack
|
|
3
|
+
Version: 0.22.1
|
|
4
|
+
Summary: The official Python client for SweatStack
|
|
5
|
+
Author-email: Aart Goossens <aart@gssns.io>
|
|
6
|
+
Requires-Python: >=3.12
|
|
7
|
+
Requires-Dist: httpx>=0.28.1
|
|
8
|
+
Requires-Dist: pandas>=2.2.3
|
|
9
|
+
Requires-Dist: pyarrow>=19.0.0
|
|
10
|
+
Requires-Dist: pydantic>=2.10.5
|
|
11
|
+
Provides-Extra: jupyter
|
|
12
|
+
Requires-Dist: ipython>=8.31.0; extra == 'jupyter'
|
|
13
|
+
Requires-Dist: jupyterlab>=4.3.4; extra == 'jupyter'
|
|
14
|
+
Requires-Dist: matplotlib>=3.10.0; extra == 'jupyter'
|
|
15
|
+
Provides-Extra: streamlit
|
|
16
|
+
Requires-Dist: streamlit>=1.42.0; extra == 'streamlit'
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
|
|
19
|
+
# SweatStack Python client library
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
This is the official Python client library for SweatStack.
|
|
23
|
+
|
|
24
|
+
Documentation can be found [here](https://sweatstack.no/python-client-library/).
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
sweatstack/__init__.py,sha256=tiVfgKlswRPaDMEy0gA7u8rveqEYZTA_kyB9lJ3J6Sc,21
|
|
2
2
|
sweatstack/cli.py,sha256=N1NWOgEZR2yaJvIXxo9qvp_jFlypZYb0nujpbVNYQ6A,720
|
|
3
|
-
sweatstack/client.py,sha256=
|
|
3
|
+
sweatstack/client.py,sha256=09c9f-ij0Pe4MIoCQustskz8YGxpzUxpSeVoCI2deLk,23713
|
|
4
4
|
sweatstack/constants.py,sha256=fGO6ksOv5HeISv9lHRoYm4besW1GTveXS8YD3K0ljg0,41
|
|
5
5
|
sweatstack/ipython_init.py,sha256=zBGUlMFkdpLvsNpOpwrNaKRUpUZhzaICvH8ODJgMPcI,229
|
|
6
6
|
sweatstack/jupyterlab_oauth2_startup.py,sha256=eZ6xi0Sa4hO4vUanimq0SqjduHtiywCURSDNWk_I-7s,1200
|
|
@@ -11,7 +11,7 @@ sweatstack/streamlit.py,sha256=F5oQdWkcJ76Um5fRqFT5QrjpEz8v3OaiH9kMQOYktgo,4466
|
|
|
11
11
|
sweatstack/sweatshell.py,sha256=MYLNcWbOdceqKJ3S0Pe8dwHXEeYsGJNjQoYUXpMTftA,333
|
|
12
12
|
sweatstack/utils.py,sha256=HtR1NNCKus59vfgfaCSFS-tHA11mtdcuUx5lS6ZX58g,1773
|
|
13
13
|
sweatstack/Sweat Stack examples/Getting started.ipynb,sha256=k2hiSffWecoQ0VxjdpDcgFzBXDQiYEebhnAYlu8cgX8,6335204
|
|
14
|
-
sweatstack-0.
|
|
15
|
-
sweatstack-0.
|
|
16
|
-
sweatstack-0.
|
|
17
|
-
sweatstack-0.
|
|
14
|
+
sweatstack-0.22.1.dist-info/METADATA,sha256=hq8tYbkShOb5KqTObhqkuMa4UR8Afu7plg7fKnQPJbA,776
|
|
15
|
+
sweatstack-0.22.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
16
|
+
sweatstack-0.22.1.dist-info/entry_points.txt,sha256=kCzOUQI3dqbTpEYqtgYDeiKFaqaA7BMlV6D24BMzCFU,208
|
|
17
|
+
sweatstack-0.22.1.dist-info/RECORD,,
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: sweatstack
|
|
3
|
-
Version: 0.21.0
|
|
4
|
-
Summary: The official Python client for SweatStack
|
|
5
|
-
Author-email: Aart Goossens <aart@gssns.io>
|
|
6
|
-
Requires-Python: >=3.12
|
|
7
|
-
Requires-Dist: httpx>=0.28.1
|
|
8
|
-
Requires-Dist: pandas>=2.2.3
|
|
9
|
-
Requires-Dist: pyarrow>=19.0.0
|
|
10
|
-
Requires-Dist: pydantic>=2.10.5
|
|
11
|
-
Provides-Extra: jupyter
|
|
12
|
-
Requires-Dist: ipython>=8.31.0; extra == 'jupyter'
|
|
13
|
-
Requires-Dist: jupyterlab>=4.3.4; extra == 'jupyter'
|
|
14
|
-
Requires-Dist: matplotlib>=3.10.0; extra == 'jupyter'
|
|
15
|
-
Provides-Extra: streamlit
|
|
16
|
-
Requires-Dist: streamlit>=1.42.0; extra == 'streamlit'
|
|
17
|
-
Description-Content-Type: text/markdown
|
|
18
|
-
|
|
19
|
-
# SweatStack Python client library
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
# Quickstart
|
|
23
|
-
|
|
24
|
-
```
|
|
25
|
-
uv pip install sweatstack
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
```python
|
|
29
|
-
import sweatstack as ss
|
|
30
|
-
|
|
31
|
-
ss.login()
|
|
32
|
-
|
|
33
|
-
ss.list_activities()
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
# Authentication
|
|
38
|
-
|
|
39
|
-
SweatStack supports three authentication methods:
|
|
40
|
-
|
|
41
|
-
### 1. Browser-Based OAuth2 Authentication
|
|
42
|
-
```python
|
|
43
|
-
ss.login() # Opens your default browser for authentication
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
### 2. Direct API Key Authentication
|
|
47
|
-
```python
|
|
48
|
-
client = ss.Client(api_key="your-api-key")
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
### 3. Environment Variable
|
|
52
|
-
Set the `SWEATSTACK_API_KEY` environment variable:
|
|
53
|
-
```bash
|
|
54
|
-
export SWEATSTACK_API_KEY="your-api-key"
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
SweatStack follows this priority order:
|
|
58
|
-
|
|
59
|
-
1. Browser-based OAuth2 (`ss.login()`)
|
|
60
|
-
2. Direct API key via `Client` constructor
|
|
61
|
-
3. `SWEATSTACK_API_KEY` environment variable
|
|
62
|
-
|
|
63
|
-
For example, calling `ss.login()` or `client.login()` will override any existing API key authentication, including those set through the constructor or environment variables.
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
## Interfaces: Singleton vs Class-based
|
|
67
|
-
|
|
68
|
-
This library provides both a singleton interface and a class-based interface.
|
|
69
|
-
|
|
70
|
-
Singleton interface:
|
|
71
|
-
```python
|
|
72
|
-
import sweatstack as ss
|
|
73
|
-
|
|
74
|
-
activities = ss.list_activities()
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
Class-based interface:
|
|
78
|
-
```python
|
|
79
|
-
from sweatstack import Client
|
|
80
|
-
|
|
81
|
-
client = Client()
|
|
82
|
-
activities = client.list_activities()
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
Although both interfaces are feature-equivalent, they serve different purposes:
|
|
86
|
-
- The singleton interface is the default and recommended interface. It is intended for most use cases and is the easiest to use.
|
|
87
|
-
- The class-based interface is intended for more advanced use cases, such as when you need to authenticate multiple users at the same time or in multi-threaded applications.
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
## Streamlit integration
|
|
91
|
-
|
|
92
|
-
The `sweatstack.streamlit` module provides a Streamlit integration for SweatStack. This requires the optional `streamlit` dependency that can be installed with:
|
|
93
|
-
```
|
|
94
|
-
uv pip install 'sweatstack[streamlit]'
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
The `StreamlitAuth` class is a Streamlit component that handles the OAuth2 authentication flow. It provides a `st.authenticate()` function that can be used to authenticate the user.
|
|
98
|
-
|
|
99
|
-
Example usage:
|
|
100
|
-
|
|
101
|
-
```python
|
|
102
|
-
from sweatstack.streamlit import StreamlitAuth
|
|
103
|
-
|
|
104
|
-
auth = StreamlitAuth()
|
|
105
|
-
|
|
106
|
-
with st.sidebar:
|
|
107
|
-
st.authenticate()
|
|
108
|
-
|
|
109
|
-
if not auth.is_authenticated():
|
|
110
|
-
st.write("User is not authenticated")
|
|
111
|
-
st.stop()
|
|
112
|
-
|
|
113
|
-
st.write("User is authenticated")
|
|
114
|
-
|
|
115
|
-
auth.client.get_latest_activity()
|
|
116
|
-
```
|
|
File without changes
|
|
File without changes
|