mostlyai 4.8.3__tar.gz → 4.9.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.
Files changed (87) hide show
  1. {mostlyai-4.8.3 → mostlyai-4.9.0}/PKG-INFO +1 -1
  2. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/__init__.py +1 -1
  3. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_local/routes.py +96 -0
  4. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_local/storage.py +12 -0
  5. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/client/api.py +2 -0
  6. mostlyai-4.9.0/mostlyai/sdk/client/datasets.py +236 -0
  7. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/domain.py +157 -1
  8. {mostlyai-4.8.3 → mostlyai-4.9.0}/pyproject.toml +1 -1
  9. {mostlyai-4.8.3 → mostlyai-4.9.0}/.gitignore +0 -0
  10. {mostlyai-4.8.3 → mostlyai-4.9.0}/LICENSE +0 -0
  11. {mostlyai-4.8.3 → mostlyai-4.9.0}/README.md +0 -0
  12. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_data/__init__.py +0 -0
  13. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_data/auto_detect.py +0 -0
  14. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_data/base.py +0 -0
  15. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_data/context.py +0 -0
  16. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_data/conversions.py +0 -0
  17. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_data/db/__init__.py +0 -0
  18. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_data/db/base.py +0 -0
  19. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_data/db/bigquery.py +0 -0
  20. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_data/db/databricks.py +0 -0
  21. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_data/db/hive.py +0 -0
  22. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_data/db/mssql.py +0 -0
  23. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_data/db/mysql.py +0 -0
  24. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_data/db/oracle.py +0 -0
  25. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_data/db/postgresql.py +0 -0
  26. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_data/db/snowflake.py +0 -0
  27. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_data/db/sqlite.py +0 -0
  28. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_data/db/types_coercion.py +0 -0
  29. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_data/dtype.py +0 -0
  30. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_data/exceptions.py +0 -0
  31. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_data/file/__init__.py +0 -0
  32. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_data/file/base.py +0 -0
  33. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_data/file/container/__init__.py +0 -0
  34. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_data/file/container/aws.py +0 -0
  35. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_data/file/container/azure.py +0 -0
  36. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_data/file/container/bucket_based.py +0 -0
  37. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_data/file/container/gcs.py +0 -0
  38. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_data/file/container/minio.py +0 -0
  39. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_data/file/table/__init__.py +0 -0
  40. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_data/file/table/csv.py +0 -0
  41. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_data/file/table/feather.py +0 -0
  42. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_data/file/table/json.py +0 -0
  43. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_data/file/table/parquet.py +0 -0
  44. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_data/file/utils.py +0 -0
  45. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_data/language_model.py +0 -0
  46. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_data/metadata_objects.py +0 -0
  47. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_data/non_context.py +0 -0
  48. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_data/progress_callback.py +0 -0
  49. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_data/pull.py +0 -0
  50. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_data/pull_context.py +0 -0
  51. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_data/pull_utils.py +0 -0
  52. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_data/push.py +0 -0
  53. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_data/util/__init__.py +0 -0
  54. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_data/util/common.py +0 -0
  55. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_data/util/kerberos.py +0 -0
  56. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_local/__init__.py +0 -0
  57. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_local/cli.py +0 -0
  58. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_local/connectors.py +0 -0
  59. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_local/execution/__init__.py +0 -0
  60. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_local/execution/jobs.py +0 -0
  61. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_local/execution/migration.py +0 -0
  62. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_local/execution/plan.py +0 -0
  63. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_local/execution/step_analyze_training_data.py +0 -0
  64. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_local/execution/step_create_data_report.py +0 -0
  65. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_local/execution/step_create_model_report.py +0 -0
  66. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_local/execution/step_deliver_data.py +0 -0
  67. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_local/execution/step_encode_training_data.py +0 -0
  68. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_local/execution/step_finalize_generation.py +0 -0
  69. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_local/execution/step_finalize_training.py +0 -0
  70. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_local/execution/step_generate_data.py +0 -0
  71. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_local/execution/step_generate_model_report_data.py +0 -0
  72. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_local/execution/step_pull_training_data.py +0 -0
  73. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_local/execution/step_train_model.py +0 -0
  74. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_local/generators.py +0 -0
  75. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_local/progress.py +0 -0
  76. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_local/server.py +0 -0
  77. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/_local/synthetic_datasets.py +0 -0
  78. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/client/__init__.py +0 -0
  79. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/client/_base_utils.py +0 -0
  80. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/client/_naming_conventions.py +0 -0
  81. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/client/_utils.py +0 -0
  82. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/client/base.py +0 -0
  83. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/client/connectors.py +0 -0
  84. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/client/exceptions.py +0 -0
  85. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/client/generators.py +0 -0
  86. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/client/synthetic_datasets.py +0 -0
  87. {mostlyai-4.8.3 → mostlyai-4.9.0}/mostlyai/sdk/py.typed +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mostlyai
