synapse-sdk 1.0.0a46__py3-none-any.whl → 1.0.0a47__py3-none-any.whl

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.

Potentially problematic release.


This version of synapse-sdk might be problematic. Click here for more details.

@@ -1,4 +1,4 @@
1
- from synapse_sdk.clients.backend.models import Storage
1
+ from synapse_sdk.clients.backend.models import Storage, UpdateJob
2
2
  from synapse_sdk.clients.base import BaseClient
3
3
  from synapse_sdk.utils.file import convert_file_to_base64
4
4
 
@@ -43,7 +43,7 @@ class IntegrationClientMixin(BaseClient):
43
43
 
44
44
  def update_job(self, pk, data):
45
45
  path = f'jobs/{pk}/'
46
- return self._patch(path, data=data)
46
+ return self._patch(path, request_model=UpdateJob, data=data)
47
47
 
48
48
  def list_job_console_logs(self, pk):
49
49
  path = f'jobs/{pk}/console_logs/'
@@ -82,4 +82,4 @@ class IntegrationClientMixin(BaseClient):
82
82
  def get_storage(self, pk):
83
83
  """Get specific storage data from synapse backend."""
84
84
  path = f'storages/{pk}/'
85
- return self._get(path, pydantic_model=Storage)
85
+ return self._get(path, response_model=Storage)
@@ -1,5 +1,5 @@
1
1
  from enum import Enum
2
- from typing import Dict
2
+ from typing import Dict, Optional
3
3
 
4
4
  from pydantic import BaseModel
5
5
 
@@ -42,3 +42,35 @@ class Storage(BaseModel):
42
42
  provider: StorageProvider
43
43
  configuration: Dict
44
44
  is_default: bool
45
+
46
+
47
+ class JobStatus(str, Enum):
48
+ """Synapse Backend Job Status Enum."""
49
+
50
+ PENDING = 'pending'
51
+ RUNNING = 'running'
52
+ STOPPED = 'stopped'
53
+ SUCCEEDED = 'succeeded'
54
+ FAILED = 'failed'
55
+
56
+
57
+ class UpdateJob(BaseModel):
58
+ """Synapse Backend Update Job Request Payload Model.
59
+
60
+ Attrs:
61
+ status (str): The job status. (ex: pending, running, stopped, succeeded, failed)
62
+ progress_record (Dict): The job progress record.
63
+ console_logs (Dict): The job console logs.
64
+ result (Dict): The job result.
65
+ """
66
+
67
+ status: Optional[JobStatus] = None
68
+ progress_record: Optional[Dict] = None
69
+ console_logs: Optional[Dict] = None
70
+ result: Optional[Dict] = None
71
+
72
+ def model_dump(self, **kwargs):
73
+ data = super().model_dump(**kwargs)
74
+ if data.get('status') is not None:
75
+ data['status'] = data['status'].value
76
+ return data
@@ -86,14 +86,15 @@ class BaseClient:
86
86
  except ValueError:
87
87
  return response.text
88
88
 
