mostlyai 0.3.9__tar.gz → 0.3.10__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.3.9
3
+ Version: 0.3.10
4
4
  Summary: The official Python client for the MOSTLY AI platform.
5
5
  Home-page: https://app.mostly.ai/
6
6
  License: Proprietary
@@ -87,10 +87,15 @@ g.open()
87
87
  g.reload()
88
88
  g.delete()
89
89
 
90
+ # training
90
91
  g.training.start()
91
92
  g.training.progress()
92
93
  g.training.cancel()
93
94
  g.training.wait()
95
+
96
+ # import / export
97
+ g.export_to_file(file_path)
98
+ mostly.generators.import_from_file(file_path)
94
99
  ```
95
100
 
96
101
  ### Synthetic Datasets
@@ -65,10 +65,15 @@ g.open()
65
65
  g.reload()
66
66
  g.delete()
67
67
 
68
+ # training
68
69
  g.training.start()
69
70
  g.training.progress()
70
71
  g.training.cancel()
71
72
  g.training.wait()
73
+
74
+ # import / export
75
+ g.export_to_file(file_path)
76
+ mostly.generators.import_from_file(file_path)
72
77
  ```
73
78
 
74
79
  ### Synthetic Datasets
@@ -0,0 +1,4 @@
1
+ from mostlyai.api import MostlyAI
2
+
3
+ __all__ = ["MostlyAI"]
4
+ __version__ = "0.3.10" # Do not set this manually. Use poetry version [params].
@@ -170,7 +170,7 @@ class MostlyAI(_MostlyBaseClient):
170
170
  secrets:
171
171
  password: string
172
172
  ssl:
173
- rootCertificate: base64-encoded string
173
+ rootCertificate: base64-encoded string
174
174
  sslCertificate: base64-encoded string
175
175
  sslCertificateKey: base64-encoded string
176
176
 
@@ -1,5 +1,6 @@
1
1
  from pathlib import Path
2
2
  from typing import Any, Iterator, Optional, Union
3
+ import re
3
4
 
4
5
  import pandas as pd
5
6
 
@@ -75,7 +76,50 @@ class _MostlyGeneratorsClient(_MostlyBaseClient, _MostlySharesMixin):
75
76
  )
76
77
  return generator
77
78
 
79
+ def import_from_file(
80
+ self,
81
+ file_path: Union[str, Path],
82
+ ) -> Generator:
83
+ """
84
+ Import a generator from a file.
85
+ Supported from release v212 onwards.
86
+
87
+ :param file_path: Path to the file to import.
88
+ :return: The imported generator.
89
+ """
90
+ response = self.request(
91
+ verb=POST,
92
+ path=["import-from-file"],
93
+ headers={
94
+ "Accept": "application/json, text/plain, */*",
95
+ },
96
+ files={"file": open(file_path, "rb")},
97
+ response_type=Generator,
98
+ )
99
+ return response
100
+
78
101
  # PRIVATE METHODS #
102
+ def _export_to_file(
103
+ self,
104
+ generator_id: str,
105
+ ) -> (bytes, Optional[str]):
106
+ response = self.request(
107
+ verb=GET,
108
+ path=[generator_id, "export-to-file"],
109
+ headers={
110
+ "Content-Type": "application/octet-stream",
111
+ "Accept": "application/json, text/plain, */*",
112
+ },
113
+ raw_response=True,
114
+ )
115
+ content_bytes = response.content
116
+ # Check if 'Content-Disposition' header is present
117
+ if "Content-Disposition" in response.headers:
118
+ content_disposition = response.headers["Content-Disposition"]
119
+ filename = re.findall("filename=(.+)", content_disposition)[0]
120
+ else:
121
+ filename = f"generator-{generator_id[:8]}.mostly"
122
+ return content_bytes, filename
79
123
 
80
124
  def _update(self, generator_id: str, config: dict[str, Any]) -> Generator:
81
125
  response = self.request(
@@ -1,5 +1,5 @@
1
1
  # generated by datamodel-codegen:
2
- # timestamp: 2024-05-28T13:04:58+00:00
2
+ # timestamp: 2024-06-21T12:02:58+00:00
3
3
 
4
4
  from __future__ import annotations
5
5
 
@@ -128,7 +128,7 @@ class Metadata(CustomBaseModel):
128
128
  Field(
129
129
  None,
130
130
  alias="shortLivedFileToken",
131
- description="An auto-generated short-lived file token (`slft`) for accessing resource artefacts.\nThe token is always restricted to a single resource, only valid for 10 minutes, and \nonly accepted by API endpoints that allow to download single files.\n",
131
+ description="An auto-generated short-lived file token (`slft`) for accessing resource artefacts.\nThe token is always restricted to a single resource, only valid for 60 minutes, and \nonly accepted by API endpoints that allow to download single files.\n",
132
132
  ),
133
133
  ] = None
134
134
 
@@ -746,6 +746,20 @@ class SyntheticTableRebalancing(CustomBaseModel):
746
746
  ] = None
747
747
 
748
748
 
749
+ class SyntheticTableFairness(CustomBaseModel):
750
+ """
751
+ Configure a fairness objective for the table. Only applicable for a subject table.
752
+ The generated synthetic data will maintain robust statistical parity between the target column and
753
+ the specified sensitive columns. All these columns must be categorical.
754
+
755
+ """
756
+
757
+ target_column: Annotated[Optional[str], Field(None, alias="targetColumn")] = None
758
+ sensitive_columns: Annotated[
759
+ Optional[List[str]], Field(None, alias="sensitiveColumns")
760
+ ] = None
761
+
762
+
749
763
  class SyntheticTableConfiguration(CustomBaseModel):
