ml-dash 0.6.9__py3-none-any.whl → 0.6.10__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.
ml_dash/__init__.py CHANGED
@@ -36,14 +36,60 @@ Usage:
36
36
  exp.log("Training started")
37
37
  """
38
38
 
39
- from .client import RemoteClient
39
+ from .client import RemoteClient, userinfo
40
40
  from .experiment import Experiment, OperationMode, ml_dash_experiment
41
41
  from .log import LogBuilder, LogLevel
42
42
  from .params import ParametersBuilder
43
43
  from .run import RUN
44
44
  from .storage import LocalStorage
45
45
 
46
- __version__ = "0.6.4"
46
+ __version__ = "0.6.10"
47
+
48
+ # Minimum version required - blocks older versions
49
+ MINIMUM_REQUIRED_VERSION = "0.6.10"
50
+
51
+
52
+ def _check_version_compatibility():
53
+ """
54
+ Enforce minimum version requirement.
55
+
56
+ Raises ImportError if installed version is below minimum required version.
57
+ This ensures users have the latest features (userinfo, namespace auto-detection, etc.)
58
+ """
59
+ try:
60
+ from packaging import version
61
+ except ImportError:
62
+ # If packaging is not available, skip check
63
+ # (unlikely since it's a common dependency)
64
+ return
65
+
66
+ current = version.parse(__version__)
67
+ minimum = version.parse(MINIMUM_REQUIRED_VERSION)
68
+
69
+ if current < minimum:
70
+ raise ImportError(
71
+ f"\n"
72
+ f"{'=' * 80}\n"
73
+ f"ERROR: ml-dash version {__version__} is too old!\n"
74
+ f"{'=' * 80}\n"
75
+ f"\n"
76
+ f"This version of ml-dash ({__version__}) is no longer supported.\n"
77
+ f"Minimum required version: {MINIMUM_REQUIRED_VERSION}\n"
78
+ f"\n"
79
+ f"Please upgrade to the latest version:\n"
80
+ f"\n"
81
+ f" pip install --upgrade ml-dash\n"
82
+ f"\n"
83
+ f"Or install specific version:\n"
84
+ f"\n"
85
+ f" pip install ml-dash>={MINIMUM_REQUIRED_VERSION}\n"
86
+ f"\n"
87
+ f"{'=' * 80}\n"
88
+ )
89
+
90
+
91
+ # Enforce version check on import
92
+ _check_version_compatibility()
47
93
 
48
94
  __all__ = [
49
95
  "Experiment",
@@ -55,4 +101,5 @@ __all__ = [
55
101
  "LogBuilder",
56
102
  "ParametersBuilder",
57
103
  "RUN",
104
+ "userinfo",
58
105
  ]
@@ -292,12 +292,3 @@ def decode_jwt_payload(token: str) -> dict:
292
292
  return {}
293
293
 
294
294
 
295
- def get_jwt_user():
296
- # Load token
297
- storage = get_token_storage()
298
- token = storage.load("ml-dash-token")
299
-
300
- if token:
301
- user = decode_jwt_payload(token)
302
- return user
303
- return None
ml_dash/auto_start.py CHANGED
@@ -31,19 +31,34 @@ import atexit
31
31
  # Token is auto-loaded from storage when first used
32
32
  # If not authenticated, operations will fail with AuthenticationError
33
33
  # Prefix format: {owner}/{project}/path...
34
- # Using getpass to get current user as owner for local convenience
35
34
  import getpass
36
35
  from datetime import datetime
37
36
 
38
- from .auth.token_storage import get_jwt_user
39
37
  from .experiment import Experiment
40
38
 
41
- _user = get_jwt_user()
42
- # Fallback to system username if not authenticated
43
- _username = _user["username"] if _user else getpass.getuser()
39
+ # Get username for dxp namespace
40
+ # Note: We use userinfo for fresh data (recommended approach)
41
+ # Falls back to system username if not authenticated
42
+ try:
43
+ from .client import userinfo
44
+ _username = userinfo.username or getpass.getuser()
45
+ except Exception:
46
+ # If userinfo fails (e.g., no network), fall back to system user
47
+ _username = getpass.getuser()
48
+
44
49
  _now = datetime.now()
45
50
 
46
- dxp = Experiment()
51
+ # Create pre-configured singleton experiment in REMOTE mode
52
+ # - dash_url=True: Use default remote server (https://api.dash.ml)
53
+ # - dash_root=None: Remote-only mode (no local storage)
54
+ # - user: Uses authenticated username from userinfo (fresh from server)
55
+ # - Token is auto-loaded from storage when first used
56
+ # - If not authenticated, operations will fail with AuthenticationError
57
+ dxp = Experiment(
58
+ user=_username, # Use authenticated username for namespace
59
+ dash_url=True, # Use remote API (https://api.dash.ml)
60
+ dash_root=None, # Remote-only mode (no local .dash/)
61
+ )
47
62
 
48
63
 
49
64
  # Register cleanup handler to complete experiment on Python exit (if still open)
@@ -24,9 +24,9 @@ def add_parser(subparsers):
24
24
  help="Output as JSON",
25
25
  )
26
26
  parser.add_argument(
27
- "--refresh",
27
+ "--cached",
28
28
  action="store_true",
29
- help="Fetch fresh profile from server (not from cached token)",
29
+ help="Use cached token data (default: fetch fresh from server)",
30
30
  )
31
31
 
32
32
 
@@ -45,27 +45,17 @@ def _fetch_fresh_profile(remote_url: str, token: str) -> dict:
45
45
 
46
46
  client = RemoteClient(remote_url, api_key=token)
47
47
 
48
- # Query for full user profile
49
- query = """
50
- query GetUserProfile {
51
- me {
52
- id
53
- username
54
- name
55
- email
56
- }
57
- }
58
- """
59
-
60
- result = client.graphql_query(query)
61
- me = result.get("me", {})
48
+ # Use the new get_current_user() method
49
+ user_data = client.get_current_user()
62
50
 
63
- if me:
51
+ if user_data:
64
52
  return {
65
- "sub": me.get("id"),
66
- "username": me.get("username"),
67
- "name": me.get("name"),
68
- "email": me.get("email"),
53
+ "sub": user_data.get("id"),
54
+ "username": user_data.get("username"),
55
+ "name": user_data.get("name"),
56
+ "email": user_data.get("email"),
57
+ "given_name": user_data.get("given_name"),
58
+ "family_name": user_data.get("family_name"),
69
59
  }
70
60
  except Exception as e:
71
61
  # If API call fails, return None to fall back to token decoding
@@ -131,8 +121,13 @@ def cmd_profile(args) -> int:
131
121
  info["authenticated"] = False
132
122
  info["error"] = "Token expired. Please run 'ml-dash login' to re-authenticate."
133
123
  else:
134
- # Fetch fresh profile from server if requested, or fall back to token
135
- if args.refresh:
124
+ # Fetch fresh profile from server by default, use cached token only if --cached flag is set
125
+ if args.cached:
126
+ # Use cached token data
127
+ info["user"] = token_payload
128
+ info["source"] = "token"
129
+ else:
130
+ # Fetch fresh data from server (default behavior)
136
131
  fresh_profile = _fetch_fresh_profile(config.remote_url, token)
137
132
  if fresh_profile:
138
133
  info["user"] = fresh_profile
@@ -141,9 +136,6 @@ def cmd_profile(args) -> int:
141
136
  info["user"] = token_payload
142
137
  info["source"] = "token"
143
138
  info["warning"] = "Could not fetch fresh profile from server, using cached token data"
144
- else:
145
- info["user"] = token_payload
146
- info["source"] = "token"
147
139
 
148
140
  if expiry_message:
149
141
  info["token_status"] = expiry_message
@@ -199,9 +191,9 @@ def cmd_profile(args) -> int:
199
191
  if info.get("warning"):
200
192
  warning_text = f"\n[yellow]⚠ {info['warning']}[/yellow]"
201
193
 
202
- # Show tip for refreshing
203
- if source == "token":
204
- tip_text = "\n[dim]Tip: Use --refresh to fetch fresh data from server[/dim]"
194
+ # Show tip for using cached data
195
+ if source == "server":
196
+ tip_text = "\n[dim]Tip: Use --cached to use cached token data (faster but may be outdated)[/dim]"
205
197
  else:
206
198
  tip_text = None
207
199
 
ml_dash/client.py CHANGED
@@ -6,6 +6,95 @@ from typing import Optional, Dict, Any, List
6
6
  import httpx
7
7
 
8
8
 
9
+ class UserInfo:
10
+ """
11
+ Singleton user info object that fetches current user from API server.
12
+
13
+ Fetches user info from API server on first access (lazy loading).
14
+ This queries the API for fresh user data, ensuring up-to-date information.
15
+
16
+ Usage:
17
+ >>> from ml_dash import userinfo
18
+ >>> if userinfo.username:
19
+ ... print(f"Namespace: {userinfo.username}")
20
+ ... print(f"Email: {userinfo.email}")
21
+ ... print(f"Project: {userinfo.username}/my-project")
22
+ """
23
+
24
+ def __init__(self):
25
+ self._data = None
26
+ self._fetched = False
27
+
28
+ def _fetch(self):
29
+ """Fetch user info from API server (lazy loading)."""
30
+ if self._fetched:
31
+ return
32
+
33
+ self._fetched = True
34
+ try:
35
+ client = RemoteClient("https://api.dash.ml")
36
+ self._data = client.get_current_user()
37
+ except Exception:
38
+ self._data = None
39
+
40
+ @property
41
+ def username(self) -> Optional[str]:
42
+ """Username (namespace) - e.g., 'tom_tao_e4c2c9'"""
43
+ self._fetch()
44
+ return self._data.get("username") if self._data else None
45
+
46
+ @property
47
+ def email(self) -> Optional[str]:
48
+ """User email"""
49
+ self._fetch()
50
+ return self._data.get("email") if self._data else None
51
+
52
+ @property
53
+ def name(self) -> Optional[str]:
54
+ """Full name"""
55
+ self._fetch()
56
+ return self._data.get("name") if self._data else None
57
+
58
+ @property
59
+ def given_name(self) -> Optional[str]:
60
+ """First/given name"""
61
+ self._fetch()
62
+ return self._data.get("given_name") if self._data else None
63
+
64
+ @property
65
+ def family_name(self) -> Optional[str]:
66
+ """Last/family name"""
67
+ self._fetch()
68
+ return self._data.get("family_name") if self._data else None
69
+
70
+ @property
71
+ def picture(self) -> Optional[str]:
72
+ """Profile picture URL"""
73
+ self._fetch()
74
+ return self._data.get("picture") if self._data else None
75
+
76
+ @property
77
+ def id(self) -> Optional[str]:
78
+ """User ID"""
79
+ self._fetch()
80
+ return self._data.get("id") if self._data else None
81
+
82
+ def __bool__(self) -> bool:
83
+ """Return True if user is authenticated and data was fetched successfully."""
84
+ self._fetch()
85
+ return self._data is not None
86
+
87
+ def __repr__(self) -> str:
88
+ self._fetch()
89
+ if self._data:
90
+ return f"UserInfo(username='{self.username}', email='{self.email}')"
91
+ return "UserInfo(not authenticated)"
92
+
93
+
94
+ # Create singleton instance
95
+ userinfo = UserInfo()
96
+
97
+
9
98
  def _serialize_value(value: Any) -> Any:
10
99
  """