3
- Version: 4.8.3
3
+ Version: 4.9.0
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
@@ -15,4 +15,4 @@
15
15
  from mostlyai.sdk.client.api import MostlyAI
16
16
 
17
17
  __all__ = ["MostlyAI"]
18
- __version__ = "4.8.3" # Do not set this manually. Use poetry version [params].
18
+ __version__ = "4.9.0" # Do not set this manually. Use poetry version [params].
@@ -37,10 +37,12 @@ from mostlyai.sdk._local.storage import (
37
37
  create_zip_in_memory,
38
38
  get_model_label,
39
39
  read_connector_from_json,
40
+ read_dataset_from_json,
40
41
  read_generator_from_json,
41
42
  read_job_progress_from_json,
42
43
  read_synthetic_dataset_from_json,
43
44
  write_connector_to_json,
45
+ write_dataset_to_json,
44
46
  write_generator_to_json,
45
47
  write_synthetic_dataset_to_json,
46
48
  )
@@ -56,6 +58,10 @@ from mostlyai.sdk.domain import (
56
58
  ConnectorType,
57
59
  ConnectorWriteDataConfig,
58
60
  CurrentUser,
61
+ Dataset,
62
+ DatasetConfig,
63
+ DatasetListItem,
64
+ DatasetPatchConfig,
59
65
  Generator,
60
66
  GeneratorCloneConfig,
61
67
  GeneratorCloneTrainingStatus,
@@ -289,6 +295,96 @@ class Routes:
289
295
  background=BackgroundTask(Path(tmp_path).unlink, missing_ok=True),
290
296
  )
291
297
 
