mostlyai 0.3.9__tar.gz → 0.3.11__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.
- {mostlyai-0.3.9 → mostlyai-0.3.11}/PKG-INFO +6 -1
- {mostlyai-0.3.9 → mostlyai-0.3.11}/README.md +5 -0
- mostlyai-0.3.11/mostlyai/__init__.py +4 -0
- {mostlyai-0.3.9 → mostlyai-0.3.11}/mostlyai/api.py +1 -1
- {mostlyai-0.3.9 → mostlyai-0.3.11}/mostlyai/generators.py +52 -0
- {mostlyai-0.3.9 → mostlyai-0.3.11}/mostlyai/model.py +60 -3
- {mostlyai-0.3.9 → mostlyai-0.3.11}/mostlyai/synthetic_datasets.py +1 -1
- {mostlyai-0.3.9 → mostlyai-0.3.11}/pyproject.toml +2 -13
- mostlyai-0.3.9/mostlyai/__init__.py +0 -4
- {mostlyai-0.3.9 → mostlyai-0.3.11}/LICENSE +0 -0
- {mostlyai-0.3.9 → mostlyai-0.3.11}/mostlyai/base.py +0 -0
- {mostlyai-0.3.9 → mostlyai-0.3.11}/mostlyai/connectors.py +0 -0
- {mostlyai-0.3.9 → mostlyai-0.3.11}/mostlyai/exceptions.py +0 -0
- {mostlyai-0.3.9 → mostlyai-0.3.11}/mostlyai/shares.py +0 -0
- {mostlyai-0.3.9 → mostlyai-0.3.11}/mostlyai/utils.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: mostlyai
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.11
|
|
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
|
|
@@ -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
|
|
|
@@ -69,13 +70,64 @@ class _MostlyGeneratorsClient(_MostlyBaseClient, _MostlySharesMixin):
|
|
|
69
70
|
table["data"] = _convert_to_base64(table["data"])
|
|
70
71
|
else:
|
|
71
72
|
raise ValueError("data must be a DataFrame or a file path")
|
|
73
|
+
# convert `columns` to list[dict], if provided as list[str]
|
|
74
|
+
if "tables" in config and config["tables"]:
|
|
75
|
+
for table in config["tables"]:
|
|
76
|
+
if "columns" in table and table["columns"]:
|
|
77
|
+
table["columns"] = [
|
|
78
|
+
{"name": col} if isinstance(col, str) else col
|
|
79
|
+
for col in table["columns"]
|
|
80
|
+
]
|
|
72
81
|
|
|
73
82
|
generator = self.request(
|
|
74
83
|
verb=POST, path=[], json=config, response_type=Generator
|
|
75
84
|
)
|
|
76
85
|
return generator
|
|
77
86
|
|
|
87
|
+
def import_from_file(
|
|
88
|
+
self,
|
|
89
|
+
file_path: Union[str, Path],
|
|
90
|
+
) -> Generator:
|
|
91
|
+
"""
|
|
92
|
+
Import a generator from a file.
|
|
93
|
+
Supported from release v212 onwards.
|
|
94
|
+
|
|
95
|
+
:param file_path: Path to the file to import.
|
|
96
|
+
:return: The imported generator.
|
|
97
|
+
"""
|
|
98
|
+
response = self.request(
|
|
99
|
+
verb=POST,
|
|
100
|
+
path=["import-from-file"],
|
|
101
|
+
headers={
|
|
102
|
+
"Accept": "application/json, text/plain, */*",
|
|
103
|
+
},
|
|
104
|
+
files={"file": open(file_path, "rb")},
|
|
105
|
+
response_type=Generator,
|
|
106
|
+
)
|
|
107
|
+
return response
|
|
108
|
+
|
|
78
109
|
# PRIVATE METHODS #
|
|
110
|
+
def _export_to_file(
|
|
111
|
+
self,
|
|
112
|
+
generator_id: str,
|
|
113
|
+
) -> (bytes, Optional[str]):
|
|
114
|
+
response = self.request(
|
|
115
|
+
verb=GET,
|
|
116
|
+
path=[generator_id, "export-to-file"],
|
|
117
|
+
headers={
|
|
118
|
+
"Content-Type": "application/octet-stream",
|
|
119
|
+
"Accept": "application/json, text/plain, */*",
|
|
120
|
+
},
|
|
121
|
+
raw_response=True,
|
|
122
|
+
)
|
|
123
|
+
content_bytes = response.content
|
|
124
|
+
# Check if 'Content-Disposition' header is present
|
|
125
|
+
if "Content-Disposition" in response.headers:
|
|
126
|
+
content_disposition = response.headers["Content-Disposition"]
|
|
127
|
+
filename = re.findall("filename=(.+)", content_disposition)[0]
|
|
128
|
+
else:
|
|
129
|
+
filename = f"generator-{generator_id[:8]}.mostly"
|
|
130
|
+
return content_bytes, filename
|
|
79
131
|
|
|
80
132
|
def _update(self, generator_id: str, config: dict[str, Any]) -> Generator:
|
|
81
133
|
response = self.request(
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# generated by datamodel-codegen:
|
|
2
|
-
# timestamp: 2024-
|
|
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
|
|
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 =
|
|
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.
|
|
3
|
+
version = "0.3.11"
|
|
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"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|