11
100
  Convert value to JSON-serializable format.
@@ -140,6 +229,44 @@ class RemoteClient:
140
229
  except Exception:
141
230
  return None
142
231
 
232
+ def get_current_user(self) -> Optional[Dict[str, Any]]:
233
+ """
234
+ Get current authenticated user's info from server.
235
+
236
+ This queries the API server for fresh user data, ensuring up-to-date information.
237
+
238
+ Returns:
239
+ User info dict with keys: username, email, name, given_name, family_name, picture
240
+ Returns None if not authenticated or if query fails
241
+
242
+ Example:
243
+ >>> client = RemoteClient("https://api.dash.ml")
244
+ >>> user = client.get_current_user()
245
+ >>> print(user["username"]) # e.g., "tom_tao_e4c2c9"
246
+ >>> print(user["email"]) # e.g., "user@example.com"
247
+ """
248
+ try:
249
+ self._ensure_authenticated()
250
+
251
+ # Query server for current user's complete profile
252
+ query = """
253
+ query GetCurrentUser {
254
+ me {
255
+ id
256
+ username
257
+ email
258
+ name
259
+ given_name
260
+ family_name
261
+ picture
262
+ }
263
+ }
264
+ """
265
+ result = self.graphql_query(query)
266
+ return result.get("me")
267
+ except Exception:
268
+ return None
269
+
143
270
  def _ensure_authenticated(self):