298
+ ## DATASETS
299
+
300
+ @self.router.get("/datasets")
301
+ async def list_datasets(
302
+ offset: int = 0,
303
+ limit: int = 50,
304
+ searchTerm: str | None = None,
305
+ ) -> JSONResponse:
306
+ dataset_dirs = [p for p in (self.home_dir / "datasets").glob("*") if p.is_dir()]
307
+ dataset_list_items = []
308
+ for dataset_dir in dataset_dirs:
309
+ dataset = read_dataset_from_json(dataset_dir)
310
+ dataset_string = " ".join([dataset.name or "", dataset.description or ""]).lower()
311
+ if searchTerm and searchTerm.lower() not in dataset_string:
312
+ continue
313
+ # use model_construct to skip validation and warnings of extra fields
314
+ dataset_list_items.append(DatasetListItem.model_construct(**dataset.model_dump()))
315
+
316
+ return JSONResponse(
317
+ status_code=200,
318
+ content=jsonable_encoder(
319
+ {
320
+ "totalCount": len(dataset_list_items),
321
+ "results": dataset_list_items[int(offset) : int(offset) + int(limit)],
322
+ }
323
+ ),
324
+ )
325
+
326
+ @self.router.post("/datasets", response_model=Dataset)
327
+ async def create_dataset(config: DatasetConfig = Body(...)) -> Dataset:
328
+ dataset = Dataset(**config.model_dump())
329
+ dataset_dir = self.home_dir / "datasets" / dataset.id
330
+ write_dataset_to_json(dataset_dir, dataset)
331
+ return dataset
332
+
333
+ @self.router.get("/datasets/{id}", response_model=Dataset)
334
+ async def get_dataset(id: str) -> Dataset:
335
+ dataset_dir = self.home_dir / "datasets" / id
336
+ if not dataset_dir.exists():
337
+ raise HTTPException(status_code=404, detail=f"Dataset `{id}` not found")
338
+ dataset = read_dataset_from_json(dataset_dir)
339
+ return dataset
340
+
341
+ @self.router.patch("/datasets/{id}", response_model=Dataset)
342
+ async def patch_dataset(id: str, config: DatasetPatchConfig = Body(...)) -> Dataset:
343
+ dataset_dir = self.home_dir / "datasets" / id
344
+ dataset = read_dataset_from_json(dataset_dir)
345
+ for key, value in config.model_dump().items():
346
+ if value is not None:
347
+ setattr(dataset, key, value)
348
+ write_dataset_to_json(dataset_dir, dataset)
349
+ return dataset
350
+
351
+ @self.router.delete("/datasets/{id}")
352
+ async def delete_dataset(id: str):
353
+ dataset_dir = self.home_dir / "datasets" / id
354
+ shutil.rmtree(dataset_dir, ignore_errors=True)
355
+
356
+ @self.router.get("/datasets/{id}/file")
357
+ async def download_dataset_file(id: str, filepath: str) -> FileResponse:
358
+ dataset_dir = self.home_dir / "datasets" / id
359
+ filename = Path(filepath).name
360
+ return StreamingResponse(
361
+ open(dataset_dir / filepath, "rb"),
362
+ media_type="application/octet-stream",
363
+ headers={"Content-Disposition": f"attachment; filename={filename}"},
364
+ )
365
+
366
+ @self.router.post("/datasets/{id}/file")
367
+ async def upload_dataset_file(id: str, file: UploadFile = File(...)) -> None:
368
+ dataset_dir = self.home_dir / "datasets" / id
369
+ dataset = read_dataset_from_json(dataset_dir)
370
+ try:
371
+ file_content = await file.read()
372
+ with open(dataset_dir / file.filename, "wb") as f:
373
+ f.write(file_content)
374
+ dataset.files.append(file.filename)
375
+ write_dataset_to_json(dataset_dir, dataset)
376
+ except Exception as e:
377
+ raise HTTPException(status_code=500, detail=f"Error uploading file `{file.filename}`: {e}")
378
+
379
+ @self.router.delete("/datasets/{id}/file")
380
+ async def delete_dataset_file(id: str, filepath: str) -> None:
381
+ dataset_dir = self.home_dir / "datasets" / id
382
+ dataset = read_dataset_from_json(dataset_dir)
383
+ if os.path.exists(dataset_dir / filepath):
384
+ os.remove(dataset_dir / filepath)
385
+ dataset.files = [f for f in dataset.files if f != filepath]
386
+ write_dataset_to_json(dataset_dir, dataset)
387
+
292
388
  ## GENERATORS
293
389
 
294
390
  @self.router.get("/generators")
@@ -23,6 +23,7 @@ from pydantic import BaseModel
23
23
 
