mostlyai 0.6.2__tar.gz → 4.0.0__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.0/.gitignore +8 -0
- mostlyai-4.0.0/PKG-INFO +213 -0
- mostlyai-4.0.0/README.md +119 -0
- {mostlyai-0.6.2/mostlyai → mostlyai-4.0.0/mostlyai/sdk}/__init__.py +3 -3
- mostlyai-4.0.0/mostlyai/sdk/_data/__init__.py +18 -0
- mostlyai-4.0.0/mostlyai/sdk/_data/auto_detect.py +99 -0
- mostlyai-4.0.0/mostlyai/sdk/_data/base.py +700 -0
- mostlyai-4.0.0/mostlyai/sdk/_data/context.py +267 -0
- mostlyai-4.0.0/mostlyai/sdk/_data/conversions.py +89 -0
- {mostlyai-0.6.2/mostlyai/client → mostlyai-4.0.0/mostlyai/sdk/_data/db}/__init__.py +1 -2
- mostlyai-4.0.0/mostlyai/sdk/_data/db/base.py +1343 -0
- mostlyai-4.0.0/mostlyai/sdk/_data/db/bigquery.py +234 -0
- mostlyai-4.0.0/mostlyai/sdk/_data/db/databricks.py +388 -0
- mostlyai-4.0.0/mostlyai/sdk/_data/db/hive.py +206 -0
- mostlyai-4.0.0/mostlyai/sdk/_data/db/mssql.py +133 -0
- mostlyai-4.0.0/mostlyai/sdk/_data/db/mysql.py +113 -0
- mostlyai-4.0.0/mostlyai/sdk/_data/db/oracle.py +194 -0
- mostlyai-4.0.0/mostlyai/sdk/_data/db/postgresql.py +109 -0
- mostlyai-4.0.0/mostlyai/sdk/_data/db/snowflake.py +109 -0
- mostlyai-4.0.0/mostlyai/sdk/_data/db/sqlite.py +60 -0
- mostlyai-4.0.0/mostlyai/sdk/_data/db/types_coercion.py +95 -0
- mostlyai-4.0.0/mostlyai/sdk/_data/dtype.py +587 -0
- mostlyai-4.0.0/mostlyai/sdk/_data/exceptions.py +17 -0
- mostlyai-4.0.0/mostlyai/sdk/_data/file/__init__.py +13 -0
- mostlyai-4.0.0/mostlyai/sdk/_data/file/base.py +525 -0
- mostlyai-4.0.0/mostlyai/sdk/_data/file/container/__init__.py +13 -0
- mostlyai-4.0.0/mostlyai/sdk/_data/file/container/aws.py +149 -0
- mostlyai-4.0.0/mostlyai/sdk/_data/file/container/azure.py +127 -0
- mostlyai-4.0.0/mostlyai/sdk/_data/file/container/bucket_based.py +129 -0
- mostlyai-4.0.0/mostlyai/sdk/_data/file/container/gcs.py +74 -0
- mostlyai-4.0.0/mostlyai/sdk/_data/file/container/minio.py +19 -0
- mostlyai-4.0.0/mostlyai/sdk/_data/file/table/__init__.py +13 -0
- mostlyai-4.0.0/mostlyai/sdk/_data/file/table/csv.py +119 -0
- mostlyai-4.0.0/mostlyai/sdk/_data/file/table/feather.py +39 -0
- mostlyai-4.0.0/mostlyai/sdk/_data/file/table/json.py +138 -0
- mostlyai-4.0.0/mostlyai/sdk/_data/file/table/parquet.py +56 -0
- mostlyai-4.0.0/mostlyai/sdk/_data/file/utils.py +84 -0
- mostlyai-4.0.0/mostlyai/sdk/_data/language_model.py +95 -0
- mostlyai-4.0.0/mostlyai/sdk/_data/metadata_objects.py +194 -0
- mostlyai-4.0.0/mostlyai/sdk/_data/non_context.py +138 -0
- mostlyai-4.0.0/mostlyai/sdk/_data/progress_callback.py +71 -0
- mostlyai-4.0.0/mostlyai/sdk/_data/pull.py +103 -0
- mostlyai-4.0.0/mostlyai/sdk/_data/pull_context.py +66 -0
- mostlyai-4.0.0/mostlyai/sdk/_data/pull_utils.py +1051 -0
- mostlyai-4.0.0/mostlyai/sdk/_data/push.py +129 -0
- mostlyai-4.0.0/mostlyai/sdk/_data/util/__init__.py +13 -0
- mostlyai-4.0.0/mostlyai/sdk/_data/util/common.py +199 -0
- mostlyai-4.0.0/mostlyai/sdk/_data/util/kerberos.py +71 -0
- mostlyai-4.0.0/mostlyai/sdk/_local/__init__.py +13 -0
- mostlyai-4.0.0/mostlyai/sdk/_local/cli.py +45 -0
- mostlyai-4.0.0/mostlyai/sdk/_local/connectors.py +50 -0
- mostlyai-4.0.0/mostlyai/sdk/_local/execution/__init__.py +13 -0
- mostlyai-4.0.0/mostlyai/sdk/_local/execution/jobs.py +636 -0
- mostlyai-4.0.0/mostlyai/sdk/_local/execution/plan.py +140 -0
- mostlyai-4.0.0/mostlyai/sdk/_local/execution/step_analyze_training_data.py +117 -0
- mostlyai-4.0.0/mostlyai/sdk/_local/execution/step_create_data_report.py +41 -0
- mostlyai-4.0.0/mostlyai/sdk/_local/execution/step_create_model_report.py +308 -0
- mostlyai-4.0.0/mostlyai/sdk/_local/execution/step_deliver_data.py +78 -0
- mostlyai-4.0.0/mostlyai/sdk/_local/execution/step_encode_training_data.py +32 -0
- mostlyai-4.0.0/mostlyai/sdk/_local/execution/step_finalize_generation.py +480 -0
- mostlyai-4.0.0/mostlyai/sdk/_local/execution/step_finalize_training.py +17 -0
- mostlyai-4.0.0/mostlyai/sdk/_local/execution/step_generate_data.py +105 -0
- mostlyai-4.0.0/mostlyai/sdk/_local/execution/step_generate_model_report_data.py +115 -0
- mostlyai-4.0.0/mostlyai/sdk/_local/execution/step_pull_training_data.py +82 -0
- mostlyai-4.0.0/mostlyai/sdk/_local/execution/step_train_model.py +71 -0
- mostlyai-4.0.0/mostlyai/sdk/_local/generators.py +110 -0
- mostlyai-4.0.0/mostlyai/sdk/_local/progress.py +138 -0
- mostlyai-4.0.0/mostlyai/sdk/_local/routes.py +516 -0
- mostlyai-4.0.0/mostlyai/sdk/_local/server.py +106 -0
- mostlyai-4.0.0/mostlyai/sdk/_local/storage.py +89 -0
- mostlyai-4.0.0/mostlyai/sdk/_local/synthetic_datasets.py +156 -0
- mostlyai-4.0.0/mostlyai/sdk/client/__init__.py +13 -0
- {mostlyai-0.6.2/mostlyai → mostlyai-4.0.0/mostlyai/sdk}/client/_base_utils.py +18 -6
- {mostlyai-0.6.2/mostlyai → mostlyai-4.0.0/mostlyai/sdk}/client/_naming_conventions.py +3 -6
- mostlyai-0.6.2/mostlyai/client/_mostly_utils.py → mostlyai-4.0.0/mostlyai/sdk/client/_utils.py +26 -43
- {mostlyai-0.6.2/mostlyai → mostlyai-4.0.0/mostlyai/sdk}/client/api.py +123 -97
- {mostlyai-0.6.2/mostlyai → mostlyai-4.0.0/mostlyai/sdk}/client/base.py +57 -62
- {mostlyai-0.6.2/mostlyai → mostlyai-4.0.0/mostlyai/sdk}/client/connectors.py +37 -27
- {mostlyai-0.6.2/mostlyai → mostlyai-4.0.0/mostlyai/sdk}/client/exceptions.py +1 -1
- {mostlyai-0.6.2/mostlyai → mostlyai-4.0.0/mostlyai/sdk}/client/generators.py +69 -46
- {mostlyai-0.6.2/mostlyai → mostlyai-4.0.0/mostlyai/sdk}/client/synthetic_datasets.py +69 -45
- {mostlyai-0.6.2/mostlyai/client → mostlyai-4.0.0/mostlyai/sdk}/domain.py +1205 -772
- mostlyai-4.0.0/pyproject.toml +174 -0
- mostlyai-0.6.2/PKG-INFO +0 -115
- mostlyai-0.6.2/README.md +0 -79
- mostlyai-0.6.2/pyproject.toml +0 -65
- {mostlyai-0.6.2 → mostlyai-4.0.0}/LICENSE +0 -0
mostlyai-4.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mostlyai
|
|
3
|
+
Version: 4.0.0
|
|
4
|
+
Summary: MOSTLY AI - Python Client
|
|
5
|
+
Project-URL: Homepage, https://app.mostly.ai/
|
|
6
|
+
Project-URL: Documentation, https://mostly-ai.github.io/mostlyai/
|
|
7
|
+
Project-URL: Source, https://github.com/mostly-ai/mostlyai
|
|
8
|
+
Author-email: MOSTLY AI <dev@mostly.ai>
|
|
9
|
+
License-Expression: Apache-2.0
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Intended Audience :: Financial and Insurance Industry
|
|
14
|
+
Classifier: Intended Audience :: Healthcare Industry
|
|
15
|
+
Classifier: Intended Audience :: Information Technology
|
|
16
|
+
Classifier: Intended Audience :: Science/Research
|
|
17
|
+
Classifier: Intended Audience :: Telecommunications Industry
|
|
18
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
19
|
+
Classifier: Operating System :: OS Independent
|
|
20
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
21
|
+
Classifier: Typing :: Typed
|
|
22
|
+
Requires-Python: <3.13,>=3.10
|
|
23
|
+
Requires-Dist: adlfs<2024,>=2023.4.0
|
|
24
|
+
Requires-Dist: azure-storage-blob<13,>=12.16.0
|
|
25
|
+
Requires-Dist: cloudpathlib[azure,gs,s3]<0.18,>=0.17.0
|
|
26
|
+
Requires-Dist: cryptography<44,>=43.0.1
|
|
27
|
+
Requires-Dist: environs<10,>=9.5.0
|
|
28
|
+
Requires-Dist: fastparquet<2024,>=2023.4.0
|
|
29
|
+
Requires-Dist: gcsfs<2024,>=2023.1.0
|
|
30
|
+
Requires-Dist: gputil<2,>=1.4.0
|
|
31
|
+
Requires-Dist: greenlet<4,>=3.1.1
|
|
32
|
+
Requires-Dist: gunicorn<24,>=23.0.0
|
|
33
|
+
Requires-Dist: httpx<0.28.0,>=0.25.0
|
|
34
|
+
Requires-Dist: joblib<2,>=1.2.0
|
|
35
|
+
Requires-Dist: networkx~=3.1
|
|
36
|
+
Requires-Dist: openpyxl>=3.1.5
|
|
37
|
+
Requires-Dist: pandas<3,>=1.5.3
|
|
38
|
+
Requires-Dist: psutil<6,>=5.9.5
|
|
39
|
+
Requires-Dist: pyarrow>=16.0.0
|
|
40
|
+
Requires-Dist: pycryptodomex<4,>=3.20.0
|
|
41
|
+
Requires-Dist: pydantic<3,>=2.4.2
|
|
42
|
+
Requires-Dist: pydot<2,>=1.4.2
|
|
43
|
+
Requires-Dist: requests<3,>=2.31.0
|
|
44
|
+
Requires-Dist: rich>=13.7.0
|
|
45
|
+
Requires-Dist: s3fs<2024,>=2023.1.0
|
|
46
|
+
Requires-Dist: schema<0.8,>=0.7.5
|
|
47
|
+
Requires-Dist: semantic-version<3,>=2.10.0
|
|
48
|
+
Requires-Dist: smart-open>=6.0.0
|
|
49
|
+
Requires-Dist: smart-open[azure,gcs,s3]<7,>=6.3.0
|
|
50
|
+
Requires-Dist: sqlalchemy<3,>=2.0.0
|
|
51
|
+
Requires-Dist: sshtunnel<0.5,>=0.4.0
|
|
52
|
+
Requires-Dist: typer<0.10,>=0.9.0
|
|
53
|
+
Requires-Dist: xlsxwriter<4,>=3.1.9
|
|
54
|
+
Requires-Dist: xxhash<4,>=3.2.0
|
|
55
|
+
Provides-Extra: databricks
|
|
56
|
+
Requires-Dist: databricks-sql-connector<4,>=3.2.0; extra == 'databricks'
|
|
57
|
+
Provides-Extra: googlebigquery
|
|
58
|
+
Requires-Dist: sqlalchemy-bigquery<2,>=1.6.1; extra == 'googlebigquery'
|
|
59
|
+
Provides-Extra: hive
|
|
60
|
+
Requires-Dist: impyla<0.20,>=0.19.0; extra == 'hive'
|
|
61
|
+
Requires-Dist: kerberos<2,>=1.3.1; extra == 'hive'
|
|
62
|
+
Requires-Dist: pyhive[hive-pure-sasl]<0.8,>=0.7.0; extra == 'hive'
|
|
63
|
+
Provides-Extra: local
|
|
64
|
+
Requires-Dist: fastapi<0.116,>=0.115.6; extra == 'local'
|
|
65
|
+
Requires-Dist: mostlyai-engine==1.0.1; extra == 'local'
|
|
66
|
+
Requires-Dist: mostlyai-qa==1.5.0; extra == 'local'
|
|
67
|
+
Requires-Dist: python-multipart>=0.0.20; extra == 'local'
|
|
68
|
+
Requires-Dist: uvicorn<0.35,>=0.34.0; extra == 'local'
|
|
69
|
+
Provides-Extra: local-cpu
|
|
70
|
+
Requires-Dist: fastapi<0.116,>=0.115.6; extra == 'local-cpu'
|
|
71
|
+
Requires-Dist: mostlyai-engine[cpu]==1.0.1; extra == 'local-cpu'
|
|
72
|
+
Requires-Dist: mostlyai-qa==1.5.0; extra == 'local-cpu'
|
|
73
|
+
Requires-Dist: python-multipart>=0.0.20; extra == 'local-cpu'
|
|
74
|
+
Requires-Dist: torch>=2.5.1; extra == 'local-cpu'
|
|
75
|
+
Requires-Dist: uvicorn<0.35,>=0.34.0; extra == 'local-cpu'
|
|
76
|
+
Provides-Extra: local-gpu
|
|
77
|
+
Requires-Dist: fastapi<0.116,>=0.115.6; extra == 'local-gpu'
|
|
78
|
+
Requires-Dist: mostlyai-engine[gpu]==1.0.1; extra == 'local-gpu'
|
|
79
|
+
Requires-Dist: mostlyai-qa==1.5.0; extra == 'local-gpu'
|
|
80
|
+
Requires-Dist: python-multipart>=0.0.20; extra == 'local-gpu'
|
|
81
|
+
Requires-Dist: torch>=2.5.1; extra == 'local-gpu'
|
|
82
|
+
Requires-Dist: uvicorn<0.35,>=0.34.0; extra == 'local-gpu'
|
|
83
|
+
Provides-Extra: mssql
|
|
84
|
+
Requires-Dist: pyodbc<6,>=5.1.0; extra == 'mssql'
|
|
85
|
+
Provides-Extra: mysql
|
|
86
|
+
Requires-Dist: mysql-connector-python<10,>=9.1.0; extra == 'mysql'
|
|
87
|
+
Provides-Extra: oracle
|
|
88
|
+
Requires-Dist: oracledb<3,>=2.2.1; extra == 'oracle'
|
|
89
|
+
Provides-Extra: postgres
|
|
90
|
+
Requires-Dist: psycopg2<3,>=2.9.4; extra == 'postgres'
|
|
91
|
+
Provides-Extra: snowflake
|
|
92
|
+
Requires-Dist: snowflake-sqlalchemy<2,>=1.6.1; extra == 'snowflake'
|
|
93
|
+
Description-Content-Type: text/markdown
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
# Synthetic Data SDK ✨
|
|
97
|
+
|
|
98
|
+
[](https://mostly-ai.github.io/mostlyai/) [](https://pypi.org/project/mostlyai/)   
|
|
99
|
+
|
|
100
|
+
[SDK Documentation](https://mostly-ai.github.io/mostlyai/) | [Platform Documentation](https://mostly.ai/docs) | [Usage Examples](https://mostly-ai.github.io/mostlyai/usage/)
|
|
101
|
+
|
|
102
|
+
The official SDK of [MOSTLY AI](https://app.mostly.ai/), a Python toolkit for high-fidelity, privacy-safe **Synthetic Data**.
|
|
103
|
+
|
|
104
|
+
- **Client mode** connects to a remote MOSTLY AI platform for training & generating synthetic data there.
|
|
105
|
+
- **Local mode** trains and generates synthetic data locally on your own compute resources.
|
|
106
|
+
- Generators, that were trained locally, can be easily imported to a platform for further sharing.
|
|
107
|
+
|
|
108
|
+
## Overview
|
|
109
|
+
|
|
110
|
+
The SDK allows you to programmatically create, browse and manage 3 key resources:
|
|
111
|
+
|
|
112
|
+
1. **Generators** - Train a synthetic data generator on your existing tabular or language data assets
|
|
113
|
+
2. **Synthetic Datasets** - Use a generator to create any number of synthetic samples to your needs
|
|
114
|
+
3. **Connectors** - Connect to any data source within your organization, for reading and writing data
|
|
115
|
+
|
|
116
|
+
| Intent | Primitive | Documentation |
|
|
117
|
+
|-----------------------------------------------|-----------------------------------|-------------------------------------------------------------------------------------------------------------------|
|
|
118
|
+
| Train a Generator on tabular or language data | `g = mostly.train(config)` | see [mostly.train](https://mostly-ai.github.io/mostlyai/api_client/#mostlyai.sdk.client.api.MostlyAI.train) |
|
|
119
|
+
| Generate any number of synthetic data records | `sd = mostly.generate(g, config)` | see [mostly.generate](https://mostly-ai.github.io/mostlyai/api_client/#mostlyai.sdk.client.api.MostlyAI.generate) |
|
|
120
|
+
| Live probe the generator on demand | `df = mostly.probe(g, config)` | see [mostly.probe](https://mostly-ai.github.io/mostlyai/api_client/#mostlyai.sdk.client.api.MostlyAI.probe) |
|
|
121
|
+
| Connect to any data source within your org | `c = mostly.connect(config)` | see [mostly.connect](https://mostly-ai.github.io/mostlyai/api_client/#mostlyai.sdk.client.api.MostlyAI.connect) |
|
|
122
|
+
|
|
123
|
+
## Installation
|
|
124
|
+
|
|
125
|
+
**Client mode only**
|
|
126
|
+
|
|
127
|
+
```shell
|
|
128
|
+
pip install -U mostlyai
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
**Client + Local mode**
|
|
132
|
+
|
|
133
|
+
```shell
|
|
134
|
+
pip install -U mostlyai[local-cpu] # for CPU
|
|
135
|
+
#pip install -U mostlyai[local-gpu] # for GPU
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
NOTE: installing `mostlyai[local-cpu]` on Linux requires `--extra-index-url https://download.pytorch.org/whl/cpu` to be specified.
|
|
139
|
+
|
|
140
|
+
**Optional Connectors**
|
|
141
|
+
|
|
142
|
+
Add any of the following extras for further data connectors support: `databricks`, `googlebigquery`, `hive`, `mssql`, `mysql`, `oracle`, `postgres`, `snowflake`.
|
|
143
|
+
|
|
144
|
+
E.g.
|
|
145
|
+
```shell
|
|
146
|
+
pip install -U mostlyai[local, databricks, snowflake]
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## Quick Start
|
|
150
|
+
|
|
151
|
+
For client mode, initialize with `base_url` and `api_key` obtained from your [account settings page](https://app.mostly.ai/settings/api-keys). For local mode, initialize the client simply with `local=True`.
|
|
152
|
+
|
|
153
|
+
```python
|
|
154
|
+
import pandas as pd
|
|
155
|
+
from mostlyai.sdk import MostlyAI
|
|
156
|
+
|
|
157
|
+
# 1) Initialize the SDK in local or client mode
|
|
158
|
+
mostly = MostlyAI(local=True)
|
|
159
|
+
# mostly = MostlyAI(base_url='https://app.mostly.ai', api_key='YOUR_API_KEY')
|
|
160
|
+
|
|
161
|
+
# 2) Load your original data
|
|
162
|
+
trn_df = pd.read_csv('https://github.com/mostly-ai/public-demo-data/raw/dev/census/census.csv.gz')
|
|
163
|
+
|
|
164
|
+
# 3) Train a synthetic data generator
|
|
165
|
+
g = mostly.train(name='census', data=trn_df) # shorthand syntax for 1-table config
|
|
166
|
+
|
|
167
|
+
# 4) Live probe small synthetic samples
|
|
168
|
+
df_samples = mostly.probe(g, size=10)
|
|
169
|
+
|
|
170
|
+
# 5) Generate a full synthetic dataset
|
|
171
|
+
sd = mostly.generate(g, size=100_000)
|
|
172
|
+
syn_df = sd.data()
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## Key Features
|
|
176
|
+
|
|
177
|
+
- **Broad Data Support**
|
|
178
|
+
- Mixed-type data (categorical, numerical, geospatial, text, etc.)
|
|
179
|
+
- Single-table, multi-table, and time-series
|
|
180
|
+
- **Multiple Model Types**
|
|
181
|
+
- TabularARGN for SOTA tabular performance
|
|
182
|
+
- Fine-tune HuggingFace-based language models
|
|
183
|
+
- Efficient LSTM for text synthesis from scratch
|
|
184
|
+
- **Advanced Training Options**
|
|
185
|
+
- GPU/CPU support
|
|
186
|
+
- Differential Privacy
|
|
187
|
+
- Progress Monitoring
|
|
188
|
+
- **Automated Quality Assurance**
|
|
189
|
+
- Quality metrics for fidelity and privacy
|
|
190
|
+
- In-depth HTML reports for visual analysis
|
|
191
|
+
- **Flexible Sampling**
|
|
192
|
+
- Up-sample to any data volumes
|
|
193
|
+
- Conditional generation by any columns
|
|
194
|
+
- Re-balance underrepresented segments
|
|
195
|
+
- Context-aware data imputation
|
|
196
|
+
- Statistical fairness controls
|
|
197
|
+
- Rule-adherence via temperature
|
|
198
|
+
- **Seamless Integration**
|
|
199
|
+
- Connect to external data sources (DBs, cloud storages)
|
|
200
|
+
- Fully permissive open-source license
|
|
201
|
+
|
|
202
|
+
## Citation
|
|
203
|
+
|
|
204
|
+
Please consider citing our project if you find it useful:
|
|
205
|
+
|
|
206
|
+
```bibtex
|
|
207
|
+
@software{mostlyai,
|
|
208
|
+
author = {{MOSTLY AI}},
|
|
209
|
+
title = {{MOSTLY AI SDK}},
|
|
210
|
+
url = {https://github.com/mostly-ai/mostlyai},
|
|
211
|
+
year = {2025}
|
|
212
|
+
}
|
|
213
|
+
```
|
mostlyai-4.0.0/README.md
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
|
|
2
|
+
# Synthetic Data SDK ✨
|
|
3
|
+
|
|
4
|
+
[](https://mostly-ai.github.io/mostlyai/) [](https://pypi.org/project/mostlyai/)   
|
|
5
|
+
|
|
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
|
+
|
|
8
|
+
The official SDK of [MOSTLY AI](https://app.mostly.ai/), a Python toolkit for high-fidelity, privacy-safe **Synthetic Data**.
|
|
9
|
+
|
|
10
|
+
- **Client mode** connects to a remote MOSTLY AI platform for training & generating synthetic data there.
|
|
11
|
+
- **Local mode** trains and generates synthetic data locally on your own compute resources.
|
|
12
|
+
- Generators, that were trained locally, can be easily imported to a platform for further sharing.
|
|
13
|
+
|
|
14
|
+
## Overview
|
|
15
|
+
|
|
16
|
+
The SDK allows you to programmatically create, browse and manage 3 key resources:
|
|
17
|
+
|
|
18
|
+
1. **Generators** - Train a synthetic data generator on your existing tabular or language data assets
|
|
19
|
+
2. **Synthetic Datasets** - Use a generator to create any number of synthetic samples to your needs
|
|
20
|
+
3. **Connectors** - Connect to any data source within your organization, for reading and writing data
|
|
21
|
+
|
|
22
|
+
| Intent | Primitive | Documentation |
|
|
23
|
+
|-----------------------------------------------|-----------------------------------|-------------------------------------------------------------------------------------------------------------------|
|
|
24
|
+
| Train a Generator on tabular or language data | `g = mostly.train(config)` | see [mostly.train](https://mostly-ai.github.io/mostlyai/api_client/#mostlyai.sdk.client.api.MostlyAI.train) |
|
|
25
|
+
| Generate any number of synthetic data records | `sd = mostly.generate(g, config)` | see [mostly.generate](https://mostly-ai.github.io/mostlyai/api_client/#mostlyai.sdk.client.api.MostlyAI.generate) |
|
|
26
|
+
| Live probe the generator on demand | `df = mostly.probe(g, config)` | see [mostly.probe](https://mostly-ai.github.io/mostlyai/api_client/#mostlyai.sdk.client.api.MostlyAI.probe) |
|
|
27
|
+
| Connect to any data source within your org | `c = mostly.connect(config)` | see [mostly.connect](https://mostly-ai.github.io/mostlyai/api_client/#mostlyai.sdk.client.api.MostlyAI.connect) |
|
|
28
|
+
|
|
29
|
+
## Installation
|
|
30
|
+
|
|
31
|
+
**Client mode only**
|
|
32
|
+
|
|
33
|
+
```shell
|
|
34
|
+
pip install -U mostlyai
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
**Client + Local mode**
|
|
38
|
+
|
|
39
|
+
```shell
|
|
40
|
+
pip install -U mostlyai[local-cpu] # for CPU
|
|
41
|
+
#pip install -U mostlyai[local-gpu] # for GPU
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
NOTE: installing `mostlyai[local-cpu]` on Linux requires `--extra-index-url https://download.pytorch.org/whl/cpu` to be specified.
|
|
45
|
+
|
|
46
|
+
**Optional Connectors**
|
|
47
|
+
|
|
48
|
+
Add any of the following extras for further data connectors support: `databricks`, `googlebigquery`, `hive`, `mssql`, `mysql`, `oracle`, `postgres`, `snowflake`.
|
|
49
|
+
|
|
50
|
+
E.g.
|
|
51
|
+
```shell
|
|
52
|
+
pip install -U mostlyai[local, databricks, snowflake]
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Quick Start
|
|
56
|
+
|
|
57
|
+
For client mode, initialize with `base_url` and `api_key` obtained from your [account settings page](https://app.mostly.ai/settings/api-keys). For local mode, initialize the client simply with `local=True`.
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
import pandas as pd
|
|
61
|
+
from mostlyai.sdk import MostlyAI
|
|
62
|
+
|
|
63
|
+
# 1) Initialize the SDK in local or client mode
|
|
64
|
+
mostly = MostlyAI(local=True)
|
|
65
|
+
# mostly = MostlyAI(base_url='https://app.mostly.ai', api_key='YOUR_API_KEY')
|
|
66
|
+
|
|
67
|
+
# 2) Load your original data
|
|
68
|
+
trn_df = pd.read_csv('https://github.com/mostly-ai/public-demo-data/raw/dev/census/census.csv.gz')
|
|
69
|
+
|
|
70
|
+
# 3) Train a synthetic data generator
|
|
71
|
+
g = mostly.train(name='census', data=trn_df) # shorthand syntax for 1-table config
|
|
72
|
+
|
|
73
|
+
# 4) Live probe small synthetic samples
|
|
74
|
+
df_samples = mostly.probe(g, size=10)
|
|
75
|
+
|
|
76
|
+
# 5) Generate a full synthetic dataset
|
|
77
|
+
sd = mostly.generate(g, size=100_000)
|
|
78
|
+
syn_df = sd.data()
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Key Features
|
|
82
|
+
|
|
83
|
+
- **Broad Data Support**
|
|
84
|
+
- Mixed-type data (categorical, numerical, geospatial, text, etc.)
|
|
85
|
+
- Single-table, multi-table, and time-series
|
|
86
|
+
- **Multiple Model Types**
|
|
87
|
+
- TabularARGN for SOTA tabular performance
|
|
88
|
+
- Fine-tune HuggingFace-based language models
|
|
89
|
+
- Efficient LSTM for text synthesis from scratch
|
|
90
|
+
- **Advanced Training Options**
|
|
91
|
+
- GPU/CPU support
|
|
92
|
+
- Differential Privacy
|
|
93
|
+
- Progress Monitoring
|
|
94
|
+
- **Automated Quality Assurance**
|
|
95
|
+
- Quality metrics for fidelity and privacy
|
|
96
|
+
- In-depth HTML reports for visual analysis
|
|
97
|
+
- **Flexible Sampling**
|
|
98
|
+
- Up-sample to any data volumes
|
|
99
|
+
- Conditional generation by any columns
|
|
100
|
+
- Re-balance underrepresented segments
|
|
101
|
+
- Context-aware data imputation
|
|
102
|
+
- Statistical fairness controls
|
|
103
|
+
- Rule-adherence via temperature
|
|
104
|
+
- **Seamless Integration**
|
|
105
|
+
- Connect to external data sources (DBs, cloud storages)
|
|
106
|
+
- Fully permissive open-source license
|
|
107
|
+
|
|
108
|
+
## Citation
|
|
109
|
+
|
|
110
|
+
Please consider citing our project if you find it useful:
|
|
111
|
+
|
|
112
|
+
```bibtex
|
|
113
|
+
@software{mostlyai,
|
|
114
|
+
author = {{MOSTLY AI}},
|
|
115
|
+
title = {{MOSTLY AI SDK}},
|
|
116
|
+
url = {https://github.com/mostly-ai/mostlyai},
|
|
117
|
+
year = {2025}
|
|
118
|
+
}
|
|
119
|
+
```
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Copyright 2024 MOSTLY AI
|
|
1
|
+
# Copyright 2024-2025 MOSTLY AI
|
|
2
2
|
#
|
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
4
|
# you may not use this file except in compliance with the License.
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
-
from mostlyai.client.api import MostlyAI
|
|
15
|
+
from mostlyai.sdk.client.api import MostlyAI
|
|
16
16
|
|
|
17
17
|
__all__ = ["MostlyAI"]
|
|
18
|
-
__version__ = "0.
|
|
18
|
+
__version__ = "4.0.0" # Do not set this manually. Use poetry version [params].
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Copyright 2025 MOSTLY AI
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
from mostlyai.sdk._data.pull import pull
|
|
16
|
+
from mostlyai.sdk._data.pull_context import pull_context
|
|
17
|
+
|
|
18
|
+
__all__ = ["pull", "pull_context"]
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# Copyright 2025 MOSTLY AI
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
import re
|
|
16
|
+
import logging
|
|
17
|
+
import time
|
|
18
|
+
|
|
19
|
+
import pandas as pd
|
|
20
|
+
|
|
21
|
+
from mostlyai.engine._common import safe_convert_datetime
|
|
22
|
+
from mostlyai.sdk.domain import ModelEncodingType
|
|
23
|
+
from mostlyai.sdk._data.base import DataTable
|
|
24
|
+
from mostlyai.sdk._data.dtype import VirtualDType, VirtualVarchar, VirtualInteger
|
|
25
|
+
from mostlyai.sdk._data.util.common import run_with_timeout_unsafe, absorb_errors
|
|
26
|
+
|
|
27
|
+
AUTODETECT_SAMPLE_SIZE = 10_000
|
|
28
|
+
AUTODETECT_TIMEOUT = 15
|
|
29
|
+
LAT_LONG_REGEX = re.compile(r"^\s*-?\d+(\.\d+)?,\s*-?\d+(\.\d+)?\s*$")
|
|
30
|
+
PK_POSSIBLE_VIRTUAL_DTYPES = (VirtualVarchar, VirtualInteger)
|
|
31
|
+
|
|
32
|
+
_LOG = logging.getLogger(__name__)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def auto_detect_encoding_types_and_pk(table: DataTable) -> tuple[dict, str | None]:
|
|
36
|
+
# sub-select only the columns which got the default tabular categorical encoding type
|
|
37
|
+
columns_to_auto_detect = [
|
|
38
|
+
c for c, enc in table.encoding_types.items() if enc == ModelEncodingType.tabular_categorical
|
|
39
|
+
]
|
|
40
|
+
dtypes = VirtualDType.from_dtypes(table.dtypes)
|
|
41
|
+
primary_key_candidates = [
|
|
42
|
+
c for c, t in dtypes.items() if type(t) in PK_POSSIBLE_VIRTUAL_DTYPES and c.lower().endswith("id")
|
|
43
|
+
] # sub-select primary key candidates before sampling the data
|
|
44
|
+
columns_to_sample = primary_key_candidates + [c for c in columns_to_auto_detect if c not in primary_key_candidates]
|
|
45
|
+
fallback = (
|
|
46
|
+
{c: ModelEncodingType.tabular_categorical for c in columns_to_auto_detect},
|
|
47
|
+
None,
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
def auto_detection_logic():
|
|
51
|
+
return_vals = None
|
|
52
|
+
t0 = time.time()
|
|
53
|
+
with absorb_errors():
|
|
54
|
+
data_sample = next(table.read_chunks(columns=columns_to_sample, fetch_chunk_size=AUTODETECT_SAMPLE_SIZE))
|
|
55
|
+
primary_key = auto_detect_primary_key(data_sample[primary_key_candidates])
|
|
56
|
+
remaining_columns_to_auto_detect = [c for c in columns_to_auto_detect if c != primary_key]
|
|
57
|
+
# auto-detect encoding types for the sampled data
|
|
58
|
+
return_vals = (
|
|
59
|
+
{c: auto_detect_encoding_type(data_sample[c]) for c in remaining_columns_to_auto_detect},
|
|
60
|
+
primary_key,
|
|
61
|
+
)
|
|
62
|
+
_LOG.info(f"auto_detect_encoding_types_and_pk logic for table={table.name} took {time.time() - t0:.2f} seconds")
|
|
63
|
+
return return_vals if return_vals is not None else fallback
|
|
64
|
+
|
|
65
|
+
# wrap the detection logic with timeout and fallback
|
|
66
|
+
return run_with_timeout_unsafe(
|
|
67
|
+
auto_detection_logic,
|
|
68
|
+
timeout=AUTODETECT_TIMEOUT,
|
|
69
|
+
fallback=fallback,
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def auto_detect_primary_key(sample: pd.DataFrame) -> str | None:
|
|
74
|
+
# assuming sample columns are (1) ending with "id" and (2) of PK_POSSIBLE_VIRTUAL_DTYPES dtype
|
|
75
|
+
for c in sample.columns:
|
|
76
|
+
# check (3) all values unique and non-null and (4) of max len 36 (e.g. uuid len)
|
|
77
|
+
if sample[c].is_unique and sample[c].notnull().all() and sample[c].astype(str).str.len().max() <= 36:
|
|
78
|
+
return c
|
|
79
|
+
return None
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def auto_detect_encoding_type(x: pd.Series):
|
|
83
|
+
x = x.dropna()
|
|
84
|
+
x = x.astype(str)
|
|
85
|
+
x = x[x.str.strip() != ""] # filter out empty and whitespace-only strings
|
|
86
|
+
|
|
87
|
+
# if all non-null values can be converted to datetime -> datetime encoding
|
|
88
|
+
if safe_convert_datetime(x).notna().all():
|
|
89
|
+
return ModelEncodingType.tabular_datetime
|
|
90
|
+
|
|
91
|
+
# if all values match lat/long pattern -> lat_long (geo) encoding
|
|
92
|
+
if x.str.match(LAT_LONG_REGEX).all():
|
|
93
|
+
return ModelEncodingType.tabular_lat_long
|
|
94
|
+
|
|
95
|
+
# if more than 5% of rows contain unique values -> text encoding
|
|
96
|
+
if len(x.dropna()) >= 100 and x.value_counts().eq(1).reindex(x).mean() > 0.05:
|
|
97
|
+
return ModelEncodingType.language_text
|
|
98
|
+
|
|
99
|
+
return ModelEncodingType.tabular_categorical
|