144
271
  """Check if authenticated, raise error if not."""
145
272
  if not self.api_key:
ml_dash/run.py CHANGED
@@ -223,7 +223,7 @@ class RUN:
223
223
  # experiments/vision/resnet/train.py
224
224
  from ml_dash import RUN
225
225
 
226
- RUN.__post_init__(entry=__file__)
226
+ RUN(entry=__file__)
227
227
  # Result: RUN.prefix = "vision/resnet", RUN.name = "resnet"
228
228
  """
229
229
  # Use provided entry or try to auto-detect from caller
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: ml-dash
3
- Version: 0.6.9
3
+ Version: 0.6.10
4
4
  Summary: ML experiment tracking and data storage
5
5
  Keywords: machine-learning,experiment-tracking,mlops,data-storage
6
6
  Author: Ge Yang, Tom Tao
@@ -1,11 +1,11 @@
1
- ml_dash/__init__.py,sha256=B1oYUXt2DnCctz5nWEqkg1M_XtbJNxaOPxbg54C0Vdc,1555
1
+ ml_dash/__init__.py,sha256=bsn9dwFrkXyZNcm6A4pAKS3ow1Q-2C5Z1jpak-at0Wo,2995
2
2
  ml_dash/auth/__init__.py,sha256=3lwM-Y8UBHPU1gFW2JNpmXlPVTnkGudWLKNFFKulQfo,1200
3
3
  ml_dash/auth/constants.py,sha256=ku4QzQUMNjvyJwjy7AUdywMAZd59jXSxNHZxDiagUWU,280
4
4
  ml_dash/auth/device_flow.py,sha256=DQOdPNlZCuU1umZOA_A6WXdRM3zWphnyo9IntToBl_A,7921
5
5
  ml_dash/auth/device_secret.py,sha256=qUsz6M9S1GEIukvmz57eJEp57srSx74O4MU9mZEeDlE,1158
6
6
  ml_dash/auth/exceptions.py,sha256=IeBwUzoaTyFtPwd4quFOIel49inIzuabe_ChEeEXEWI,725
7
- ml_dash/auth/token_storage.py,sha256=L18W8J7D1LlCDlY3Q32l0RXeNh0o7YVDQeeGYm64Dgw,8163
8
- ml_dash/auto_start.py,sha256=FHTTui33bxfk5rHf-VY2RFcd2JQ_LsNpkUu7Qtpc-GY,1721
7
+ ml_dash/auth/token_storage.py,sha256=9YQXGrn41UVyc1wUvZYbTYLzxSt5NGOyNFNjeX28bjA,7976
8
+ ml_dash/auto_start.py,sha256=mYNjLGI2kyylIfOX5wGOR74gb9UlXg1n5OUQu7aw5SE,2412
9
9
  ml_dash/buffer.py,sha256=i4-PZ703_yuKJPAXpmWBGm8jHAAdIBqiA0NIZQEc3wo,26201
10
10
  ml_dash/cli.py,sha256=X8LsQA8Wfa1XuXsbvePaGo6NYer7f8CNzy33VT3jrqg,2740
11
11
  ml_dash/cli_commands/__init__.py,sha256=bjAmV7MsW-bhtW_4SnLJ0Cfkt9h82vMDC8ebW1Ke8KE,38
@@ -15,9 +15,9 @@ ml_dash/cli_commands/download.py,sha256=Jw-ZeVH8SL9t2yRNCwSmQ0qUOzI4_iWGWt7SwAfM
15
15
  ml_dash/cli_commands/list.py,sha256=H442wOAcWYtDwq6BS7lpZbkKhqfTXBCHGctbw8zT1Zw,20841
16
16
  ml_dash/cli_commands/login.py,sha256=zX-urtUrfzg2qOGtKNYQgj6UloN9kzj4zEO6h_xwuNs,6782
17
17
  ml_dash/cli_commands/logout.py,sha256=lTUUNyRXqvo61qNkCd4KBrPUujDAHnNqsHkU6bHie0U,1332
18
- ml_dash/cli_commands/profile.py,sha256=AsdwAA2bmSTVnYyJ31iddkSwYJfYqJ60V1UGjFpa3YI,5869
18
+ ml_dash/cli_commands/profile.py,sha256=PoRO1XA4bnOINptj4AO0SyNDBADeryPJBfgC74327e4,5997
19
19
  ml_dash/cli_commands/upload.py,sha256=SSUfXC3qoNpoFvPM_ia-ing_N50LNiAvMy9op6FM9Ew,49664
20
- ml_dash/client.py,sha256=L-FZysVAuIovJJZ1MlDMPhOPJFyL77pMuBxtucG88x8,62005
20
+ ml_dash/client.py,sha256=WgdQRwI9OzEB9dtBtkjFOWNP1t1jj7wr4gvcDUYzZBM,65806
21
21
  ml_dash/config.py,sha256=oz2xvoBh2X_xUXWr92cPD5nFxXMT5LxVNypv5B5O0fA,3116
22
22
  ml_dash/experiment.py,sha256=sq5Bu-vcKhzTQlUsI6SzIHUZyUkxn7ZSMp_AbhFe4Bw,43462
23
23
  ml_dash/files.py,sha256=tGJCTxPfd9vmfvIEqstZjzLvqmHzMZffPXHz0jU9bYU,54441
@@ -26,11 +26,11 @@ ml_dash/metric.py,sha256=ghD1jnuv6dbjV1Jlo7q0mx9UEzpdto2Y1-oDWrSfg04,25809
26
26
  ml_dash/params.py,sha256=pPFvknJAJX5uhckzjO1r-HNnKbQFFKDISFmOXNET5eY,9046
27
27
  ml_dash/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
28
28
  ml_dash/remote_auto_start.py,sha256=5fvQDHv1CWEKFb6WAa5_uyEInwV_SvotXjOO_6i6ZKE,1687
29
- ml_dash/run.py,sha256=_a1l5qswwMgrhvajx_lI-I5IXhfHDeH3hfLAJ7Uk_Gs,8847
29
+ ml_dash/run.py,sha256=Hlt_YHaN95TC3TDejzLjFmW9EWyKWi6ruibw-eiPm2U,8833
30
30
  ml_dash/snowflake.py,sha256=14rEpRU5YltsmmmZW0EMUy_hdv5S5ME9gWVtmdmwfiU,4917
31
31
  ml_dash/storage.py,sha256=x1W-dK6wQY36-LVOJ4kA8Dn07ObNQuIErQWJ3b0PoGY,44910
32
32
  ml_dash/track.py,sha256=Dfg1ZnmKZ_FlE5ZfG8Qld_wN4RIMs3nrOxrxwf3thiY,8164
33
- ml_dash-0.6.9.dist-info/WHEEL,sha256=z-mOpxbJHqy3cq6SvUThBZdaLGFZzdZPtgWLcP2NKjQ,79
34
- ml_dash-0.6.9.dist-info/entry_points.txt,sha256=dYs2EHX1uRNO7AQGNnVaJJpgiy0Z9q7tiy4fHSyaf3Q,46
35
- ml_dash-0.6.9.dist-info/METADATA,sha256=f2YU7ukCO9VmIQ1zrctXaRBOA5D6t5caT89JLMD6Sxw,9535
36
- ml_dash-0.6.9.dist-info/RECORD,,
33
+ ml_dash-0.6.10.dist-info/WHEEL,sha256=XV0cjMrO7zXhVAIyyc8aFf1VjZ33Fen4IiJk5zFlC3g,80
34
+ ml_dash-0.6.10.dist-info/entry_points.txt,sha256=dYs2EHX1uRNO7AQGNnVaJJpgiy0Z9q7tiy4fHSyaf3Q,46
35
+ ml_dash-0.6.10.dist-info/METADATA,sha256=z9L0TSRTGJUSZ1gDYNR3Pj5IW3oh0AYeMFjEplnhFYA,9536
36
+ ml_dash-0.6.10.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: uv 0.9.15
2
+ Generator: uv 0.9.26
3
3
  Root-Is-Purelib: true
4
- Tag: py3-none-any
4
+ Tag: py3-none-any