atlasai-dstoolkit-client 0.0.9__py3-none-any.whl → 0.0.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.
@@ -33,5 +33,5 @@ del osp
33
33
  del os
34
34
 
35
35
 
36
- from . import fabric, feature
36
+ from . import fabric, feature, dataset, model
37
37
  from .login import login, logout
@@ -3,6 +3,9 @@ import os
3
3
  VINZ_URL = os.getenv('VINZ_URL') or 'https://vinz.atlasai.co'
4
4
  DS_TOOLKIT_URL = os.getenv('DS_TOOLKIT_URL') or 'https://dstoolkit.atlasai.co'
5
5
 
6
+ # force mlhub library to go to ds toolkit
7
+ os.environ['MLHUB_URL'] = f'{DS_TOOLKIT_URL}/api'
8
+
6
9
  DEFAULT_PAGE_SIZE = 20
7
10
  DISABLE_SSL_VERIFICATION = 'DISABLE_SSL_VERIFICATION'
8
11
 
@@ -0,0 +1,108 @@
1
+ # Copyright 2025 AtlasAI PBC. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ import uuid
16
+ import io
17
+ import pandas as pd
18
+
19
+ from . import api, constants, utils
20
+ from .requests import get_session
21
+
22
+ def register(product_name: str, data=None, file=None, start_date: str = None, end_date: str = None, tags: dict = None, type: str = 'Other'):
23
+ """
24
+
25
+ Parameters
26
+ ----------
27
+ data: The data you want to upload
28
+ file: The file you want to upload. It's either a file or data in RAM
29
+ product_name: The name of the product you want to be registered
30
+ start_date: Effective start date of the product in YYYY-MM-DD format
31
+ end_date: Effective end date of the product in YYYY-MM-DD format
32
+ tags: Tags you want to add to the product and instance
33
+ type: Type of the asset
34
+
35
+ Returns
36
+ -------
37
+
38
+ """
39
+ if data is None and file is None:
40
+ raise Exception('data or file parameter required')
41
+
42
+ if file:
43
+ with open('data.json', 'r', encoding='utf-8') as f:
44
+ file_contents = f.read()
45
+ data = io.StringIO(file_contents)
46
+ else:
47
+ if isinstance(data, pd.DataFrame):
48
+ data = data.to_json(orient='records')
49
+ data = io.StringIO(data)
50
+
51
+ additional_params = [
52
+ ('start_date', start_date),
53
+ ('end_date', end_date),
54
+ ('tags', tags),
55
+ ('type', type)
56
+ ]
57
+ _, result = api._post(resource='dataset/upload')
58
+ result = result['data']
59
+ session = get_session()
60
+ response = session.put(result['signed_url'], data=data, headers=result['headers'])
61
+ response.raise_for_status()
62
+
63
+ register_data = {
64
+ 'product_name': product_name,
65
+ 'path': result['storage_path'],
66
+ }
67
+ for name, value in additional_params:
68
+ if value:
69
+ register_data[name] = value
70
+
71
+ _, data = api._post(resource='dataset/register', data=register_data)
72
+ return {
73
+ 'product_name': data['data']['product_name'],
74
+ 'storage_path': result['storage_path']
75
+ }
76
+
77
+ def search(*args, **kwargs):
78
+ ds = DatasetSearch(*args, **kwargs)
79
+ utils.show_page(ds.page)
80
+ return ds
81
+
82
+ class DatasetSearch:
83
+
84
+ def __init__(self, id=None, *args, **kwargs):
85
+ self.id = id or uuid.uuid4()
86
+ self._search = None
87
+
88
+ def __repr__(self):
89
+ return f'DatasetSearch({self.id})'
90
+
91
+ def __str__(self):
92
+ return f'DatasetSearch({self.id})'
93
+
94
+ @property
95
+ def page(self):
96
+ return f'{constants.DS_TOOLKIT_URL}/dataset/search/{self.id}'
97
+
98
+ @property
99
+ def search(self):
100
+ return self._search
101
+
102
+ def info(self):
103
+ return self._info()
104
+
105
+ def _info(self):
106
+ resource = f'dataset/search/{self.id}/info'
107
+ _, data = api._get(resource=resource)
108
+ return data['data']
@@ -0,0 +1,121 @@
1
+ # Copyright 2025 AtlasAI PBC. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ import json
16
+ import pandas as pd
17
+ from typing import Union
18
+
19
+ from atlasai.mlhub import client
20
+
21
+ from .api import _get_access_token
22
+
23
+
24
+ def search(name=None, version=None, source=None, tags=None, aliases=None):
25
+ return ModelSearch(name, version, source, tags, aliases).search()
26
+
27
+ def get(name, version=None):
28
+ return ModelGet(name, version).get()
29
+
30
+
31
+ class ModelPredictWrapper:
32
+ def __init__(self, model):
33
+ self._model = model
34
+
35
+ def predict(
36
+ self,
37
+ data: Union[dict, str, pd.DataFrame] = None,
38
+ deployment_type: str = 'http',
39
+ timeout: int = 3600,
40
+ wait_for_completion: bool = True,
41
+ tabular: bool = True,
42
+ data_type: str = 'json'
43
+ ):
44
+ if deployment_type not in self._model.deployments:
45
+ raise Exception(f'This model has no {deployment_type} deployment.')
46
+
47
+ return client.evaluate(
48
+ self._model.name,
49
+ self._model.version,
50
+ deployment_type=deployment_type,
51
+ data=data,
52
+ wait_for_completion=wait_for_completion,
53
+ timeout=timeout,
54
+ tabular=tabular,
55
+ data_type=data_type
56
+
57
+ )
58
+
59
+ def __getattr__(self, item):
60
+ return getattr(self._model, item)
61
+
62
+
63
+ class ModelResults:
64
+ def __init__(self, results):
65
+ self.results = results
66
+
67
+ def __iter__(self):
68
+ return iter(self.results)
69
+
70
+ def display(self):
71
+ data = [
72
+ {
73
+ 'name': r.name,
74
+ 'version': r.version,
75
+ 'aliases': r.aliases if r.aliases else '',
76
+ 'tags': json.dumps(r.tags) if isinstance(r.tags, dict) else r.tags
77
+ } for r in self.results
78
+ ]
79
+ return pd.DataFrame(data)
80
+
81
+ def first(self):
82
+ return self.results[0]
83
+
84
+ def last(self):
85
+ return self.results[-1]
86
+
87
+ def all(self):
88
+ return self.results
89
+
90
+ class ModelSearch:
91
+ def __init__(self, name=None, version=None, source=None, tags=None, aliases=None):
92
+ if aliases is None:
93
+ aliases = []
94
+ if tags is None:
95
+ tags = {}
96
+ self.name = name
97
+ self.version = version
98
+ self.source = source
99
+ self.tags = tags
100
+ self.aliases = aliases if isinstance(aliases, list) else [aliases]
101
+
102
+ def search(self):
103
+ search = {}
104
+ filters = ['name', 'version', 'source', 'tags', 'aliases']
105
+ for f in filters:
106
+ if not getattr(self, f, None):
107
+ continue
108
+ search[f] = getattr(self, f)
109
+
110
+ _get_access_token()
111
+ results = client.get_models(search=search, tabular=False)
112
+ return ModelResults([ModelPredictWrapper(r) for r in results])
113
+
114
+ class ModelGet:
115
+ def __init__(self, name, version='latest'):
116
+ self.name = name
117
+ self.version = version
118
+
119
+ def get(self):
120
+ result = client.get_model_info(self.name, self.version)
121
+ return ModelPredictWrapper(result)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: atlasai-dstoolkit-client
3
- Version: 0.0.9
3
+ Version: 0.0.10
4
4
  Summary: UNKNOWN