24
24
  from mostlyai.sdk.domain import (
25
25
  Connector,
26
+ Dataset,
26
27
  Generator,
27
28
  JobProgress,
28
29
  ModelType,
@@ -82,6 +83,17 @@ def write_connector_to_json(connector_dir: Path, connector: Connector) -> None:
82
83
  write_to_json(json_file, connector)
83
84
 
84
85
 
86
+ def read_dataset_from_json(dataset_dir: Path) -> Dataset:
87
+ json_file = dataset_dir / "dataset.json"
88
+ return Dataset(**json.loads(json_file.read_text()))
89
+
90
+
91
+ def write_dataset_to_json(dataset_dir: Path, dataset: Dataset) -> None:
92
+ json_file = dataset_dir / "dataset.json"
93
+ dataset_dir.mkdir(parents=True, exist_ok=True)
94
+ write_to_json(json_file, dataset)
95
+
96
+
85
97
  def read_job_progress_from_json(resource_dir: Path) -> JobProgress:
86
98
  progress_file = resource_dir / "job_progress.json"
87
99
  lock_file = progress_file.with_suffix(".lock")
@@ -30,6 +30,7 @@ from mostlyai.sdk.client._utils import (
30
30
  )
31
31
  from mostlyai.sdk.client.base import DEFAULT_BASE_URL, GET, _MostlyBaseClient
32
32
  from mostlyai.sdk.client.connectors import _MostlyConnectorsClient
33
+ from mostlyai.sdk.client.datasets import _MostlyDatasetsClient
33
34
  from mostlyai.sdk.client.exceptions import APIError
34
35
  from mostlyai.sdk.client.generators import _MostlyGeneratorsClient
35
36
  from mostlyai.sdk.client.synthetic_datasets import (
@@ -218,6 +219,7 @@ class MostlyAI(_MostlyBaseClient):
218
219
  super().__init__(**client_kwargs)
219
220
  self.connectors = _MostlyConnectorsClient(**client_kwargs)
220
221
  self.generators = _MostlyGeneratorsClient(**client_kwargs)
222
+ self.datasets = _MostlyDatasetsClient(**client_kwargs)
221
223
  self.synthetic_datasets = _MostlySyntheticDatasetsClient(**client_kwargs)
222
224
  self.synthetic_probes = _MostlySyntheticProbesClient(**client_kwargs)
223
225
  if mode == "LOCAL":
@@ -0,0 +1,236 @@
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
+ from collections.abc import Iterator
17
+ from pathlib import Path
18
+ from typing import Any
19
+
20
+ import rich
21
+
22
+ from mostlyai.sdk.client.base import (
23
+ DELETE,
24
+ GET,
25
+ PATCH,
26
+ POST,
27
+ Paginator,
28
+ _MostlyBaseClient,
29
+ )
30
+ from mostlyai.sdk.domain import (
31
+ Dataset,
32
+ DatasetConfig,
33
+ DatasetListItem,
34
+ DatasetPatchConfig,
35
+ )
36
+
37
+
38
+ class _MostlyDatasetsClient(_MostlyBaseClient):
39
+ SECTION = ["datasets"]
40
+
41
+ # PUBLIC METHODS #
42
+
43
+ def list(
44
+ self,
45
+ offset: int = 0,
46
+ limit: int | None = None,
47
+ search_term: str | None = None,
48
+ owner_id: str | list[str] | None = None,
49
+ visibility: str | list[str] | None = None,
50
+ created_from: str | None = None,
51
+ created_to: str | None = None,
52
+ sort_by: str | list[str] | None = None,
53
+ ) -> Iterator[DatasetListItem]:
54
+ """
55
+ List datasets.
56
+
57
+ Args:
58
+ offset: Offset for the entities in the response.
59
+ limit: Limit for the number of entities in the response.
60
+ status: Filter by generation status.
61
+ search_term: Filter by name or description.
62
+ owner_id: Filter by owner ID.
63
+ visibility: Filter by visibility (e.g., PUBLIC, PRIVATE or UNLISTED).
64
+ created_from: Filter by creation date, not older than this date. Format: YYYY-MM-DD.
65
+ created_to: Filter by creation date, not younger than this date. Format: YYYY-MM-DD.
66
+ sort_by: Sort by field. Either RECENCY, NO_OF_LIKES.
67
+
68
+ Returns:
69
+ An iterator over datasets.
70
+
71
+ Example for listing all datasets:
72
+ ```python
73
+ from mostlyai.sdk import MostlyAI
74
+ mostly = MostlyAI()
75
+ for ds in mostly.datasets.list():
76
+ print(f"Dataset `{ds.name}` ({ds.id})")
77
+ ```
78
+
79
+ Example for searching datasets via key word:
80
+ ```python
81
+ from mostlyai.sdk import MostlyAI
82
+ mostly = MostlyAI()
83
+ datasets = list(mostly.datasets.list(search_term="census"))
84
+ print(f"Found {len(datasets)} datasets")
85
+ """
86
+ with Paginator(
87
+ self,
88
+ DatasetListItem,
89
+ offset=offset,
90
+ limit=limit,
91
+ search_term=search_term,
92
+ owner_id=owner_id,
93
+ visibility=visibility,
94
+ created_from=created_from,
95
+ created_to=created_to,
96
+ sort_by=sort_by,
97
+ ) as paginator:
98
+ yield from paginator
99
+
100
+ def get(self, dataset_id: str) -> Dataset:
101
+ """
102
+ Retrieve a dataset by its ID.
103
+
104
+ Args:
105
+ dataset_id: The unique identifier of the dataset.
106
+
107
+ Returns:
108
+ Dataset: The retrieved dataset object.
109
+
110
+ Example for retrieving a dataset:
111
+ ```python
112
+ from mostlyai.sdk import MostlyAI
113
+ mostly = MostlyAI()
114
+ ds = mostly.datasets.get('INSERT_YOUR_DATASET_ID')
115
+ ds
116
+ ```
117
+ """
118
+ if not isinstance(dataset_id, str) or len(dataset_id) != 36:
119
+ raise ValueError("The provided dataset_id must be a UUID string")
120
+ response = self.request(verb=GET, path=[dataset_id], response_type=Dataset)
121
+ return response
122
+
123
+ def create(self, config: DatasetConfig | dict[str, Any]) -> Dataset:
124
+ """
125
+ Create a dataset.
126
+
127
+ Args:
128
+ config: Configuration for the dataset.
129
+
130
+ Returns:
131
+ The created dataset object.
132
+
133
+ Example for creating a dataset:
134
+ ```python
135
+ from mostlyai.sdk import MostlyAI
136
+ mostly = MostlyAI()
137
+ ds = mostly.datasets.create(
138
+ config=DatasetConfig(
139
+ name="INSERT_YOUR_DATASET_NAME",
140
+ description="INSERT_YOUR_DATASET_DESCRIPTION",
141
+ connectors=[
142
+ DatasetConnector(
143
+ connector_id="INSERT_YOUR_CONNECTOR_ID",
144
+ location="INSERT_YOUR_LOCATION",
145
+ )
146
+ ],
147
+ )
148
+ )
149
+ ```
150
+ """
151
+ dataset = self.request(
152
+ verb=POST,
153
+ path=[],
154
+ json=config,
155
+ response_type=Dataset,
156
+ )
157
+ dsid = dataset.id
158
+ if self.local:
159
+ rich.print(f"Created dataset [dodger_blue2]{dsid}[/]")
160
+ else:
161
+ rich.print(f"Created dataset [link={self.base_url}/d/datasets/{dsid} dodger_blue2 underline]{dsid}[/]")
162
+ return dataset
163
+
164
+ def _update(
165
+ self,
166
+ dataset_id: str,
167
+ config: DatasetPatchConfig | dict[str, Any],
168
+ ) -> Dataset:
169
+ response = self.request(
170
+ verb=PATCH,
171
+ path=[dataset_id],
172
+ json=config,
173
+ response_type=Dataset,
174
+ )
175
+ return response
176
+
177
+ def _delete(self, dataset_id: str) -> None:
178
+ response = self.request(verb=DELETE, path=[dataset_id])
179
+ return response
180
+
181
+ def _config(self, dataset_id: str) -> DatasetConfig:
182
+ response = self.request(verb=GET, path=[dataset_id, "config"], response_type=DatasetConfig)
183
+ return response
184
+
185
+ def _download_file(
186
+ self,
187
+ dataset_id: str,
188
+ file_path: str,
189
+ ) -> tuple[bytes, str | None]:
190
+ response = self.request(
191
+ verb=GET,
192
+ path=[dataset_id, "file"],
193
+ params={"filepath": file_path},
194
+ headers={
195
+ "Accept": "application/json, text/plain, */*",
196
+ },
197
+ raw_response=True,
198
+ )
199
+ content_bytes = response.content
200
+ # Check if 'Content-Disposition' header is present
201
+ if "Content-Disposition" in response.headers:
202
+ content_disposition = response.headers["Content-Disposition"]
203
+ filename = re.findall(r"filename(?:=|\*=UTF-8'')(.+)", content_disposition)[0]
204
+ else:
205
+ filename = Path(file_path).name
206
+ return content_bytes, filename
207
+
208
+ def _upload_file(
209
+ self,
210
+ dataset_id: str,
211
+ file_path: str | Path,
212
+ ) -> None:
213
+ with open(file_path, "rb") as f:
214
+ _ = self.request(
215
+ verb=POST,
216
+ path=[dataset_id, "file"],
217
+ headers={
218
+ "Accept": "application/json, text/plain, */*",
219
+ },
220
+ files={"file": f},
221
+ )
222
+ rich.print(f"Uploaded file `{file_path}` to Dataset [dodger_blue2]{dataset_id}[/]")
223
+
224
+ def _delete_file(
225
+ self,
226
+ dataset_id: str,
227
+ file_path: str | Path,
228
+ ) -> None:
229
+ _ = self.request(
230
+ verb=DELETE,
231
+ path=[dataset_id, "file"],
232
+ params={
233
+ "filepath": file_path,
234
+ },
235
+ )
236
+ rich.print(f"Deleted file `{file_path}` from Dataset [dodger_blue2]{dataset_id}[/]")
@@ -13,7 +13,7 @@
13
13
  # limitations under the License.
14
14
 
15
15
  # generated by datamodel-codegen:
16
- # timestamp: 2025-06-26T08:04:20+00:00
16
+ # timestamp: 2025-07-10T14:44:02+00:00
17
17
 
18
18
  from __future__ import annotations
19
19
 
@@ -175,6 +175,19 @@ class PaginatedTotalCount(RootModel[int]):
175
175
  root: int = Field(..., description="The total number of entities within the list")
176
176
 
177
177
 
178
+ class DatasetUsage(CustomBaseModel):
179
+ """
180
+ Usage statistics of a dataset.
181
+ """
182
+
183
+ no_of_likes: int | None = Field(None, alias="noOfLikes", description="Number of likes of this dataset.")
184
+
185
+
186
+ class DatasetSortField(str, Enum):
187
+ recency = "RECENCY"
188
+ no_of_likes = "NO_OF_LIKES"
189
+
190
+
178
191
  class ConnectorAccessType(str, Enum):
179
192
  """
180
193
  The access permissions of a connector.
@@ -889,6 +902,7 @@ class AssistantMessageContentType(str, Enum):
889
902
  artifact_generator = "artifact/generator"
890
903
  artifact_synthetic_dataset = "artifact/synthetic-dataset"
891
904
  artifact_connector = "artifact/connector"
905
+ artifact_dataset = "artifact/dataset"
892
906
 
893
907
 
894
908
  class AssistantMessageDeltaContentType(str, Enum):
@@ -1794,6 +1808,148 @@ class Metadata(CustomBaseModel):
1794
1808
  )
1795
1809
 
1796
1810
 
1811
+ class DatasetConnector(CustomBaseModel):
1812
+ """
1813
+ Configuration for a dataset connector.
1814
+ """
1815
+
1816
+ connector_id: str | None = Field(None, alias="connectorId", description="The unique identifier of a connector.")
1817
+ locations: list[str] | None = None
1818
+
1819
+
1820
+ class Dataset(CustomBaseModel):
1821
+ """
1822
+ A dataset to be consumed via the assistant.
1823
+ """
1824
+
1825
+ id: str = Field(..., description="The unique identifier of a dataset.")
1826
+ name: str | None = Field(None, description="The name of a dataset.")
1827
+ description: str | None = Field(None, description="The description of / instructions for a dataset.")
1828
+ connectors: list[DatasetConnector] | None = None
1829
+ files: list[str] | None = None
1830
+ usage: DatasetUsage | None = None
1831
+ metadata: Metadata | None = None
1832
+ OPEN_URL_PARTS: ClassVar[list] = ["d", "datasets"]
1833
+
1834
+ @model_validator(mode="before")
1835
+ @classmethod
1836
+ def add_required_fields(cls, values):
1837
+ if isinstance(values, dict):
1838
+ if "id" not in values:
1839
+ values["id"] = str(uuid.uuid4())
1840
+ return values
1841
+
1842
+ @field_validator("files", mode="after")
1843
+ @classmethod
1844
+ def initialize_file_list(cls, values):
1845
+ if values is None:
1846
+ values = []
1847
+ return values
1848
+
1849
+ def update(
1850
+ self,
1851
+ name: str | None = None,
1852
+ description: str | None = None,
1853
+ connectors: list[DatasetConnector] | None = None,
1854
+ ) -> None:
1855
+ """
1856
+ Update a dataset with specific parameters.
1857
+
1858
+ Args:
1859
+ name (str | None): The name of the connector.
1860
+ description (str | None): The description of the connector.
1861
+ connectors (list[DatasetConnector] | None): The connectors of the dataset.
1862
+ """
1863
+ patch_config = DatasetPatchConfig(
1864
+ name=name,
1865
+ description=description,
1866
+ connectors=connectors,
1867
+ )
1868
+ self.client._update(
1869
+ dataset_id=self.id,
1870
+ config=patch_config,
1871
+ )
1872
+ self.reload()
1873
+
1874
+ def delete(self) -> None:
1875
+ """
1876
+ Delete the dataset.
1877
+ """
1878
+ return self.client._delete(dataset_id=self.id)
1879
+
1880
+ def download_file(
1881
+ self,
1882
+ dataset_file_path: str | Path,
1883
+ output_file_path: str | Path | None = None,
1884
+ ) -> Path:
1885
+ """
1886
+ Download the dataset file.
1887
+
1888
+ Args:
1889
+ file_path (str | Path | None): The file path to save the dataset file.
1890
+
1891
+ Returns:
1892
+ Path: The path to the saved file.
1893
+ """
1894
+ bytes, filename = self.client._download_file(dataset_id=self.id, file_path=str(dataset_file_path))
1895
+ output_file_path = Path(output_file_path or ".")
1896
+ if output_file_path.is_dir():
1897
+ output_file_path = output_file_path / filename
1898
+ output_file_path.write_bytes(bytes)
1899
+ return output_file_path
1900
+
1901
+ def upload_file(
1902
+ self,
1903
+ file_path: str | Path,
1904
+ ) -> None:
1905
+ """
1906
+ Upload the dataset file.
1907
+ """
1908
+ self.client._upload_file(dataset_id=self.id, file_path=str(file_path))
1909
+ self.reload()
1910
+
1911
+ def delete_file(
1912
+ self,
1913
+ file_path: str | Path,
1914
+ ) -> None:
1915
+ """
1916
+ Delete the dataset file.
1917
+ """
1918
+ self.client._delete_file(dataset_id=self.id, file_path=str(file_path))
1919
+ self.reload()
1920
+
1921
+
1922
+ class DatasetListItem(CustomBaseModel):
1923
+ """
1924
+ Essential dataset details for listings.
1925
+ """
1926
+
1927
+ id: str = Field(..., description="The unique identifier of a dataset.")
1928
+ name: str | None = Field(None, description="The name of a dataset.")
1929
+ usage: DatasetUsage | None = None
1930
+ metadata: Metadata | None = None
1931
+
1932
+
1933
+ class DatasetConfig(CustomBaseModel):
1934
+ """
1935
+ The configuration for creating a dataset.
1936
+ """
1937
+
1938
+ name: str | None = Field(None, description="The name of a dataset.")
1939
+ description: str | None = Field(None, description="The description of / instructions for a dataset.")
1940
+ connectors: list[DatasetConnector] | None = None
1941
+
1942
+
1943
+ class DatasetPatchConfig(CustomBaseModel):
1944
+ """
1945
+ The configuration for updating a dataset.
1946
+ """
1947
+
1948
+ name: str | None = Field(None, description="The name of a dataset.")
1949
+ description: str | None = Field(None, description="The description of / instructions for a dataset.")
1950
+ connectors: list[DatasetConnector] | None = None
1951
+
1952
+
1797
1953
  class ConnectorListItem(CustomBaseModel):
1798
1954
  """
1799
1955
  Essential connector details for listings.
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "mostlyai"
3
- version = "4.8.3"
3
+ version = "4.9.0"
4
4
  description = "Synthetic Data SDK"
5
5
  authors = [{ name = "MOSTLY AI", email = "dev@mostly.ai" }]
6
6
  requires-python = ">=3.10,<3.14"
File without changes
File without changes
File without changes
File without changes