mostlyai 0.3.8__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.
- {mostlyai-0.3.8 → mostlyai-0.3.10}/PKG-INFO +29 -12
- {mostlyai-0.3.8 → mostlyai-0.3.10}/README.md +28 -11
- mostlyai-0.3.10/mostlyai/__init__.py +4 -0
- {mostlyai-0.3.8 → mostlyai-0.3.10}/mostlyai/api.py +19 -7
- {mostlyai-0.3.8 → mostlyai-0.3.10}/mostlyai/base.py +2 -1
- {mostlyai-0.3.8 → mostlyai-0.3.10}/mostlyai/generators.py +44 -0
- {mostlyai-0.3.8 → mostlyai-0.3.10}/mostlyai/model.py +60 -3
- {mostlyai-0.3.8 → mostlyai-0.3.10}/mostlyai/synthetic_datasets.py +1 -1
- {mostlyai-0.3.8 → mostlyai-0.3.10}/pyproject.toml +2 -13
- mostlyai-0.3.8/mostlyai/__init__.py +0 -4
- {mostlyai-0.3.8 → mostlyai-0.3.10}/LICENSE +0 -0
- {mostlyai-0.3.8 → mostlyai-0.3.10}/mostlyai/connectors.py +0 -0
- {mostlyai-0.3.8 → mostlyai-0.3.10}/mostlyai/exceptions.py +0 -0
- {mostlyai-0.3.8 → mostlyai-0.3.10}/mostlyai/shares.py +0 -0
- {mostlyai-0.3.8 → mostlyai-0.3.10}/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.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
|
|
@@ -24,21 +24,24 @@ Description-Content-Type: text/markdown
|
|
|
24
24
|
|
|
25
25
|
A Python wrapper for the MOSTLY AI platform (https://app.mostly.ai/).
|
|
26
26
|
|
|
27
|
-
| Intent | Primitive
|
|
28
|
-
|
|
29
|
-
| Train a Generative AI on tabular data | `g = mostly.train(data)`
|
|
30
|
-
| Empower your team with safe synthetic data | `mostly.share(g, email)`
|
|
31
|
-
| Generate
|
|
32
|
-
| Prompt the generator for the data that you need | `mostly.generate(g, seed)`
|
|
33
|
-
|
|
|
34
|
-
|
|
|
27
|
+
| Intent | Primitive |
|
|
28
|
+
|-------------------------------------------------|----------------------------------|
|
|
29
|
+
| Train a Generative AI on tabular data | `g = mostly.train(data)` |
|
|
30
|
+
| Empower your team with safe synthetic data | `mostly.share(g, email)` |
|
|
31
|
+
| Generate any number of synthetic data records | `mostly.generate(g, size)` |
|
|
32
|
+
| Prompt the generator for the data that you need | `mostly.generate(g, seed)` |
|
|
33
|
+
| Live probe the generator on demand | `mostly.probe(g, size \| seed)` |
|
|
34
|
+
| Connect to any data source within your org | `mostly.connect(config)` |
|
|
35
|
+
| Info about the current user | `mostly.me()` |
|
|
36
|
+
| Info about the platform | `mostly.about()` |
|
|
35
37
|
|
|
36
38
|
|
|
37
39
|
|
|
38
40
|
|
|
39
41
|
## Installation
|
|
42
|
+
|
|
40
43
|
```shell
|
|
41
|
-
pip install mostlyai
|
|
44
|
+
pip install -U mostlyai
|
|
42
45
|
```
|
|
43
46
|
|
|
44
47
|
## Basic Usage
|
|
@@ -46,8 +49,10 @@ pip install mostlyai
|
|
|
46
49
|
from mostlyai import MostlyAI
|
|
47
50
|
mostly = MostlyAI(api_key='your_api_key')
|
|
48
51
|
g = mostly.train(data) # train a generator on your data
|
|
49
|
-
|
|
50
|
-
|
|
52
|
+
mostly.share(g, email) # share the generator with your team
|
|
53
|
+
sd = mostly.generate(g) # use the generator to create a synthetic dataset
|
|
54
|
+
syn = sd.data() # consume the synthetic data as pandas DataFrame(s)
|
|
55
|
+
mostly.probe(g, size=100) # generate few samples on demand
|
|
51
56
|
```
|
|
52
57
|
|
|
53
58
|
## Supported Methods
|
|
@@ -82,10 +87,15 @@ g.open()
|
|
|
82
87
|
g.reload()
|
|
83
88
|
g.delete()
|
|
84
89
|
|
|
90
|
+
# training
|
|
85
91
|
g.training.start()
|
|
86
92
|
g.training.progress()
|
|
87
93
|
g.training.cancel()
|
|
88
94
|
g.training.wait()
|
|
95
|
+
|
|
96
|
+
# import / export
|
|
97
|
+
g.export_to_file(file_path)
|
|
98
|
+
mostly.generators.import_from_file(file_path)
|
|
89
99
|
```
|
|
90
100
|
|
|
91
101
|
### Synthetic Datasets
|
|
@@ -131,3 +141,10 @@ sd.shares()
|
|
|
131
141
|
c.shares()
|
|
132
142
|
```
|
|
133
143
|
|
|
144
|
+
### Info
|
|
145
|
+
|
|
146
|
+
```python
|
|
147
|
+
mostly.about()
|
|
148
|
+
mostly.me()
|
|
149
|
+
```
|
|
150
|
+
|
|
@@ -2,21 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
A Python wrapper for the MOSTLY AI platform (https://app.mostly.ai/).
|
|
4
4
|
|
|
5
|
-
| Intent | Primitive
|
|
6
|
-
|
|
7
|
-
| Train a Generative AI on tabular data | `g = mostly.train(data)`
|
|
8
|
-
| Empower your team with safe synthetic data | `mostly.share(g, email)`
|
|
9
|
-
| Generate
|
|
10
|
-
| Prompt the generator for the data that you need | `mostly.generate(g, seed)`
|
|
11
|
-
|
|
|
12
|
-
|
|
|
5
|
+
| Intent | Primitive |
|
|
6
|
+
|-------------------------------------------------|----------------------------------|
|
|
7
|
+
| Train a Generative AI on tabular data | `g = mostly.train(data)` |
|
|
8
|
+
| Empower your team with safe synthetic data | `mostly.share(g, email)` |
|
|
9
|
+
| Generate any number of synthetic data records | `mostly.generate(g, size)` |
|
|
10
|
+
| Prompt the generator for the data that you need | `mostly.generate(g, seed)` |
|
|
11
|
+
| Live probe the generator on demand | `mostly.probe(g, size \| seed)` |
|
|
12
|
+
| Connect to any data source within your org | `mostly.connect(config)` |
|
|
13
|
+
| Info about the current user | `mostly.me()` |
|
|
14
|
+
| Info about the platform | `mostly.about()` |
|
|
13
15
|
|
|
14
16
|
|
|
15
17
|
|
|
16
18
|
|
|
17
19
|
## Installation
|
|
20
|
+
|
|
18
21
|
```shell
|
|
19
|
-
pip install mostlyai
|
|
22
|
+
pip install -U mostlyai
|
|
20
23
|
```
|
|
21
24
|
|
|
22
25
|
## Basic Usage
|
|
@@ -24,8 +27,10 @@ pip install mostlyai
|
|
|
24
27
|
from mostlyai import MostlyAI
|
|
25
28
|
mostly = MostlyAI(api_key='your_api_key')
|
|
26
29
|
g = mostly.train(data) # train a generator on your data
|
|
27
|
-
|
|
28
|
-
|
|
30
|
+
mostly.share(g, email) # share the generator with your team
|
|
31
|
+
sd = mostly.generate(g) # use the generator to create a synthetic dataset
|
|
32
|
+
syn = sd.data() # consume the synthetic data as pandas DataFrame(s)
|
|
33
|
+
mostly.probe(g, size=100) # generate few samples on demand
|
|
29
34
|
```
|
|
30
35
|
|
|
31
36
|
## Supported Methods
|
|
@@ -60,10 +65,15 @@ g.open()
|
|
|
60
65
|
g.reload()
|
|
61
66
|
g.delete()
|
|
62
67
|
|
|
68
|
+
# training
|
|
63
69
|
g.training.start()
|
|
64
70
|
g.training.progress()
|
|
65
71
|
g.training.cancel()
|
|
66
72
|
g.training.wait()
|
|
73
|
+
|
|
74
|
+
# import / export
|
|
75
|
+
g.export_to_file(file_path)
|
|
76
|
+
mostly.generators.import_from_file(file_path)
|
|
67
77
|
```
|
|
68
78
|
|
|
69
79
|
### Synthetic Datasets
|
|
@@ -108,3 +118,10 @@ g.shares()
|
|
|
108
118
|
sd.shares()
|
|
109
119
|
c.shares()
|
|
110
120
|
```
|
|
121
|
+
|
|
122
|
+
### Info
|
|
123
|
+
|
|
124
|
+
```python
|
|
125
|
+
mostly.about()
|
|
126
|
+
mostly.me()
|
|
127
|
+
```
|
|
@@ -115,12 +115,15 @@ class MostlyAI(_MostlyBaseClient):
|
|
|
115
115
|
host: string
|
|
116
116
|
port: integer, default: 10000
|
|
117
117
|
username: string (required for regular auth)
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
118
|
+
kerberosEnabled: boolean, default: false
|
|
119
|
+
kerberosPrincipal: string (required if kerberosEnabled)
|
|
120
|
+
kerberosKrb5Conf: string (required if kerberosEnabled)
|
|
121
|
+
sslEnabled: boolean, default: false
|
|
121
122
|
secrets:
|
|
122
123
|
password: string (required for regular auth)
|
|
123
|
-
|
|
124
|
+
kerberosKeytab: base64-encoded string (required if kerberosEnabled)
|
|
125
|
+
ssl:
|
|
126
|
+
caCertificate: base64-encoded string
|
|
124
127
|
|
|
125
128
|
- type: MARIADB
|
|
126
129
|
config:
|
|
@@ -163,12 +166,13 @@ class MostlyAI(_MostlyBaseClient):
|
|
|
163
166
|
port: integer, default: 5432
|
|
164
167
|
username: string
|
|
165
168
|
database: string
|
|
169
|
+
sslEnabled: boolean, default: false
|
|
166
170
|
secrets:
|
|
167
171
|
password: string
|
|
168
172
|
ssl:
|
|
169
|
-
rootCertificate: string
|
|
170
|
-
sslCertificate: string
|
|
171
|
-
sslCertificateKey: string
|
|
173
|
+
rootCertificate: base64-encoded string
|
|
174
|
+
sslCertificate: base64-encoded string
|
|
175
|
+
sslCertificateKey: base64-encoded string
|
|
172
176
|
|
|
173
177
|
- type: SNOWFLAKE
|
|
174
178
|
config:
|
|
@@ -370,3 +374,11 @@ class MostlyAI(_MostlyBaseClient):
|
|
|
370
374
|
:return: info about the current user.
|
|
371
375
|
"""
|
|
372
376
|
return self.request(verb=GET, path=["users", "me"], response_type=CurrentUser)
|
|
377
|
+
|
|
378
|
+
def about(self) -> dict[str, Any]:
|
|
379
|
+
"""
|
|
380
|
+
Retrieve about info from the endpoint.
|
|
381
|
+
Supported from release v210 onwards.
|
|
382
|
+
:return: info about the platform.
|
|
383
|
+
"""
|
|
384
|
+
return self.request(verb=GET, path=["about"])
|
|
@@ -213,7 +213,7 @@ class CustomBaseModel(BaseModel):
|
|
|
213
213
|
rich.print(self.dict())
|
|
214
214
|
return capture.get()
|
|
215
215
|
|
|
216
|
-
def open(self):
|
|
216
|
+
def open(self) -> str:
|
|
217
217
|
"""
|
|
218
218
|
Opens the instance in a web browser.
|
|
219
219
|
"""
|
|
@@ -221,6 +221,7 @@ class CustomBaseModel(BaseModel):
|
|
|
221
221
|
raise APIError("Cannot open the instance")
|
|
222
222
|
url = "/".join([self.client.base_url, *self.OPEN_URL_PARTS, str(self.id)])
|
|
223
223
|
webbrowser.open_new(url)
|
|
224
|
+
return url
|
|
224
225
|
|
|
225
226
|
def reload(self):
|
|
226
227
|
"""
|
|
@@ -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-
|
|
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.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"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|