750
764
  """
751
765
  The sample configuration for a synthetic table
@@ -756,7 +770,7 @@ class SyntheticTableConfiguration(CustomBaseModel):
756
770
  Field(
757
771
  None,
758
772
  alias="sampleSize",
759
- description="Number of generated samples. Only applicable for subject tables.\n",
773
+ description="Number of generated samples. Only applicable for subject tables.\nIf neither size nor seed is provided, then the default behavior for Synthetic Datasets is to generate the\nsame size of samples as the original, and the default behavior for Synthetic Datasets is to generate one\nsubject only.\n",
760
774
  ge=1,
761
775
  ),
762
776
  ] = None
@@ -808,6 +822,7 @@ class SyntheticTableConfiguration(CustomBaseModel):
808
822
  description="Specify a list of column names that are to be imputed.\nImputed columns will suppress the sampling of NULL values.\n",
809
823
  ),
810
824
  ] = None
825
+ fairness: Optional[SyntheticTableFairness] = None
811
826
 
812
827
 
813
828
  class SyntheticTableName(RootModel[str]):
@@ -857,6 +872,30 @@ class SyntheticTable(CustomBaseModel):
857
872
  Optional[List[ForeignKey]],
858
873
  Field(None, alias="foreignKeys", description="The foreign keys of this table."),
859
874
  ] = None
875
+ total_rows: Annotated[
876
+ Optional[int],
877
+ Field(
878
+ None,
879
+ alias="totalRows",
880
+ description="The total number of rows for that table in the generated synthetic dataset.\n",
881
+ ),
882
+ ] = None
883
+ total_datapoints: Annotated[
884
+ Optional[int],
885
+ Field(
886
+ None,
887
+ alias="totalDatapoints",
888
+ description="The total number of datapoints for that table in the generated synthetic dataset.\n",
889
+ ),
890
+ ] = None
891
+ source_table_total_rows: Annotated[
892
+ Optional[int],
893
+ Field(
894
+ None,
895
+ alias="sourceTableTotalRows",
896
+ description="The total number of rows in the source table while fetching data for training.\n",
897
+ ),
898
+ ] = None
860
899
 
861
900
 
862
901
  class SyntheticDatasetDelivery(CustomBaseModel):
@@ -1501,6 +1540,24 @@ class Generator(CustomBaseModel):
1501
1540
  def shares(self):
1502
1541
  return self.client._shares(resource=self)
1503
1542
 
1543
+ def export_to_file(
1544
+ self,
1545
+ file_path: Union[str, Path, None] = None,
1546
+ ) -> Path:
1547
+ """
1548
+ Export generator and save to file.
1549
+ Supported from release v212 onwards.
1550
+
1551
+ :param file_path: Optional. The file path to save the synthetic dataset.
1552
+ :return: The file path of the exported generator
1553
+ """
1554
+ bytes, filename = self.client._export_to_file(generator_id=self.id)
1555
+ file_path = Path(file_path or ".")
1556
+ if file_path.is_dir():
1557
+ file_path = file_path / filename
1558
+ file_path.write_bytes(bytes)
1559
+ return file_path
1560
+
1504
1561
  class Training:
1505
1562
  def __init__(self, _generator: "Generator"):
1506
1563
  self.generator = _generator
@@ -122,7 +122,7 @@ class _MostlySyntheticDatasetsClient(_MostlyBaseClient):
122
122
  content_disposition = response.headers["Content-Disposition"]
123
123
  filename = re.findall("filename=(.+)", content_disposition)[0]
124
124
  else:
125
- filename = None
125
+ filename = f"synthetic-dataset-{synthetic_dataset_id[:8]}.zip"
126
126
  return content_bytes, filename
127
127
 
128
128
  def _data(
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "mostlyai"
3
- version = "0.3.9"
3
+ version = "0.3.10"
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>"]
@@ -29,21 +29,10 @@ respx = "^0.20.2"
29
29
  twine = "^5.0.0"
30
30
  commitizen = "^3.18.0"
31
31
  mkdocs = "^1.5.3"
32
- mkdocstrings = "^0.24.1"
32
+ mkdocstrings = { version = "^0.24.1", extras = ["crystal", "python"] }
33
33
  mkdocs-material = "^9.5.13"
34
34
  poetry-bumpversion = "^0.3.2"
35
35
 
36
- [tool.mypy]
37
- python_version = "3.9"
38
- follow_imports = "silent"
39
- ignore_missing_imports = true
40
- warn_unused_to_dicts = true
41
- warn_redundant_casts = true
42
- warn_unreachable = true
43
-
44
- [tool.isort]
45
- profile = "black"
46
-
47
36
  [tool.commitizen]
48
37
  name = "cz_conventional_commits"
49
38
  tag_format = "$version"
@@ -1,4 +0,0 @@
1
- from mostlyai.api import MostlyAI
2
-
3
- __all__ = ["MostlyAI"]
4
- __version__ = "0.3.9" # Do not set this manually. Use poetry version [params].
File without changes
File without changes
File without changes
File without changes