mostlyai 4.0.4__tar.gz → 4.0.6__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-4.0.4 → mostlyai-4.0.6}/PKG-INFO +60 -58
- {mostlyai-4.0.4 → mostlyai-4.0.6}/README.md +35 -30
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/__init__.py +1 -1
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_data/util/common.py +1 -1
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_local/execution/jobs.py +1 -1
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_local/generators.py +39 -2
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_local/routes.py +13 -15
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_local/synthetic_datasets.py +28 -20
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/client/_utils.py +3 -1
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/client/api.py +5 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/client/base.py +13 -2
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/domain.py +194 -37
- {mostlyai-4.0.4 → mostlyai-4.0.6}/pyproject.toml +33 -29
- {mostlyai-4.0.4 → mostlyai-4.0.6}/.gitignore +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/LICENSE +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_data/__init__.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_data/auto_detect.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_data/base.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_data/context.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_data/conversions.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_data/db/__init__.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_data/db/base.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_data/db/bigquery.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_data/db/databricks.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_data/db/hive.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_data/db/mssql.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_data/db/mysql.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_data/db/oracle.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_data/db/postgresql.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_data/db/snowflake.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_data/db/sqlite.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_data/db/types_coercion.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_data/dtype.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_data/exceptions.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_data/file/__init__.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_data/file/base.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_data/file/container/__init__.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_data/file/container/aws.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_data/file/container/azure.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_data/file/container/bucket_based.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_data/file/container/gcs.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_data/file/container/minio.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_data/file/table/__init__.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_data/file/table/csv.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_data/file/table/feather.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_data/file/table/json.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_data/file/table/parquet.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_data/file/utils.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_data/language_model.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_data/metadata_objects.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_data/non_context.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_data/progress_callback.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_data/pull.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_data/pull_context.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_data/pull_utils.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_data/push.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_data/util/__init__.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_data/util/kerberos.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_local/__init__.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_local/cli.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_local/connectors.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_local/execution/__init__.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_local/execution/plan.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_local/execution/step_analyze_training_data.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_local/execution/step_create_data_report.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_local/execution/step_create_model_report.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_local/execution/step_deliver_data.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_local/execution/step_encode_training_data.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_local/execution/step_finalize_generation.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_local/execution/step_finalize_training.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_local/execution/step_generate_data.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_local/execution/step_generate_model_report_data.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_local/execution/step_pull_training_data.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_local/execution/step_train_model.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_local/progress.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_local/server.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/_local/storage.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/client/__init__.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/client/_base_utils.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/client/_naming_conventions.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/client/connectors.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/client/exceptions.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/client/generators.py +0 -0
- {mostlyai-4.0.4 → mostlyai-4.0.6}/mostlyai/sdk/client/synthetic_datasets.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mostlyai
|
|
3
|
-
Version: 4.0.
|
|
3
|
+
Version: 4.0.6
|
|
4
4
|
Summary: Synthetic Data SDK
|
|
5
5
|
Project-URL: homepage, https://app.mostly.ai/
|
|
6
6
|
Project-URL: repository, https://github.com/mostly-ai/mostlyai
|
|
@@ -23,40 +23,35 @@ Classifier: Programming Language :: Python :: 3.12
|
|
|
23
23
|
Classifier: Programming Language :: Python :: 3.13
|
|
24
24
|
Classifier: Topic :: Software Development :: Libraries
|
|
25
25
|
Classifier: Typing :: Typed
|
|
26
|
-
Requires-Python:
|
|
26
|
+
Requires-Python: <3.14,>=3.10
|
|
27
27
|
Requires-Dist: adlfs<2024,>=2023.4.0
|
|
28
28
|
Requires-Dist: azure-storage-blob<13,>=12.16.0
|
|
29
29
|
Requires-Dist: cloudpathlib[azure,gs,s3]<0.18,>=0.17.0
|
|
30
|
-
Requires-Dist:
|
|
31
|
-
Requires-Dist: environs<10,>=9.5.0
|
|
32
|
-
Requires-Dist: fastparquet<2024,>=2023.4.0
|
|
30
|
+
Requires-Dist: environs>=9.5.0
|
|
33
31
|
Requires-Dist: filelock>=3.16.1
|
|
34
32
|
Requires-Dist: gcsfs<2024,>=2023.1.0
|
|
35
|
-
Requires-Dist: gputil<2,>=1.4.0
|
|
36
33
|
Requires-Dist: greenlet<4,>=3.1.1
|
|
37
|
-
Requires-Dist: gunicorn
|
|
38
|
-
Requires-Dist: httpx
|
|
39
|
-
Requires-Dist: joblib
|
|
40
|
-
Requires-Dist: networkx~=3.1
|
|
34
|
+
Requires-Dist: gunicorn>=23.0.0
|
|
35
|
+
Requires-Dist: httpx>=0.25.0
|
|
36
|
+
Requires-Dist: joblib>=1.2.0
|
|
41
37
|
Requires-Dist: openpyxl>=3.1.5
|
|
42
|
-
Requires-Dist: pandas
|
|
43
|
-
Requires-Dist: psutil
|
|
38
|
+
Requires-Dist: pandas>=2.0.0
|
|
39
|
+
Requires-Dist: psutil>=5.9.5
|
|
44
40
|
Requires-Dist: pyarrow>=16.0.0
|
|
45
|
-
Requires-Dist: pycryptodomex<4,>=3.
|
|
41
|
+
Requires-Dist: pycryptodomex<4,>=3.10.0
|
|
46
42
|
Requires-Dist: pydantic<3,>=2.4.2
|
|
47
|
-
Requires-Dist:
|
|
48
|
-
Requires-Dist: requests<3,>=2.31.0
|
|
43
|
+
Requires-Dist: requests>=2.31.0
|
|
49
44
|
Requires-Dist: rich>=13.7.0
|
|
50
45
|
Requires-Dist: s3fs<2024,>=2023.1.0
|
|
51
|
-
Requires-Dist: schema
|
|
52
|
-
Requires-Dist: semantic-version
|
|
46
|
+
Requires-Dist: schema>=0.7.5
|
|
47
|
+
Requires-Dist: semantic-version>=2.10.0
|
|
53
48
|
Requires-Dist: smart-open>=6.0.0
|
|
54
49
|
Requires-Dist: smart-open[azure,gcs,s3]<7,>=6.3.0
|
|
55
|
-
Requires-Dist: sqlalchemy
|
|
50
|
+
Requires-Dist: sqlalchemy>=2.0.0
|
|
56
51
|
Requires-Dist: sshtunnel<0.5,>=0.4.0
|
|
57
|
-
Requires-Dist: typer
|
|
52
|
+
Requires-Dist: typer>=0.9.0
|
|
58
53
|
Requires-Dist: xlsxwriter<4,>=3.1.9
|
|
59
|
-
Requires-Dist: xxhash
|
|
54
|
+
Requires-Dist: xxhash>=3.2.0
|
|
60
55
|
Provides-Extra: databricks
|
|
61
56
|
Requires-Dist: databricks-sql-connector<4,>=3.2.0; extra == 'databricks'
|
|
62
57
|
Provides-Extra: googlebigquery
|
|
@@ -67,23 +62,25 @@ Requires-Dist: kerberos<2,>=1.3.1; extra == 'hive'
|
|
|
67
62
|
Requires-Dist: pyhive[hive-pure-sasl]<0.8,>=0.7.0; extra == 'hive'
|
|
68
63
|
Provides-Extra: local
|
|
69
64
|
Requires-Dist: fastapi<0.116,>=0.115.6; extra == 'local'
|
|
70
|
-
Requires-Dist: mostlyai-engine==1.0.
|
|
71
|
-
Requires-Dist: mostlyai-qa==1.5.
|
|
65
|
+
Requires-Dist: mostlyai-engine==1.0.3; extra == 'local'
|
|
66
|
+
Requires-Dist: mostlyai-qa==1.5.2; extra == 'local'
|
|
72
67
|
Requires-Dist: python-multipart>=0.0.20; extra == 'local'
|
|
68
|
+
Requires-Dist: torch<2.6.0,>=2.5.1; extra == 'local'
|
|
73
69
|
Requires-Dist: uvicorn<0.35,>=0.34.0; extra == 'local'
|
|
74
70
|
Provides-Extra: local-cpu
|
|
75
71
|
Requires-Dist: fastapi<0.116,>=0.115.6; extra == 'local-cpu'
|
|
76
|
-
Requires-Dist: mostlyai-engine[cpu]==1.0.
|
|
77
|
-
Requires-Dist: mostlyai-qa==1.5.
|
|
72
|
+
Requires-Dist: mostlyai-engine[cpu]==1.0.3; extra == 'local-cpu'
|
|
73
|
+
Requires-Dist: mostlyai-qa[cpu]==1.5.2; extra == 'local-cpu'
|
|
78
74
|
Requires-Dist: python-multipart>=0.0.20; extra == 'local-cpu'
|
|
79
|
-
Requires-Dist: torch
|
|
75
|
+
Requires-Dist: torch<2.6.0,>=2.5.1; (sys_platform != 'linux') and extra == 'local-cpu'
|
|
76
|
+
Requires-Dist: torch==2.5.1+cpu; (sys_platform == 'linux') and extra == 'local-cpu'
|
|
80
77
|
Requires-Dist: uvicorn<0.35,>=0.34.0; extra == 'local-cpu'
|
|
81
78
|
Provides-Extra: local-gpu
|
|
82
79
|
Requires-Dist: fastapi<0.116,>=0.115.6; extra == 'local-gpu'
|
|
83
|
-
Requires-Dist: mostlyai-engine[gpu]==1.0.
|
|
84
|
-
Requires-Dist: mostlyai-qa==1.5.
|
|
80
|
+
Requires-Dist: mostlyai-engine[gpu]==1.0.3; extra == 'local-gpu'
|
|
81
|
+
Requires-Dist: mostlyai-qa[gpu]==1.5.2; extra == 'local-gpu'
|
|
85
82
|
Requires-Dist: python-multipart>=0.0.20; extra == 'local-gpu'
|
|
86
|
-
Requires-Dist: torch
|
|
83
|
+
Requires-Dist: torch<2.6.0,>=2.5.1; extra == 'local-gpu'
|
|
87
84
|
Requires-Dist: uvicorn<0.35,>=0.34.0; extra == 'local-gpu'
|
|
88
85
|
Provides-Extra: mssql
|
|
89
86
|
Requires-Dist: pyodbc<6,>=5.1.0; extra == 'mssql'
|
|
@@ -100,13 +97,13 @@ Description-Content-Type: text/markdown
|
|
|
100
97
|
|
|
101
98
|
# Synthetic Data SDK ✨
|
|
102
99
|
|
|
103
|
-
[](https://mostly-ai.github.io/mostlyai/) [](https://mostly-ai.github.io/mostlyai/) [](https://pepy.tech/projects/mostlyai)    [](https://github.com/mostly-ai/mostlyai)
|
|
104
101
|
|
|
105
102
|
[SDK Documentation](https://mostly-ai.github.io/mostlyai/) | [Platform Documentation](https://mostly.ai/docs) | [Usage Examples](https://mostly-ai.github.io/mostlyai/usage/)
|
|
106
103
|
|
|
107
|
-
The
|
|
104
|
+
The Synthetic Data SDK is a Python toolkit for high-fidelity, privacy-safe **Synthetic Data**.
|
|
108
105
|
|
|
109
|
-
- **Client mode** connects to a remote MOSTLY AI platform for training & generating synthetic data there.
|
|
106
|
+
- **Client mode** connects to a remote [MOSTLY AI platform](https://app.mostly.ai/) for training & generating synthetic data there.
|
|
110
107
|
- **Local mode** trains and generates synthetic data locally on your own compute resources.
|
|
111
108
|
- Generators, that were trained locally, can be easily imported to a platform for further sharing.
|
|
112
109
|
|
|
@@ -136,12 +133,14 @@ pip install -U mostlyai
|
|
|
136
133
|
**Client + Local mode**
|
|
137
134
|
|
|
138
135
|
```shell
|
|
139
|
-
|
|
140
|
-
|
|
136
|
+
# for CPU on macOS
|
|
137
|
+
pip install -U 'mostlyai[local]'
|
|
138
|
+
# for CPU on Linux
|
|
139
|
+
#pip install -U mostlyai[local] --extra-index-url https://download.pytorch.org/whl/cpu
|
|
140
|
+
# for GPU on Linux
|
|
141
|
+
#pip install -U mostlyai[local-gpu]
|
|
141
142
|
```
|
|
142
143
|
|
|
143
|
-
NOTE: installing `mostlyai[local]` on Linux requires `--extra-index-url https://download.pytorch.org/whl/cpu` to be specified.
|
|
144
|
-
|
|
145
144
|
**Optional Connectors**
|
|
146
145
|
|
|
147
146
|
Add any of the following extras for further data connectors support: `databricks`, `googlebigquery`, `hive`, `mssql`, `mysql`, `oracle`, `postgres`, `snowflake`.
|
|
@@ -151,41 +150,44 @@ E.g.
|
|
|
151
150
|
pip install -U 'mostlyai[local, databricks, snowflake]'
|
|
152
151
|
```
|
|
153
152
|
|
|
154
|
-
## Quick Start
|
|
153
|
+
## Quick Start [](https://colab.research.google.com/github/mostly-ai/mostlyai/blob/main/docs/tutorials/getting-started/getting-started.ipynb)
|
|
155
154
|
|
|
156
|
-
For client mode, initialize with `base_url` and `api_key` obtained from your [account settings page](https://app.mostly.ai/settings/api-keys).
|
|
155
|
+
Generate your first samples based on your own trained generator with a few lines of code. For local mode, initialize the SDK with `local=True`. For client mode, initialize the SDK with `base_url` and `api_key` obtained from your [account settings page](https://app.mostly.ai/settings/api-keys).
|
|
157
156
|
|
|
158
157
|
```python
|
|
159
158
|
import pandas as pd
|
|
160
159
|
from mostlyai.sdk import MostlyAI
|
|
161
160
|
|
|
162
161
|
# load original data
|
|
163
|
-
repo_url =
|
|
164
|
-
df_original = pd.read_csv(f
|
|
162
|
+
repo_url = "https://github.com/mostly-ai/public-demo-data/raw/refs/heads/dev"
|
|
163
|
+
df_original = pd.read_csv(f"{repo_url}/census/census.csv.gz").sample(n=5_000)
|
|
165
164
|
|
|
166
165
|
# initialize the SDK in local or client mode
|
|
167
|
-
mostly = MostlyAI(local=True)
|
|
168
|
-
# mostly = MostlyAI(base_url='
|
|
166
|
+
mostly = MostlyAI(local=True) # local mode
|
|
167
|
+
# mostly = MostlyAI(base_url='xxx', api_key='xxx') # client mode
|
|
169
168
|
|
|
170
169
|
# train a synthetic data generator
|
|
171
|
-
g = mostly.train(
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
'
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
170
|
+
g = mostly.train(
|
|
171
|
+
config={
|
|
172
|
+
"name": "US Census Income",
|
|
173
|
+
"tables": [
|
|
174
|
+
{
|
|
175
|
+
"name": "census",
|
|
176
|
+
"data": df_original,
|
|
177
|
+
"tabular_model_configuration": { # tabular model configuration (optional)
|
|
178
|
+
"max_training_time": 1, # - limit training time (in minutes)
|
|
179
|
+
# model, max_epochs,,.. # further model configurations (optional)
|
|
180
|
+
# 'differential_privacy': { # differential privacy configuration (optional)
|
|
181
|
+
# 'max_epsilon': 5.0, # - max epsilon value, used as stopping criterion
|
|
182
|
+
# 'delta': 1e-5, # - delta value
|
|
183
|
+
# }
|
|
184
|
+
},
|
|
185
|
+
# columns, keys, compute,.. # further table configurations (optional)
|
|
186
|
+
}
|
|
187
|
+
],
|
|
186
188
|
},
|
|
187
|
-
start=True,
|
|
188
|
-
wait=True,
|
|
189
|
+
start=True, # start training immediately (default: True)
|
|
190
|
+
wait=True, # wait for completion (default: True)
|
|
189
191
|
)
|
|
190
192
|
```
|
|
191
193
|
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
|
|
2
2
|
# Synthetic Data SDK ✨
|
|
3
3
|
|
|
4
|
-
[](https://mostly-ai.github.io/mostlyai/) [](https://mostly-ai.github.io/mostlyai/) [](https://pepy.tech/projects/mostlyai)    [](https://github.com/mostly-ai/mostlyai)
|
|
5
5
|
|
|
6
6
|
[SDK Documentation](https://mostly-ai.github.io/mostlyai/) | [Platform Documentation](https://mostly.ai/docs) | [Usage Examples](https://mostly-ai.github.io/mostlyai/usage/)
|
|
7
7
|
|
|
8
|
-
The
|
|
8
|
+
The Synthetic Data SDK is a Python toolkit for high-fidelity, privacy-safe **Synthetic Data**.
|
|
9
9
|
|
|
10
|
-
- **Client mode** connects to a remote MOSTLY AI platform for training & generating synthetic data there.
|
|
10
|
+
- **Client mode** connects to a remote [MOSTLY AI platform](https://app.mostly.ai/) for training & generating synthetic data there.
|
|
11
11
|
- **Local mode** trains and generates synthetic data locally on your own compute resources.
|
|
12
12
|
- Generators, that were trained locally, can be easily imported to a platform for further sharing.
|
|
13
13
|
|
|
@@ -37,12 +37,14 @@ pip install -U mostlyai
|
|
|
37
37
|
**Client + Local mode**
|
|
38
38
|
|
|
39
39
|
```shell
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
# for CPU on macOS
|
|
41
|
+
pip install -U 'mostlyai[local]'
|
|
42
|
+
# for CPU on Linux
|
|
43
|
+
#pip install -U mostlyai[local] --extra-index-url https://download.pytorch.org/whl/cpu
|
|
44
|
+
# for GPU on Linux
|
|
45
|
+
#pip install -U mostlyai[local-gpu]
|
|
42
46
|
```
|
|
43
47
|
|
|
44
|
-
NOTE: installing `mostlyai[local]` on Linux requires `--extra-index-url https://download.pytorch.org/whl/cpu` to be specified.
|
|
45
|
-
|
|
46
48
|
**Optional Connectors**
|
|
47
49
|
|
|
48
50
|
Add any of the following extras for further data connectors support: `databricks`, `googlebigquery`, `hive`, `mssql`, `mysql`, `oracle`, `postgres`, `snowflake`.
|
|
@@ -52,41 +54,44 @@ E.g.
|
|
|
52
54
|
pip install -U 'mostlyai[local, databricks, snowflake]'
|
|
53
55
|
```
|
|
54
56
|
|
|
55
|
-
## Quick Start
|
|
57
|
+
## Quick Start [](https://colab.research.google.com/github/mostly-ai/mostlyai/blob/main/docs/tutorials/getting-started/getting-started.ipynb)
|
|
56
58
|
|
|
57
|
-
For client mode, initialize with `base_url` and `api_key` obtained from your [account settings page](https://app.mostly.ai/settings/api-keys).
|
|
59
|
+
Generate your first samples based on your own trained generator with a few lines of code. For local mode, initialize the SDK with `local=True`. For client mode, initialize the SDK with `base_url` and `api_key` obtained from your [account settings page](https://app.mostly.ai/settings/api-keys).
|
|
58
60
|
|
|
59
61
|
```python
|
|
60
62
|
import pandas as pd
|
|
61
63
|
from mostlyai.sdk import MostlyAI
|
|
62
64
|
|
|
63
65
|
# load original data
|
|
64
|
-
repo_url =
|
|
65
|
-
df_original = pd.read_csv(f
|
|
66
|
+
repo_url = "https://github.com/mostly-ai/public-demo-data/raw/refs/heads/dev"
|
|
67
|
+
df_original = pd.read_csv(f"{repo_url}/census/census.csv.gz").sample(n=5_000)
|
|
66
68
|
|
|
67
69
|
# initialize the SDK in local or client mode
|
|
68
|
-
mostly = MostlyAI(local=True)
|
|
69
|
-
# mostly = MostlyAI(base_url='
|
|
70
|
+
mostly = MostlyAI(local=True) # local mode
|
|
71
|
+
# mostly = MostlyAI(base_url='xxx', api_key='xxx') # client mode
|
|
70
72
|
|
|
71
73
|
# train a synthetic data generator
|
|
72
|
-
g = mostly.train(
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
'
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
74
|
+
g = mostly.train(
|
|
75
|
+
config={
|
|
76
|
+
"name": "US Census Income",
|
|
77
|
+
"tables": [
|
|
78
|
+
{
|
|
79
|
+
"name": "census",
|
|
80
|
+
"data": df_original,
|
|
81
|
+
"tabular_model_configuration": { # tabular model configuration (optional)
|
|
82
|
+
"max_training_time": 1, # - limit training time (in minutes)
|
|
83
|
+
# model, max_epochs,,.. # further model configurations (optional)
|
|
84
|
+
# 'differential_privacy': { # differential privacy configuration (optional)
|
|
85
|
+
# 'max_epsilon': 5.0, # - max epsilon value, used as stopping criterion
|
|
86
|
+
# 'delta': 1e-5, # - delta value
|
|
87
|
+
# }
|
|
88
|
+
},
|
|
89
|
+
# columns, keys, compute,.. # further table configurations (optional)
|
|
90
|
+
}
|
|
91
|
+
],
|
|
87
92
|
},
|
|
88
|
-
start=True,
|
|
89
|
-
wait=True,
|
|
93
|
+
start=True, # start training immediately (default: True)
|
|
94
|
+
wait=True, # wait for completion (default: True)
|
|
90
95
|
)
|
|
91
96
|
```
|
|
92
97
|
|
|
@@ -70,7 +70,7 @@ def create_key(passphrase: str) -> bytes:
|
|
|
70
70
|
|
|
71
71
|
def get_passphrase() -> str:
|
|
72
72
|
if _ENV_PASSPHRASE not in os.environ:
|
|
73
|
-
_LOG.
|
|
73
|
+
_LOG.info(f"Environment variable `{_ENV_PASSPHRASE}` is not set. Using default passphrase.")
|
|
74
74
|
passphrase = os.getenv(_ENV_PASSPHRASE, "mostly-secret")
|
|
75
75
|
return passphrase
|
|
76
76
|
|
|
@@ -170,7 +170,7 @@ def _set_overall_accuracy(generator: Generator) -> None:
|
|
|
170
170
|
|
|
171
171
|
def _probe_random_samples(home_dir: Path, generator: Generator) -> None:
|
|
172
172
|
config = SyntheticProbeConfig(generator_id=generator.id)
|
|
173
|
-
synthetic_dataset = create_synthetic_dataset(home_dir=home_dir, config=config,
|
|
173
|
+
synthetic_dataset = create_synthetic_dataset(home_dir=home_dir, config=config, sample_size=20)
|
|
174
174
|
probes = execute_probing_job(synthetic_dataset_id=synthetic_dataset.id, home_dir=home_dir)
|
|
175
175
|
|
|
176
176
|
random_samples_dir = home_dir / "generators" / generator.id / "RandomSamples"
|
|
@@ -14,7 +14,12 @@
|
|
|
14
14
|
|
|
15
15
|
from pathlib import Path
|
|
16
16
|
|
|
17
|
-
from mostlyai.sdk._local.storage import
|
|
17
|
+
from mostlyai.sdk._local.storage import (
|
|
18
|
+
write_generator_to_json,
|
|
19
|
+
write_connector_to_json,
|
|
20
|
+
write_job_progress_to_json,
|
|
21
|
+
read_generator_from_json,
|
|
22
|
+
)
|
|
18
23
|
from mostlyai.sdk._local.execution.plan import has_tabular_model, has_language_model, TRAINING_TASK_STEPS
|
|
19
24
|
from mostlyai.sdk.client._base_utils import convert_to_df
|
|
20
25
|
from mostlyai.sdk.domain import (
|
|
@@ -30,6 +35,8 @@ from mostlyai.sdk.domain import (
|
|
|
30
35
|
ProgressValue,
|
|
31
36
|
JobProgress,
|
|
32
37
|
TaskType,
|
|
38
|
+
SourceTableConfig,
|
|
39
|
+
SourceForeignKeyConfig,
|
|
33
40
|
)
|
|
34
41
|
|
|
35
42
|
|
|
@@ -67,7 +74,7 @@ def create_generator(home_dir: Path, config: GeneratorConfig) -> Generator:
|
|
|
67
74
|
"training_status": ProgressStatus.new,
|
|
68
75
|
"tables": [
|
|
69
76
|
{
|
|
70
|
-
**{k: v for k, v in t.model_dump().items() if k not in ["source_connector_id"]},
|
|
77
|
+
**{k: v for k, v in t.model_dump().items() if k not in ["source_connector_id", "data"]},
|
|
71
78
|
"source_connector_id": t.source_connector_id,
|
|
72
79
|
}
|
|
73
80
|
for t in (config.tables or [])
|
|
@@ -108,3 +115,33 @@ def create_generator(home_dir: Path, config: GeneratorConfig) -> Generator:
|
|
|
108
115
|
write_job_progress_to_json(generator_dir, job_progress)
|
|
109
116
|
|
|
110
117
|
return generator
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def get_generator_config(home_dir: Path, generator_id: str) -> GeneratorConfig:
|
|
121
|
+
generator_dir = home_dir / "generators" / generator_id
|
|
122
|
+
generator = read_generator_from_json(generator_dir)
|
|
123
|
+
# construct GeneratorConfig explicitly to avoid validation warnings of extra fields
|
|
124
|
+
config = GeneratorConfig(
|
|
125
|
+
name=generator.name,
|
|
126
|
+
description=generator.description,
|
|
127
|
+
tables=[
|
|
128
|
+
SourceTableConfig(
|
|
129
|
+
name=t.name,
|
|
130
|
+
source_connector_id=t.source_connector_id,
|
|
131
|
+
location=t.location,
|
|
132
|
+
tabular_model_configuration=t.tabular_model_configuration,
|
|
133
|
+
language_model_configuration=t.language_model_configuration,
|
|
134
|
+
primary_key=t.primary_key,
|
|
135
|
+
foreign_keys=[SourceForeignKeyConfig.model_construct(**k.model_dump()) for k in t.foreign_keys]
|
|
136
|
+
if t.foreign_keys
|
|
137
|
+
else None,
|
|
138
|
+
columns=[SourceColumnConfig.model_construct(**c.model_dump()) for c in t.columns]
|
|
139
|
+
if t.columns
|
|
140
|
+
else None,
|
|
141
|
+
)
|
|
142
|
+
for t in generator.tables
|
|
143
|
+
]
|
|
144
|
+
if generator.tables
|
|
145
|
+
else None,
|
|
146
|
+
)
|
|
147
|
+
return config
|
|
@@ -54,6 +54,7 @@ from mostlyai.sdk.domain import (
|
|
|
54
54
|
GeneratorCloneConfig,
|
|
55
55
|
GeneratorCloneTrainingStatus,
|
|
56
56
|
SyntheticDatasetReportType,
|
|
57
|
+
SyntheticDatasetListItem,
|
|
57
58
|
)
|
|
58
59
|
from mostlyai.sdk._local.storage import (
|
|
59
60
|
read_generator_from_json,
|
|
@@ -183,7 +184,8 @@ class Routes:
|
|
|
183
184
|
connector = read_connector_from_json(connector_dir)
|
|
184
185
|
if not searchTerm or searchTerm.lower() in (connector.name or "").lower():
|
|
185
186
|
if not access_type or access_type == connector.access_type:
|
|
186
|
-
|
|
187
|
+
# use model_construct to skip validation and warnings of extra fields
|
|
188
|
+
connector_list_items.append(ConnectorListItem.model_construct(**connector.model_dump()))
|
|
187
189
|
|
|
188
190
|
# use jsonable_encoder to handle non-serializable objects like datetime
|
|
189
191
|
return JSONResponse(
|
|
@@ -278,7 +280,8 @@ class Routes:
|
|
|
278
280
|
or searchTerm.lower() in (generator.description or "").lower()
|
|
279
281
|
):
|
|
280
282
|
if not status or status == generator.training_status:
|
|
281
|
-
|
|
283
|
+
# use model_construct to skip validation and warnings of extra fields
|
|
284
|
+
generator_list_items.append(GeneratorListItem.model_construct(**generator.model_dump()))
|
|
282
285
|
# use jsonable_encoder to handle non-serializable objects like datetime
|
|
283
286
|
return JSONResponse(
|
|
284
287
|
status_code=200,
|
|
@@ -338,10 +341,8 @@ class Routes:
|
|
|
338
341
|
# check if any connectors are file upload
|
|
339
342
|
if any(read_connector_from_json(c).type == ConnectorType.file_upload for c in connector_dirs):
|
|
340
343
|
raise HTTPException(status_code=400, detail="Cannot clone a generator with uploaded files.")
|
|
341
|
-
|
|
342
|
-
new_generator = create_generator_model(
|
|
343
|
-
home_dir=self.home_dir, config=GeneratorConfig(**generator.model_dump())
|
|
344
|
-
)
|
|
344
|
+
generator_config = generators.get_generator_config(self.home_dir, id)
|
|
345
|
+
new_generator = create_generator_model(home_dir=self.home_dir, config=generator_config)
|
|
345
346
|
new_generator_dir = self.home_dir / "generators" / new_generator.id
|
|
346
347
|
if config.training_status == GeneratorCloneTrainingStatus.continue_:
|
|
347
348
|
new_generator.training_status = ProgressStatus.continue_
|
|
@@ -410,10 +411,7 @@ class Routes:
|
|
|
410
411
|
|
|
411
412
|
@self.router.get("/generators/{id}/config", response_model=GeneratorConfig)
|
|
412
413
|
async def get_generator_config(id: str) -> GeneratorConfig:
|
|
413
|
-
|
|
414
|
-
generator = read_generator_from_json(generator_dir)
|
|
415
|
-
config = GeneratorConfig(**generator.model_dump())
|
|
416
|
-
return config
|
|
414
|
+
return generators.get_generator_config(self.home_dir, id)
|
|
417
415
|
|
|
418
416
|
### SYNTHETIC DATASETS
|
|
419
417
|
|
|
@@ -431,7 +429,10 @@ class Routes:
|
|
|
431
429
|
or searchTerm.lower() in (synthetic_dataset.description or "").lower()
|
|
432
430
|
):
|
|
433
431
|
if not status or status == synthetic_dataset.generation_status:
|
|
434
|
-
|
|
432
|
+
# use model_construct to skip validation and warnings of extra fields
|
|
433
|
+
synthetic_dataset_list_items.append(
|
|
434
|
+
SyntheticDatasetListItem.model_construct(**synthetic_dataset.model_dump())
|
|
435
|
+
)
|
|
435
436
|
# use jsonable_encoder to handle non-serializable objects like datetime
|
|
436
437
|
return JSONResponse(
|
|
437
438
|
status_code=200,
|
|
@@ -505,10 +506,7 @@ class Routes:
|
|
|
505
506
|
|
|
506
507
|
@self.router.get("/synthetic-datasets/{id}/config", response_model=SyntheticDatasetConfig)
|
|
507
508
|
async def get_synthetic_dataset_config(id: str) -> SyntheticDatasetConfig:
|
|
508
|
-
|
|
509
|
-
synthetic_dataset = read_synthetic_dataset_from_json(synthetic_dataset_dir)
|
|
510
|
-
config = SyntheticDatasetConfig(**synthetic_dataset.model_dump())
|
|
511
|
-
return config
|
|
509
|
+
return synthetic_datasets.get_synthetic_dataset_config(self.home_dir, id)
|
|
512
510
|
|
|
513
511
|
@self.router.get("/synthetic-datasets/{id}/download", response_class=FileResponse)
|
|
514
512
|
async def download_synthetic_dataset(id: str, slft: str, format: str) -> FileResponse:
|
|
@@ -19,6 +19,7 @@ from mostlyai.sdk._local.storage import (
|
|
|
19
19
|
write_job_progress_to_json,
|
|
20
20
|
read_generator_from_json,
|
|
21
21
|
write_connector_to_json,
|
|
22
|
+
read_synthetic_dataset_from_json,
|
|
22
23
|
)
|
|
23
24
|
from mostlyai.sdk._local.execution.plan import (
|
|
24
25
|
has_tabular_model,
|
|
@@ -36,19 +37,19 @@ from mostlyai.sdk.domain import (
|
|
|
36
37
|
ProgressValue,
|
|
37
38
|
JobProgress,
|
|
38
39
|
SyntheticTable,
|
|
39
|
-
SyntheticTableConfiguration,
|
|
40
40
|
TaskType,
|
|
41
41
|
Connector,
|
|
42
42
|
ConnectorType,
|
|
43
43
|
ConnectorAccessType,
|
|
44
44
|
SyntheticProbeConfig,
|
|
45
|
+
SyntheticTableConfig,
|
|
45
46
|
)
|
|
46
47
|
|
|
47
48
|
|
|
48
49
|
def create_synthetic_dataset(
|
|
49
50
|
home_dir: Path,
|
|
50
51
|
config: SyntheticDatasetConfig | SyntheticProbeConfig,
|
|
51
|
-
|
|
52
|
+
sample_size: int | None = None,
|
|
52
53
|
) -> SyntheticDataset:
|
|
53
54
|
# create a FILE_UPLOAD connector and replace sample_seed_dict/sample_seed_data with sample_seed_connector_id
|
|
54
55
|
for t in config.tables or []:
|
|
@@ -77,30 +78,21 @@ def create_synthetic_dataset(
|
|
|
77
78
|
generator_dir = home_dir / "generators" / config.generator_id
|
|
78
79
|
generator = read_generator_from_json(generator_dir)
|
|
79
80
|
|
|
80
|
-
# fill
|
|
81
|
-
|
|
82
|
-
|
|
81
|
+
# validate & fill defaults in config against generator
|
|
82
|
+
config.validate_against_generator(generator)
|
|
83
|
+
|
|
84
|
+
# create synthetic tables
|
|
83
85
|
sd_tables = []
|
|
84
86
|
for g_table in generator.tables:
|
|
85
|
-
|
|
86
|
-
sd_table = SyntheticTable(**next(t for t in config.tables if t.name == g_table.name).model_dump())
|
|
87
|
-
else:
|
|
88
|
-
sd_table = SyntheticTable(name=g_table.name)
|
|
87
|
+
sd_table = SyntheticTable(**next(t for t in config.tables if t.name == g_table.name).model_dump())
|
|
89
88
|
sd_table.foreign_keys = g_table.foreign_keys
|
|
90
89
|
sd_table.source_table_total_rows = g_table.total_rows
|
|
91
|
-
if sd_table.configuration is None:
|
|
92
|
-
sd_table.configuration = SyntheticTableConfiguration()
|
|
93
|
-
is_subject = not any(fk.is_context for fk in g_table.foreign_keys or [])
|
|
94
|
-
if is_subject and sd_table.configuration.sample_size is None:
|
|
95
|
-
if isinstance(size, int):
|
|
96
|
-
sd_table.configuration.sample_size = size
|
|
97
|
-
else: # isinstance(size, dict)
|
|
98
|
-
default_sample_size = 1 if isinstance(config, SyntheticProbeConfig) else g_table.total_rows
|
|
99
|
-
sd_table.configuration.sample_size = size.get(g_table.name, default_sample_size)
|
|
100
|
-
elif not is_subject:
|
|
101
|
-
sd_table.configuration.sample_size = None # sample size is not applicable to linked tables
|
|
102
90
|
sd_table.tabular_model_metrics = g_table.tabular_model_metrics
|
|
103
91
|
sd_table.language_model_metrics = g_table.language_model_metrics
|
|
92
|
+
# overwrite sample size of subject table, if provided
|
|
93
|
+
is_subject = not any(fk.is_context for fk in g_table.foreign_keys or [])
|
|
94
|
+
if is_subject and sample_size is not None:
|
|
95
|
+
sd_table.configuration.sample_size = sample_size
|
|
104
96
|
sd_tables.append(sd_table)
|
|
105
97
|
|
|
106
98
|
# create synthetic dataset
|
|
@@ -161,3 +153,19 @@ def create_synthetic_dataset(
|
|
|
161
153
|
)
|
|
162
154
|
write_job_progress_to_json(synthetic_dataset_dir, job_progress)
|
|
163
155
|
return synthetic_dataset
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def get_synthetic_dataset_config(home_dir: Path, synthetic_dataset_id: str) -> SyntheticDatasetConfig:
|
|
159
|
+
synthetic_dataset_dir = home_dir / "synthetic-datasets" / synthetic_dataset_id
|
|
160
|
+
synthetic_dataset = read_synthetic_dataset_from_json(synthetic_dataset_dir)
|
|
161
|
+
# construct SyntheticDatasetConfig explicitly to avoid validation warnings of extra fields
|
|
162
|
+
config = SyntheticDatasetConfig(
|
|
163
|
+
generator_id=synthetic_dataset.generator_id,
|
|
164
|
+
name=synthetic_dataset.name,
|
|
165
|
+
description=synthetic_dataset.description,
|
|
166
|
+
tables=[SyntheticTableConfig.model_construct(**t.model_dump()) for t in synthetic_dataset.tables]
|
|
167
|
+
if synthetic_dataset.tables
|
|
168
|
+
else None,
|
|
169
|
+
delivery=synthetic_dataset.delivery,
|
|
170
|
+
)
|
|
171
|
+
return config
|
|
@@ -175,7 +175,9 @@ def harmonize_sd_config(
|
|
|
175
175
|
size = size if size is not None else {}
|
|
176
176
|
seed = seed if seed is not None else {}
|
|
177
177
|
|
|
178
|
-
if isinstance(generator,
|
|
178
|
+
if isinstance(generator, GeneratorListItem):
|
|
179
|
+
generator = get_generator(generator.id)
|
|
180
|
+
if isinstance(generator, Generator):
|
|
179
181
|
generator_id = str(generator.id)
|
|
180
182
|
elif generator is not None:
|
|
181
183
|
generator_id = str(generator)
|
|
@@ -104,6 +104,11 @@ class MostlyAI(_MostlyBaseClient):
|
|
|
104
104
|
ssl_verify: bool = True,
|
|
105
105
|
quiet: bool = False,
|
|
106
106
|
):
|
|
107
|
+
import warnings
|
|
108
|
+
|
|
109
|
+
# suppress deprecation warnings, also those stemming from external libs
|
|
110
|
+
warnings.filterwarnings("ignore", category=DeprecationWarning)
|
|
111
|
+
|
|
107
112
|
if quiet:
|
|
108
113
|
rich.get_console().quiet = True
|
|
109
114
|
if local:
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
import enum
|
|
15
|
+
import logging
|
|
15
16
|
import os
|
|
16
17
|
import sys
|
|
17
18
|
import warnings
|
|
@@ -27,7 +28,7 @@ from typing import (
|
|
|
27
28
|
|
|
28
29
|
import httpx
|
|
29
30
|
import rich
|
|
30
|
-
from pydantic import BaseModel, ConfigDict, Field
|
|
31
|
+
from pydantic import BaseModel, ConfigDict, Field, model_validator
|
|
31
32
|
from rich.console import Console
|
|
32
33
|
|
|
33
34
|
from mostlyai.sdk.client.exceptions import APIError, APIStatusError
|
|
@@ -36,6 +37,8 @@ from mostlyai.sdk.client._naming_conventions import (
|
|
|
36
37
|
map_camel_to_snake_case,
|
|
37
38
|
)
|
|
38
39
|
|
|
40
|
+
_LOG = logging.getLogger(__name__)
|
|
41
|
+
|
|
39
42
|
GET = "GET"
|
|
40
43
|
POST = "POST"
|
|
41
44
|
PATCH = "PATCH"
|
|
@@ -218,7 +221,7 @@ class Paginator(Generic[T]):
|
|
|
218
221
|
item = self.page_items[self.index_in_page]
|
|
219
222
|
self.index_in_page += 1
|
|
220
223
|
self.index += 1
|
|
221
|
-
return self.response_class(**item, client=self.client
|
|
224
|
+
return self.response_class(**item, client=self.client)
|
|
222
225
|
|
|
223
226
|
def _fetch_page(self):
|
|
224
227
|
if self.is_last_page:
|
|
@@ -242,6 +245,14 @@ class CustomBaseModel(BaseModel):
|
|
|
242
245
|
extra_key_values: Annotated[dict | None, Field(exclude=True, repr=False)] = None
|
|
243
246
|
model_config = ConfigDict(protected_namespaces=(), populate_by_name=True)
|
|
244
247
|
|
|
248
|
+
@model_validator(mode="before")
|
|
249
|
+
def __warn_extra_fields__(cls, values):
|
|
250
|
+
if isinstance(values, dict):
|
|
251
|
+
extra_fields = values.keys() - cls.model_fields.keys() - {v.alias for v in cls.model_fields.values()}
|
|
252
|
+
if extra_fields:
|
|
253
|
+
_LOG.warning(f"ignoring unrecognized fields for {cls.__name__}: {', '.join(extra_fields)}")
|
|
254
|
+
return values
|
|
255
|
+
|
|
245
256
|
def _repr_html_(self):
|
|
246
257
|
# Use rich.print to create a rich representation of the model
|
|
247
258
|
console = Console()
|