89
- def _get(self, path, url_conversion=None, pydantic_model=None, **kwargs):
89
+ def _get(self, path, url_conversion=None, response_model=None, **kwargs):
90
90
  """
91
91
  Perform a GET request and optionally convert response to a pydantic model.
92
92
 
93
93
  Args:
94
94
  path (str): URL path to request.
95
95
  url_conversion (dict, optional): Configuration for URL to path conversion.
96
- pydantic_model (Type, optional): Pydantic model to convert the response to.
96
+ request_model (pydantic.BaseModel, optional): Pydantic model to validate the request.
97
+ response_model (pydantic.BaseModel, optional): Pydantic model to validate the response.
97
98
  **kwargs: Additional keyword arguments to pass to the request.
98
99
 
99
100
  Returns:
@@ -107,36 +108,100 @@ class BaseClient:
107
108
  else:
108
109
  files_url_to_path_from_objs(response, **url_conversion)
109
110
 
110
- if pydantic_model:
111
- return self._validate_response_with_pydantic_model(response, pydantic_model)
111
+ if response_model:
112
+ return self._validate_response_with_pydantic_model(response, response_model)
112
113
 
113
114
  return response
114
115
 
115
- def _post(self, path, pydantic_model=None, **kwargs):
116
+ def _post(self, path, request_model=None, response_model=None, **kwargs):
117
+ """
118
+ Perform a POST request and optionally convert response to a pydantic model.
119
+
120
+ Args:
121
+ path (str): URL path to request.
122
+ request_model (pydantic.BaseModel, optional): Pydantic model to validate the request.
123
+ response_model (pydantic.BaseModel, optional): Pydantic model to validate the response.
124
+ **kwargs: Additional keyword arguments to pass to the request.
125
+
126
+ Returns:
127
+ The response data, optionally converted to a pydantic model.
128
+ """
129
+ if kwargs.get('data') and request_model:
130
+ kwargs['data'] = self._validate_request_body_with_pydantic_model(kwargs['data'], request_model)
116
131
  response = self._request('post', path, **kwargs)
117
- if pydantic_model:
118
- return self._validate_response_with_pydantic_model(response, pydantic_model)
132
+ if response_model:
133
+ return self._validate_response_with_pydantic_model(response, response_model)
119
134
  else:
120
135
  return response
121
136
 
122
- def _put(self, path, pydantic_model=None, **kwargs):
137
+ def _put(self, path, request_model=None, response_model=None, **kwargs):
138
+ """
139
+ Perform a PUT request to the specified path.
140
+
141
+ Args:
142
+ path (str): The URL path for the request.
143
+ request_model (Optional[Type[BaseModel]]): A Pydantic model class to validate the request body against.
144
+ response_model (Optional[Type[BaseModel]]): A Pydantic model class to validate and parse the response.
145
+ **kwargs: Additional arguments to pass to the request method.
146
+ - data: The request body to be sent. If provided along with request_model, it will be validated.
147
+
148
+ Returns:
149
+ Union[dict, BaseModel]:
150
+ If response_model is provided, returns an instance of that model populated with the response data.
151
+ """
152
+ if kwargs.get('data') and request_model:
153
+ kwargs['data'] = self._validate_request_body_with_pydantic_model(kwargs['data'], request_model)
123
154
  response = self._request('put', path, **kwargs)
124
- if pydantic_model:
125
- return self._validate_response_with_pydantic_model(response, pydantic_model)
155
+ if response_model:
156
+ return self._validate_response_with_pydantic_model(response, response_model)
126
157
  else:
127
158
  return response
128
159
 
129
- def _patch(self, path, pydantic_model=None, **kwargs):
160
+ def _patch(self, path, request_model=None, response_model=None, **kwargs):
161
+ """
162
+ Perform a PATCH HTTP request to the specified path.
163
+
164
+ Args:
165
+ path (str): The API endpoint path to make the request to.
166
+ request_model (Optional[Type[BaseModel]]): A Pydantic model class used to validate the request body.
167
+ response_model (Optional[Type[BaseModel]]): A Pydantic model class used to validate and parse the response.
168
+ **kwargs: Additional keyword arguments to pass to the request method.
169
+ - data: The request body data. If provided along with request_model, it will be validated.
170
+
171
+ Returns:
172
+ Union[dict, BaseModel]: If response_model is provided, returns an instance of that model.
173
+ Otherwise, returns the raw response data.
174
+ """
175
+
176
+ if kwargs.get('data') and request_model:
177
+ kwargs['data'] = self._validate_request_body_with_pydantic_model(kwargs['data'], request_model)
130
178
  response = self._request('patch', path, **kwargs)
131
- if pydantic_model:
132
- return self._validate_response_with_pydantic_model(response, pydantic_model)
179
+ if response_model:
180
+ return self._validate_response_with_pydantic_model(response, response_model)
133
181
  else:
134
182
  return response
135
183
 
136
- def _delete(self, path, pydantic_model=None, **kwargs):
184
+ def _delete(self, path, request_model=None, response_model=None, **kwargs):
185
+ """
186
+ Performs a DELETE request to the specified path.
187
+
188
+ Args:
189
+ path (str): The API endpoint path to send the DELETE request to.
190
+ request_model (Optional[Type[BaseModel]]): Pydantic model to validate the request data against.
191
+ response_model (Optional[Type[BaseModel]]): Pydantic model to validate and convert the response data.
192
+ **kwargs: Additional keyword arguments passed to the request method.
193
+ - data: Request payload to send. Will be validated against request_model if both are provided.
194
+
195
+ Returns:
196
+ Union[dict, BaseModel]: If response_model is provided, returns an instance of that model.
197
+ Otherwise, returns the raw response data as a dictionary.
198
+ """
199
+
200
+ if kwargs.get('data') and request_model:
201
+ kwargs['data'] = self._validate_request_body_with_pydantic_model(kwargs['data'], request_model)
137
202
  response = self._request('delete', path, **kwargs)
138
- if pydantic_model:
139
- return self._validate_response_with_pydantic_model(response, pydantic_model)
203
+ if response_model:
204
+ return self._validate_response_with_pydantic_model(response, response_model)
140
205
  else:
141
206
  return response
142
207
 
@@ -170,3 +235,19 @@ class BaseClient:
170
235
  else:
171
236
  # Not a pydantic model
172
237
  raise TypeError('The provided model is not a pydantic model')
238
+
239
+ def _validate_request_body_with_pydantic_model(self, request_body, pydantic_model):
240
+ """Validate a request body with a pydantic model."""
241
+ # Check if model is a pydantic model (has the __pydantic_model__ attribute)
242
+ if (
243
+ hasattr(pydantic_model, '__pydantic_model__')
244
+ or hasattr(pydantic_model, 'model_validate')
245
+ or hasattr(pydantic_model, 'parse_obj')
246
+ ):
247
+ # Validate the request body and convert to model instance
248
+ model_instance = pydantic_model.model_validate(request_body)
249
+ # Convert model to dict and remove None values
250
+ return {k: v for k, v in model_instance.model_dump().items() if v is not None}
251
+ else:
252
+ # Not a pydantic model
253
+ raise TypeError('The provided model is not a pydantic model')
@@ -1,4 +1,3 @@
1
- import json
2
1
  from abc import ABC, abstractmethod
3
2
  from datetime import datetime
4
3
  from typing import Annotated, Any, Literal
@@ -17,12 +16,18 @@ from synapse_sdk.utils.pydantic.validators import non_blank
17
16
  from synapse_sdk.utils.storage import get_pathlib
18
17
 
19
18
 
19
+ class DataFileInfo(BaseModel):
20
+ """Schema for data_file_info."""
21
+
22
+ file_name: str
23
+
24
+
20
25
  class ExportRun(Run):
21
26
  class DataFileLog(BaseModel):
22
27
  """Data file log model."""
23
28
 
24
29
  target_id: int
25
- data_file_info: str | None
30
+ data_file_info: DataFileInfo
26
31
  status: ExportStatus
27
32
  error: str | None = None
28
33
  created: str
@@ -44,7 +49,7 @@ class ExportRun(Run):
44
49
  log_type,
45
50
  self.DataFileLog(
46
51
  target_id=target_id,
47
- data_file_info=json.dumps(data_file_info),
52
+ data_file_info=data_file_info,
48
53
  status=status.value,
49
54
  error=error,
50
55
  created=now,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: synapse-sdk
3
- Version: 1.0.0a46
3
+ Version: 1.0.0a47
4
4
  Summary: synapse sdk
5
5
  Author-email: datamaker <developer@datamaker.io>
6
6
  License: MIT
@@ -21,7 +21,7 @@ synapse_sdk/cli/plugin/create.py,sha256=HpYTpohV1NbSrULaVUlc4jWLWznPrx7glgydTM3s
21
21
  synapse_sdk/cli/plugin/publish.py,sha256=sIl1wiuSC3lAUpE3rOF4UDKDy2G5EVLlelMjk2aT05g,1221
22
22
  synapse_sdk/cli/plugin/run.py,sha256=xz5LRm3zh8Y9DMjw5FFRFVRWSCWtYfZJskfCmrPikaQ,2598
23
23
  synapse_sdk/clients/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
24
- synapse_sdk/clients/base.py,sha256=emtffTGGtPOSz6tT_NCL9cGE7ZEOv9pTHyc9BRfoe2s,6462
24
+ synapse_sdk/clients/base.py,sha256=K6wPKG8DFus5hG7nOUnKWS9-FuzG4ndkbNYCLBA_30Y,10957
25
25
  synapse_sdk/clients/exceptions.py,sha256=ylv7x10eOp4aA3a48jwonnvqvkiYwzJYXjkVkRTAjwk,220
26
26
  synapse_sdk/clients/utils.py,sha256=8pPJTdzHiRPSbZMoQYHAgR2BAMO6u_R_jMV6a2p34iQ,392
27
27
  synapse_sdk/clients/agent/__init__.py,sha256=Pz8_iTbIbnb7ywGJ3feqoZVmO2I3mEbwpWsISIxh0BU,1968
@@ -33,9 +33,9 @@ synapse_sdk/clients/backend/annotation.py,sha256=f4jS4qlXH7M7mQ3EuCq-NrjJ_hJNDz8
33
33
  synapse_sdk/clients/backend/core.py,sha256=5XAOdo6JZ0drfk-FMPJ96SeTd9oja-VnTwzGXdvK7Bg,1027
34
34
  synapse_sdk/clients/backend/dataset.py,sha256=11R5LuTva9jgXatxQAlKy7UEJmwIWzTsLVdFf3MZ9F8,3400
35
35
  synapse_sdk/clients/backend/hitl.py,sha256=na2mSXFud92p4zUEuagcDWk2klxO7xn-e86cm0VZEvs,709
36
- synapse_sdk/clients/backend/integration.py,sha256=Xi-DIimjaDSaLZWWd0rmFgj4uFav8H4r4gxTSsjX0vo,2647
36
+ synapse_sdk/clients/backend/integration.py,sha256=9LjkYcBpi7aog-MODSDS4RlmYahypu65qxBj-AcY7xc,2683
37
37
  synapse_sdk/clients/backend/ml.py,sha256=JoPH9Ly2E3HJ7S5mdGLtcGq7ruQVVrYfWArogwZLlms,1193
38
- synapse_sdk/clients/backend/models.py,sha256=ycuzIBi3pyKIFkNzrNGsv3cA49BjLmjyylNHBSRG4bI,1047
38
+ synapse_sdk/clients/backend/models.py,sha256=XYG6SmEnSvKRE1UD8M_3GiN56gWTGSOW5oMex3-mTtE,1947
39
39
  synapse_sdk/clients/ray/__init__.py,sha256=9ZSPXVVxlJ8Wp8ku7l021ENtPjVrGgQDgqifkkVAXgM,187
40
40
  synapse_sdk/clients/ray/core.py,sha256=a4wyCocAma2HAm-BHlbZnoVbpfdR-Aad2FM0z6vPFvw,731
41
41
  synapse_sdk/clients/ray/serve.py,sha256=rbCpXZYWf0oP8XJ9faa9QFNPYU7h8dltIG8xn9ZconY,907
@@ -61,7 +61,7 @@ synapse_sdk/plugins/categories/data_validation/templates/plugin/validation.py,sh
61
61
  synapse_sdk/plugins/categories/export/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
62
62
  synapse_sdk/plugins/categories/export/enums.py,sha256=gtyngvQ1DKkos9iKGcbecwTVQQ6sDwbrBPSGPNb5Am0,127
63
63
  synapse_sdk/plugins/categories/export/actions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
64
- synapse_sdk/plugins/categories/export/actions/export.py,sha256=xqPB_MufeMP3riaKCbGVFGukV8RdXcg6-zUrkw4t1-A,9922
64
+ synapse_sdk/plugins/categories/export/actions/export.py,sha256=sVga8cgprKFpZB-RCiZghCGQcBnr7Y58-jig9vPMbrc,9990
65
65
  synapse_sdk/plugins/categories/export/templates/config.yaml,sha256=N7YmnFROb3s3M35SA9nmabyzoSb5O2t2TRPicwFNN2o,56
66
66
  synapse_sdk/plugins/categories/export/templates/plugin/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
67
67
  synapse_sdk/plugins/categories/export/templates/plugin/export.py,sha256=UzPOYvH2rwUlTUpMgcbn7mBsenf3hmWytE-eD_cB_9A,5202
@@ -134,9 +134,9 @@ synapse_sdk/utils/storage/providers/__init__.py,sha256=x7RGwZryT2FpVxS7fGWryRVpq
134
134
  synapse_sdk/utils/storage/providers/gcp.py,sha256=i2BQCu1Kej1If9SuNr2_lEyTcr5M_ncGITZrL0u5wEA,363
135
135
  synapse_sdk/utils/storage/providers/s3.py,sha256=W94rQvhGRXti3R4mYP7gmU5pcyCQpGFIBLvxxqLVdRM,2231
136
136
  synapse_sdk/utils/storage/providers/sftp.py,sha256=_8s9hf0JXIO21gvm-JVS00FbLsbtvly4c-ETLRax68A,1426
137
- synapse_sdk-1.0.0a46.dist-info/licenses/LICENSE,sha256=bKzmC5YAg4V1Fhl8OO_tqY8j62hgdncAkN7VrdjmrGk,1101
138
- synapse_sdk-1.0.0a46.dist-info/METADATA,sha256=FBaND1uI65IAg7m8rySWXXhXU39wTMvAp1MWeFy8sfI,1203
139
- synapse_sdk-1.0.0a46.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
140
- synapse_sdk-1.0.0a46.dist-info/entry_points.txt,sha256=VNptJoGoNJI8yLXfBmhgUefMsmGI0m3-0YoMvrOgbxo,48
141
- synapse_sdk-1.0.0a46.dist-info/top_level.txt,sha256=ytgJMRK1slVOKUpgcw3LEyHHP7S34J6n_gJzdkcSsw8,12
142
- synapse_sdk-1.0.0a46.dist-info/RECORD,,
137
+ synapse_sdk-1.0.0a47.dist-info/licenses/LICENSE,sha256=bKzmC5YAg4V1Fhl8OO_tqY8j62hgdncAkN7VrdjmrGk,1101
138
+ synapse_sdk-1.0.0a47.dist-info/METADATA,sha256=m85ag15c0Y0vLrK6u7J6FVg8DgP9ew_bfXr-9ERl-jA,1203
139
+ synapse_sdk-1.0.0a47.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
140
+ synapse_sdk-1.0.0a47.dist-info/entry_points.txt,sha256=VNptJoGoNJI8yLXfBmhgUefMsmGI0m3-0YoMvrOgbxo,48
141
+ synapse_sdk-1.0.0a47.dist-info/top_level.txt,sha256=ytgJMRK1slVOKUpgcw3LEyHHP7S34J6n_gJzdkcSsw8,12
142
+ synapse_sdk-1.0.0a47.dist-info/RECORD,,