mostlyai 0.2.0__tar.gz → 0.3.1__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.1
2
2
  Name: mostlyai
3
- Version: 0.2.0
3
+ Version: 0.3.1
4
4
  Summary: The official Python client for the MOSTLY AI platform.
5
5
  Home-page: https://app.mostly.ai/
6
6
  License: Proprietary
@@ -12,6 +12,7 @@ Classifier: Programming Language :: Python :: 3
12
12
  Classifier: Programming Language :: Python :: 3.9
13
13
  Classifier: Programming Language :: Python :: 3.10
14
14
  Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
15
16
  Requires-Dist: httpx (>=0.25.1,<0.26.0)
16
17
  Requires-Dist: pandas (>=1.5.3,<3.0.0)
17
18
  Requires-Dist: pyarrow (>=14.0.2,<15.0.0)
@@ -30,6 +31,8 @@ A Python wrapper for the MOSTLY AI platform (https://app.mostly.ai/).
30
31
  | Generate unlimited synthetic data on demand | `mostly.generate(g, size)` |
31
32
  | Prompt the generator for the data that you need | `mostly.generate(g, seed)` |
32
33
  | Connect to any data source within your org | `mostly.connect(config)` |
34
+ | Info about the current user | `mostly.me()` |
35
+
33
36
 
34
37
 
35
38
 
@@ -9,6 +9,8 @@ A Python wrapper for the MOSTLY AI platform (https://app.mostly.ai/).
9
9
  | Generate unlimited synthetic data on demand | `mostly.generate(g, size)` |
10
10
  | Prompt the generator for the data that you need | `mostly.generate(g, seed)` |
11
11
  | Connect to any data source within your org | `mostly.connect(config)` |
12
+ | Info about the current user | `mostly.me()` |
13
+
12
14
 
13
15
 
14
16
 
@@ -4,11 +4,12 @@ from typing import Any, Optional, Union
4
4
  import pandas as pd
5
5
  import rich
6
6
 
7
- from mostlyai.base import _MostlyBaseClient
7
+ from mostlyai.base import GET, _MostlyBaseClient
8
8
  from mostlyai.connectors import _MostlyConnectorsClient
9
9
  from mostlyai.generators import _MostlyGeneratorsClient
10
10
  from mostlyai.model import (
11
11
  Connector,
12
+ CurrentUser,
12
13
  Generator,
13
14
  PermissionLevel,
14
15
  ProgressStatus,
@@ -30,6 +31,7 @@ class MostlyAI(_MostlyBaseClient):
30
31
  :param base_url: The base URL. If not provided, a default value is used.
31
32
  :param api_key: The API key for authenticating. If not provided, it would rely on env vars.
32
33
  :param timeout: Timeout for HTTPS requests in seconds.
34
+ :param ssl_verify: Whether to verify SSL certificates.
33
35
  """
34
36
 
35
37
  def __init__(
@@ -37,12 +39,16 @@ class MostlyAI(_MostlyBaseClient):
37
39
  base_url: Optional[str] = None,
38
40
  api_key: Optional[str] = None,
39
41
  timeout: float = 60.0,
42
+ ssl_verify: bool = True,
40
43
  ):
41
- super().__init__(base_url=base_url, api_key=api_key, timeout=timeout)
44
+ super().__init__(
45
+ base_url=base_url, api_key=api_key, timeout=timeout, ssl_verify=ssl_verify
46
+ )
42
47
  client_kwargs = {
43
48
  "base_url": self.base_url,
44
49
  "api_key": self.api_key,
45
50
  "timeout": self.timeout,
51
+ "ssl_verify": self.ssl_verify,
46
52
  }
47
53
  self.connectors = _MostlyConnectorsClient(**client_kwargs)
48
54
  self.generators = _MostlyGeneratorsClient(**client_kwargs)
@@ -284,48 +290,48 @@ class MostlyAI(_MostlyBaseClient):
284
290
 
285
291
  def share(
286
292
  self,
287
- resource: Union[str, ShareableResource],
293
+ resource: ShareableResource,
288
294
  user_email: str,
289
295
  permission_level: Union[str, PermissionLevel] = PermissionLevel.view,
290
296
  ):
291
297
  """
292
298
  Share a specified resource with a user by granting a specific permission level.
293
299
 
294
- :param resource: The resource to be shared. This can either be the resource ID as a string or an instance of a ShareableResource (Connector, Generator, or SyntheticDataset).
300
+ :param resource: The resource to be shared. This must be an instance of a ShareableResource (Connector, Generator, or SyntheticDataset).
295
301
  :param user_email: The email address of the user with whom the resource is to be shared.
296
302
  :param permission_level: The level of permission to be granted. This can be a string or an instance of PermissionLevel. Default is PermissionLevel.view, which grants 'view' access.
297
303
 
298
304
  :return: None. The function outputs a confirmation message with the details of the sharing action.
299
305
  """
300
- if isinstance(resource, (Connector, Generator, SyntheticDataset)):
301
- resource_id = resource.id
302
- else:
303
- resource_id = str(resource)
304
306
  if isinstance(permission_level, PermissionLevel):
305
307
  permission_level = permission_level.value
306
308
  if permission_level == "ADMIN":
307
309
  raise ValueError(
308
310
  "ADMIN permission level is not supported. Transfer ownership via the UI."
309
311
  )
310
- self.shares._share(resource_id, user_email, permission_level)
312
+ self.shares._share(resource, user_email, permission_level)
311
313
  rich.print(
312
- f"Granted [bold]{user_email}[/] [grey]{permission_level}[/] access to resource [bold cyan]{resource_id}[/]"
314
+ f"Granted [bold]{user_email}[/] [grey]{permission_level}[/] access to resource [bold cyan]{resource.id}[/]"
313
315
  )
314
316
 
315
- def unshare(self, resource: Union[str, ShareableResource], user_email: str):
317
+ def unshare(self, resource: ShareableResource, user_email: str):
316
318
  """
317
319
  Unshare a specified resource from a user.
318
320
 
319
- :param resource: The resource from which access is being unshared. This can be the resource ID as a string or an instance of a ShareableResource (Connector, Generator, or SyntheticDataset).
321
+ :param resource: The resource from which access is being unshared. This must be an instance of a ShareableResource (Connector, Generator, or SyntheticDataset).
320
322
  :param user_email: The email address of the user whose access to the resource is to be unshared.
321
323
 
322
324
  :return: None. The function outputs a confirmation message with the details of the revocation action.
323
325
  """
324
- if isinstance(resource, (Connector, Generator, SyntheticDataset)):
325
- resource_id = resource.id
326
- else:
327
- resource_id = str(resource)
328
326
  self.shares._unshare(resource, user_email)
329
327
  rich.print(
330
- f"Revoked access of resource [bold cyan]{resource_id}[/] for [bold]{user_email}[/]"
328
+ f"Revoked access of resource [bold cyan]{resource.id}[/] for [bold]{user_email}[/]"
331
329
  )
330
+
331
+ def me(self) -> CurrentUser:
332
+ """
333
+ Retrieve current user info.
334
+
335
+ :return: info about the current user.
336
+ """
337
+ return self.request(verb=GET, path=["users", "me"], response_type=CurrentUser)
@@ -46,16 +46,19 @@ class _MostlyBaseClient:
46
46
  base_url: Optional[str] = None,
47
47
  api_key: Optional[str] = None,
48
48
  timeout: float = 60.0,
49
+ ssl_verify: bool = True,
49
50
  ):
50
51
  self.base_url = (
51
52
  base_url or os.getenv("MOSTLY_BASE_URL") or DEFAULT_BASE_URL
52
53
  ).rstrip("/")
53
54
  self.api_key = api_key or os.getenv("MOSTLY_API_KEY")
54
55
  self.timeout = timeout
55
- if not self.base_url:
56
- raise APIError(f"Invalid {self.base_url=}")
56
+ self.ssl_verify = ssl_verify
57
57
  if not self.api_key:
58
- raise APIError(f"Invalid {self.api_key=}")
58
+ raise APIError(
59
+ "The API key must be either set by passing api_key to the client or by specifying a "
60
+ "MOSTLY_API_KEY environment variable"
61
+ )
59
62
 
60
63
  def headers(self):
61
64
  return {
@@ -103,7 +106,7 @@ class _MostlyBaseClient:
103
106
  )
104
107
 
105
108
  try:
106
- with httpx.Client(timeout=self.timeout) as client:
109
+ with httpx.Client(timeout=self.timeout, verify=self.ssl_verify) as client:
107
110
  response = client.request(method=verb, url=full_url, **kwargs)
108
111
  response.raise_for_status()
109
112
  except httpx.HTTPStatusError as exc:
@@ -1,5 +1,5 @@
1
1
  # generated by datamodel-codegen:
2
- # timestamp: 2024-03-07T15:01:14+00:00
2
+ # timestamp: 2024-03-18T16:27:33+00:00
3
3
 
4
4
  from __future__ import annotations
5
5
 
@@ -170,6 +170,7 @@ class ConnectorType(str, Enum):
170
170
  google_cloud_storage = "GOOGLE_CLOUD_STORAGE"
171
171
  s3_storage = "S3_STORAGE"
172
172
  file_upload = "FILE_UPLOAD"
173
+ hive = "HIVE"
173
174
 
174
175
 
175
176
  class ConnectorTestConnection(RootModel[bool]):
@@ -247,7 +248,7 @@ class Connector(CustomBaseModel):
247
248
  return self.client._config(connector_id=self.id)
248
249
 
249
250
  def shares(self):
250
- return self.client._shares(resource_id=self.id)
251
+ return self.client._shares(resource=self)
251
252
 
252
253
 
253
254
  class GeneratorUsage(CustomBaseModel):
@@ -653,6 +654,24 @@ class SyntheticTableName(RootModel[str]):
653
654
  ]
654
655
 
655
656
 
657
+ class ForeignKey(CustomBaseModel):
658
+ column: Annotated[str, Field(description="The column name of a foreign key.")]
659
+ referenced_table: Annotated[
660
+ str,
661
+ Field(
662
+ alias="referencedTable",
663
+ description="The table name of the referenced table. That table must have a primary key already defined.",
664
+ ),
665
+ ]
666
+ is_context: Annotated[
667
+ bool,
668
+ Field(
669
+ alias="isContext",
670
+ description="If true, then the foreign key will be considered as a context relation.\nNote, that only one foreign key relation per table can be a context relation.\n",
671
+ ),
672
+ ]
673
+
674
+
656
675
  class SyntheticTable(CustomBaseModel):
657
676
  id: Annotated[
658
677
  Optional[str], Field(description="The unique identifier of a synthetic table")
@@ -665,6 +684,10 @@ class SyntheticTable(CustomBaseModel):
665
684
  ] = None
666
685
  configuration: Optional[SyntheticTableConfiguration] = None
667
686
  model_metrics: Annotated[Optional[ModelMetrics], Field(alias="modelMetrics")] = None
687
+ foreign_keys: Annotated[
688
+ Optional[List[ForeignKey]],
689
+ Field(alias="foreignKeys", description="The foreign keys of this table."),
690
+ ] = None
668
691
 
669
692
 
670
693
  class SyntheticDatasetDelivery(CustomBaseModel):
@@ -736,6 +759,7 @@ class GeneratorListItem(CustomBaseModel):
736
759
  description="The UTC date and time when the training has finished.",
737
760
  ),
738
761
  ] = None
762
+ usage: Optional[GeneratorUsage] = None
739
763
  metadata: Metadata
740
764
  accuracy: Annotated[
741
765
  Optional[float],
@@ -788,7 +812,7 @@ class SourceTable(CustomBaseModel):
788
812
  ),
789
813
  ] = None
790
814
 
791
- def model_qa_report(self) -> "ModelQAReport":
815
+ def model_qa_report(self):
792
816
  if self.client and hasattr(self.client, "model_qa_report"):
793
817
  return self.client.model_qa_report(
794
818
  generator_id=self.extra_key_values["generator_id"], table_id=self.id
@@ -963,7 +987,7 @@ class SyntheticDataset(CustomBaseModel):
963
987
  return dfs
964
988
 
965
989
  def shares(self):
966
- return self.client._shares(resource_id=self.id)
990
+ return self.client._shares(resource=self)
967
991
 
968
992
  class Generation:
969
993
  def __init__(self, _synthetic_dataset: "SyntheticDataset"):
@@ -1024,6 +1048,7 @@ class Generator(CustomBaseModel):
1024
1048
  description="The UTC date and time when the training has finished.",
1025
1049
  ),
1026
1050
  ] = None
1051
+ usage: Optional[GeneratorUsage] = None
1027
1052
  metadata: Metadata
1028
1053
  accuracy: Annotated[
1029
1054
  Optional[float],
@@ -1066,7 +1091,7 @@ class Generator(CustomBaseModel):
1066
1091
  return self.client._config(generator_id=self.id)
1067
1092
 
1068
1093
  def shares(self):
1069
- return self.client._shares(resource_id=self.id)
1094
+ return self.client._shares(resource=self)
1070
1095
 
1071
1096
  class Training:
1072
1097
  def __init__(self, _generator: "Generator"):
@@ -0,0 +1,54 @@
1
+ from typing import Union
2
+ from uuid import UUID
3
+
4
+ from mostlyai.base import DELETE, GET, POST, _MostlyBaseClient
5
+ from mostlyai.model import (
6
+ Connector,
7
+ Generator,
8
+ PermissionLevel,
9
+ Share,
10
+ SyntheticDataset,
11
+ )
12
+ from mostlyai.utils import ShareableResource
13
+
14
+
15
+ class _MostlySharesClient(_MostlyBaseClient):
16
+ SECTION = ["shares"]
17
+ RESOURCE_TYPE = {
18
+ Connector: "connectors",
19
+ Generator: "generators",
20
+ SyntheticDataset: "synthetic-datasets",
21
+ }
22
+
23
+ # PRIVATE METHODS #
24
+
25
+ def _list(self, resource: ShareableResource) -> list[Share]:
26
+ resource_type = self.RESOURCE_TYPE.get(type(resource))
27
+ response = self.request(verb=GET, path=[resource_type, resource.id])
28
+ response = [Share(**share) for share in response]
29
+ return response
30
+
31
+ def _share(
32
+ self,
33
+ resource: ShareableResource,
34
+ user_email: str,
35
+ permission_level: PermissionLevel,
36
+ ):
37
+ config = {"userEmail": user_email, "permissionLevel": permission_level}
38
+ resource_type = self.RESOURCE_TYPE.get(type(resource))
39
+ self.request(verb=POST, path=[resource_type, resource.id], json=config)
40
+
41
+ def _unshare(self, resource: ShareableResource, user_email: str):
42
+ config = {"userEmail": user_email}
43
+ resource_type = self.RESOURCE_TYPE.get(type(resource))
44
+ self.request(verb=DELETE, path=[resource_type, resource.id], json=config)
45
+
46
+
47
+ class _MostlySharesMixin:
48
+ @property
49
+ def shares_client(self):
50
+ client_kwargs = {"base_url": self.base_url, "api_key": self.api_key}
51
+ return _MostlySharesClient(**client_kwargs)
52
+
53
+ def _shares(self, resource: ShareableResource) -> list[Share]:
54
+ return self.shares_client._list(resource)
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "mostlyai"
3
- version = "0.2.0"
3
+ version = "0.3.1"
4
4
  description = "The official Python client for the MOSTLY AI platform."
5
5
  homepage = "https://app.mostly.ai/"
6
6
  authors = ["MOSTLY AI <office@mostly.ai>"]
@@ -45,6 +45,14 @@ warn_unreachable = true
45
45
  [tool.isort]
46
46
  profile = "black"
47
47
 
48
+ [tool.commitizen]
49
+ name = "cz_conventional_commits"
50
+ tag_format = "$version"
51
+ version_scheme = "pep440"
52
+ version_provider = "poetry"
53
+ update_changelog_on_bump = true
54
+ major_version_zero = true
55
+
48
56
  [build-system]
49
57
  requires = ["poetry-core"]
50
58
  build-backend = "poetry.core.masonry.api"
@@ -1,60 +0,0 @@
1
- from typing import Union
2
- from uuid import UUID
3
-
4
- from mostlyai.base import DELETE, GET, POST, _MostlyBaseClient
5
- from mostlyai.model import (
6
- Connector,
7
- Generator,
8
- PermissionLevel,
9
- Share,
10
- SyntheticDataset,
11
- )
12
- from mostlyai.utils import ShareableResource
13
-
14
-
15
- class _MostlySharesClient(_MostlyBaseClient):
16
- SECTION = ["shares"]
17
-
18
- # PRIVATE METHODS #
19
-
20
- @staticmethod
21
- def _resource_id(
22
- resource: Union[str, UUID, Connector, Generator, SyntheticDataset],
23
- ):
24
- if isinstance(resource, (str, UUID)):
25
- resource_id = str(resource)
26
- elif isinstance(resource, (Connector, Generator, SyntheticDataset)):
27
- resource_id = str(resource.id)
28
- else:
29
- raise ValueError(f"{resource=} is invalid")
30
- return resource_id
31
-
32
- def _list(self, resource: str) -> list[Share]:
33
- resource_id = self._resource_id(resource)
34
- response = self.request(verb=GET, path=[resource_id])
35
- response = [Share(**share) for share in response]
36
- return response
37
-
38
- def _share(
39
- self,
40
- resource_id: str,
41
- user_email: str,
42
- permission_level: PermissionLevel,
43
- ):
44
- config = {"userEmail": user_email, "permissionLevel": permission_level}
45
- self.request(verb=POST, path=[resource_id], json=config)
46
-
47
- def _unshare(self, resource: Union[str, ShareableResource], user_email: str):
48
- resource_id = self._resource_id(resource)
49
- config = {"userEmail": user_email}
50
- self.request(verb=DELETE, path=[resource_id], json=config)
51
-
52
-
53
- class _MostlySharesMixin:
54
- @property
55
- def shares_client(self):
56
- client_kwargs = {"base_url": self.base_url, "api_key": self.api_key}
57
- return _MostlySharesClient(**client_kwargs)
58
-
59
- def _shares(self, resource_id: str) -> list[Share]:
60
- return self.shares_client._list(resource_id)
File without changes
File without changes
File without changes