sweatstack 0.13.1__tar.gz → 0.14.0__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sweatstack
3
- Version: 0.13.1
3
+ Version: 0.14.0
4
4
  Summary: The official Python client for SweatStack
5
5
  Author-email: Aart Goossens <aart@gssns.io>
6
6
  Requires-Python: >=3.12
@@ -13,7 +13,6 @@ Requires-Dist: ipython>=8.31.0; extra == 'jupyterlab'
13
13
  Requires-Dist: jupyterlab>=4.3.4; extra == 'jupyterlab'
14
14
  Requires-Dist: matplotlib; extra == 'jupyterlab'
15
15
  Provides-Extra: streamlit
16
- Requires-Dist: streamlit-cookies-controller>=0.0.4; extra == 'streamlit'
17
16
  Requires-Dist: streamlit>=1.42.0; extra == 'streamlit'
18
17
  Description-Content-Type: text/markdown
19
18
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "sweatstack"
3
- version = "0.13.1"
3
+ version = "0.14.0"
4
4
  description = "The official Python client for SweatStack"
5
5
  readme = "README.md"
6
6
  authors = [
@@ -22,7 +22,6 @@ jupyterlab = [
22
22
  ]
23
23
  streamlit = [
24
24
  "streamlit>=1.42.0",
25
- "streamlit-cookies-controller>=0.0.4",
26
25
  ]
27
26
 
28
27
  [build-system]
@@ -1,7 +1,4 @@
1
- import hashlib
2
- import base64
3
1
  import os
4
- import secrets
5
2
  import urllib.parse
6
3
 
7
4
  try:
@@ -13,58 +10,42 @@ except ImportError:
13
10
  "pip install 'sweatstack[streamlit]'\n\n"
14
11
  )
15
12
  import httpx
16
- from streamlit_cookies_controller import CookieController
17
13
  from sweatstack import Client
18
14
 
19
15
  from .constants import DEFAULT_URL
20
16
 
21
17
 
22
- cookie_controller = CookieController()
23
-
24
-
25
18
  class StreamlitAuth:
26
- def __init__(self, set_env_var=False, client_id=None, client_secret=None, scope=None, redirect_uri=None):
19
+ def __init__(self, client_id=None, client_secret=None, scope=None, redirect_uri=None):
27
20
  """
28
21
  Args:
29
- set_env_var: Whether to set the SWEATSTACK_API_KEY environment variable. Default is False.
30
22
  client_id: The client ID to use. If not provided, the SWEATSTACK_CLIENT_ID environment variable will be used.
31
23
  client_secret: The client secret to use. If not provided, the SWEATSTACK_CLIENT_SECRET environment variable will be used.
32
24
  scope: The scope to use. If not provided, the SWEATSTACK_SCOPE environment variable will be used.
33
25
  redirect_uri: The redirect URI to use. If not provided, the SWEATSTACK_REDIRECT_URI environment variable will be used.
34
26
  """
35
- self.set_env_var = set_env_var
36
27
  self.client_id = client_id or os.environ.get("SWEATSTACK_CLIENT_ID")
37
28
  self.client_secret = client_secret or os.environ.get("SWEATSTACK_CLIENT_SECRET")
38
29
  self.scope = scope or os.environ.get("SWEATSTACK_SCOPE")
39
30
  self.redirect_uri = redirect_uri or os.environ.get("SWEATSTACK_REDIRECT_URI")
40
31
 
41
- self.api_key = cookie_controller.get("sweatstack_api_key")
32
+ self.api_key = st.session_state.get("sweatstack_api_key")
42
33
  self.client = Client(self.api_key)
43
34
 
44
- if self.api_key and self.set_env_var:
45
- os.environ["SWEATSTACK_API_KEY"] = self.api_key
46
-
47
35
  def _show_sweatstack_logout(self):
48
36
  if st.button("Logout"):
49
37
  self.api_key = None
50
38
  self.client = Client()
51
- cookie_controller.remove("sweatstack_api_key")
52
- if self.set_env_var:
53
- os.environ.pop("SWEATSTACK_API_KEY")
39
+ st.session_state.pop("sweatstack_api_key")
40
+ st.rerun()
54
41
 
55
42
  def _show_sweatstack_login(self):
56
43
  st.link_button("Login", self._get_authorization_url_implicit())
57
44
 
58
45
  def _get_authorization_url_implicit(self):
59
- code_verifier = secrets.token_urlsafe(32)
60
- cookie_controller.set("code_verifier", code_verifier)
61
- code_challenge = hashlib.sha256(code_verifier.encode("ascii")).digest()
62
- code_challenge = base64.urlsafe_b64encode(code_challenge).rstrip(b"=").decode("ascii")
63
-
64
46
  params = {
65
47
  "client_id": self.client_id,
66
48
  "redirect_uri": self.redirect_uri,
67
- "code_challenge": code_challenge,
68
49
  "scope": "data:read",
69
50
  }