5
5
  Home-page: UNKNOWN
6
6
  Author: AtlasAI SWE
@@ -10,6 +10,7 @@ Platform: UNKNOWN
10
10
  Requires-Python: >=3.10
11
11
  License-File: LICENSE.txt
12
12
  Requires-Dist: arrow (<2.0.0,>=1.3.0)
13
+ Requires-Dist: atlasai-mlhub-client
13
14
  Requires-Dist: furl (<3.0.0,>=2.1.2)
14
15
  Requires-Dist: pandas (<3.0.0,>=2.2.3)
15
16
  Requires-Dist: pyarrow (>=19.0.1)
@@ -0,0 +1,16 @@
1
+ atlasai/toolkit/__init__.py,sha256=rjt3GfV7vA3RFMIzqPwBebJUXdQbeTLmEYmm7SOoOGw,1002
2
+ atlasai/toolkit/api.py,sha256=BvO-gLRmbmkKduwbbADjcLlIkS9blzfM_cbMR4DhQmU,5269
3
+ atlasai/toolkit/constants.py,sha256=Jxozn9tKOvAxyOYOZ6bzFtI9m1YETJF1GURzTl9NNC8,422
4
+ atlasai/toolkit/dataset.py,sha256=fhzhxF9YMzIwEpaJZEPOK2SuLMJhVGI75eahxnH_T2c,3254
5
+ atlasai/toolkit/fabric.py,sha256=6aFR2PGQc9P3Qa07WdBg9eKoUzU8n2y_-gGjYcyMrWY,1921
6
+ atlasai/toolkit/feature.py,sha256=VKwX_yAwwMo1WuLZ_RbKVJEH4L1PAoYEPzWa0lH9ats,2828
7
+ atlasai/toolkit/init.py,sha256=JkdJ6QGdYWrq65jgz2pn5RYXUeUe2Ez88_-eMf5CNi0,1100
8
+ atlasai/toolkit/login.py,sha256=n4ydfo9qCsmbZq6er1xeljBD76vdTJGjbhYHMmOyDbQ,3061
9
+ atlasai/toolkit/model.py,sha256=6gmIVx7joCpVxSQbXlmjkxAjreL_J104laAgKKgGOo0,3525
10
+ atlasai/toolkit/requests.py,sha256=X86nIo07hAjUlilZcZ1lV8RB7KOsTKbTGtcY_SpFEXY,1223
11
+ atlasai/toolkit/utils.py,sha256=lYh3P2XOshRgHCjFeXJ0FOJWQW64sddgx8c2kL6Wqwc,1566
12
+ atlasai_dstoolkit_client-0.0.10.dist-info/LICENSE.txt,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
13
+ atlasai_dstoolkit_client-0.0.10.dist-info/METADATA,sha256=h9oUexHohAl4WiRMqQX2UiXytdzdYmBeGPJ5BhM4thg,1405
14
+ atlasai_dstoolkit_client-0.0.10.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
15
+ atlasai_dstoolkit_client-0.0.10.dist-info/top_level.txt,sha256=HRTbErU8nmHFDaJJ5R_XYbwpt21dqdjDpSva8xyy_0k,8
16
+ atlasai_dstoolkit_client-0.0.10.dist-info/RECORD,,
@@ -1,14 +0,0 @@
1
- atlasai/toolkit/__init__.py,sha256=szu5LHZ41ccWztCI2LvQ3QnZRybosgTbU3yd6tS7cUw,986
2
- atlasai/toolkit/api.py,sha256=BvO-gLRmbmkKduwbbADjcLlIkS9blzfM_cbMR4DhQmU,5269
3
- atlasai/toolkit/constants.py,sha256=sE0PeFa9_htCPVFADHbkyPIz3QOai0tAIA5IiiZI8wA,329
4
- atlasai/toolkit/fabric.py,sha256=6aFR2PGQc9P3Qa07WdBg9eKoUzU8n2y_-gGjYcyMrWY,1921
5
- atlasai/toolkit/feature.py,sha256=VKwX_yAwwMo1WuLZ_RbKVJEH4L1PAoYEPzWa0lH9ats,2828
6
- atlasai/toolkit/init.py,sha256=JkdJ6QGdYWrq65jgz2pn5RYXUeUe2Ez88_-eMf5CNi0,1100
7
- atlasai/toolkit/login.py,sha256=n4ydfo9qCsmbZq6er1xeljBD76vdTJGjbhYHMmOyDbQ,3061
8
- atlasai/toolkit/requests.py,sha256=X86nIo07hAjUlilZcZ1lV8RB7KOsTKbTGtcY_SpFEXY,1223
9
- atlasai/toolkit/utils.py,sha256=lYh3P2XOshRgHCjFeXJ0FOJWQW64sddgx8c2kL6Wqwc,1566
10
- atlasai_dstoolkit_client-0.0.9.dist-info/LICENSE.txt,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
11
- atlasai_dstoolkit_client-0.0.9.dist-info/METADATA,sha256=ygcwrboXNHtv0Y4o7PrEcs2RZDcjkFfQwp357F8mIqg,1368
12
- atlasai_dstoolkit_client-0.0.9.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
13
- atlasai_dstoolkit_client-0.0.9.dist-info/top_level.txt,sha256=HRTbErU8nmHFDaJJ5R_XYbwpt21dqdjDpSva8xyy_0k,8
14
- atlasai_dstoolkit_client-0.0.9.dist-info/RECORD,,