70
51
  path = "/oauth/authorize"
@@ -72,14 +53,12 @@ class StreamlitAuth:
72
53
 
73
54
  return authorization_url
74
55
 
75
-
76
- def _exchange_token_implicit(self, code):
77
- code_verifier = cookie_controller.get("code_verifier")
56
+ def _exchange_token(self, code):
78
57
  token_data = {
79
58
  "grant_type": "authorization_code",
80
59
  "client_id": self.client_id,
60
+ "client_secret": self.client_secret,
81
61
  "code": code,
82
- "code_verifier": code_verifier
83
62
  }
84
63
  response = httpx.post(
85
64
  f"{DEFAULT_URL}/oauth/token",
@@ -92,14 +71,10 @@ class StreamlitAuth:
92
71
  token_response = response.json()
93
72
 
94
73
  self.api_key = token_response.get("access_token")
95
- cookie_controller.set("sweatstack_api_key", self.api_key)
96
- if self.set_env_var:
97
- os.environ["SWEATSTACK_API_KEY"] = self.api_key
74
+ st.session_state["sweatstack_api_key"] = self.api_key
98
75
 
99
76
  self.client = Client(self.api_key)
100
77
 
101
- cookie_controller.remove("code_verifier")
102
-
103
78
  return
104
79
 
105
80
  def is_authenticated(self):
@@ -109,7 +84,7 @@ class StreamlitAuth:
109
84
  if self.is_authenticated():
110
85
  self._show_sweatstack_logout()
111
86
  elif code := st.query_params.get("code"):
112
- self._exchange_token_implicit(code)
87
+ self._exchange_token(code)
113
88
  st.query_params.clear()
114
89
  st.rerun()
115
90
  else:
@@ -1855,21 +1855,9 @@ wheels = [
1855
1855
  { url = "https://files.pythonhosted.org/packages/ad/dc/69068179e09488d0833a970d06e8bf40e35669a7bddb8a3caadc13b7dff4/streamlit-1.42.0-py2.py3-none-any.whl", hash = "sha256:edf333fd3525b7c64b19e1156b483a1a93cbdb09a3a06f26478388d68f971090", size = 9560180 },
1856
1856
  ]
1857
1857
 
1858
- [[package]]
1859
- name = "streamlit-cookies-controller"
1860
- version = "0.0.4"
1861
- source = { registry = "https://pypi.org/simple" }
1862
- dependencies = [
1863
- { name = "streamlit" },
1864
- ]
1865
- sdist = { url = "https://files.pythonhosted.org/packages/b0/c8/7caf505d62faeb8c0f6e6b74b554e1c2b0c3ca46c0a39250445c574a5a18/streamlit-cookies-controller-0.0.4.tar.gz", hash = "sha256:f5df2543de858f1585dcb6e90f58f38aafbf313ee8e237c64663b2d9761583cc", size = 406305 }
1866
- wheels = [
1867
- { url = "https://files.pythonhosted.org/packages/02/c6/3bbdfecf5009943bcb62d37e3fd4b3fe45e87137e449a50e3025170bc9f7/streamlit_cookies_controller-0.0.4-py3-none-any.whl", hash = "sha256:f97fec6acdeee9cb9e16da25c3fc91d404b5b0ddced87c1d9fa9c62f65ca3251", size = 409303 },
1868
- ]
1869
-
1870
1858
  [[package]]
1871
1859
  name = "sweatstack"
1872
- version = "0.12.0"
1860
+ version = "0.13.2"
1873
1861
  source = { editable = "." }
1874
1862
  dependencies = [
1875
1863
  { name = "httpx" },
@@ -1886,7 +1874,6 @@ jupyterlab = [
1886
1874
  ]
1887
1875
  streamlit = [
1888
1876
  { name = "streamlit" },
1889
- { name = "streamlit-cookies-controller" },
1890
1877
  ]
1891
1878
 
1892
1879
  [package.dev-dependencies]
@@ -1904,7 +1891,6 @@ requires-dist = [
1904
1891
  { name = "pyarrow", specifier = ">=19.0.0" },
1905
1892
  { name = "pydantic", specifier = ">=2.10.5" },
1906
1893
  { name = "streamlit", marker = "extra == 'streamlit'", specifier = ">=1.42.0" },
1907
- { name = "streamlit-cookies-controller", marker = "extra == 'streamlit'", specifier = ">=0.0.4" },
1908
1894
  ]
1909
1895
 
1910
1896
  [package.metadata.requires-dev]
File without changes
File without changes
File without changes
File without changes
File without changes