destiny_sdk 0.3.0a0__py3-none-any.whl → 0.4.0__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.
destiny_sdk/client.py CHANGED
@@ -8,6 +8,9 @@ from pydantic import UUID4, HttpUrl
8
8
 
9
9
  from destiny_sdk.robots import (
10
10
  EnhancementRequestRead,
11
+ RobotEnhancementBatch,
12
+ RobotEnhancementBatchRead,
13
+ RobotEnhancementBatchResult,
11
14
  RobotResult,
12
15
  )
13
16
 
@@ -89,3 +92,50 @@ class Client:
89
92
  )
90
93
  response.raise_for_status()
91
94
  return EnhancementRequestRead.model_validate(response.json())
95
+
96
+ def send_robot_enhancement_batch_result(
97
+ self, robot_enhancement_batch_result: RobotEnhancementBatchResult
98
+ ) -> RobotEnhancementBatchRead:
99
+ """
100
+ Send a RobotEnhancementBatchResult to destiny repository.
101
+
102
+ Signs the request with the client's secret key.
103
+
104
+ :param robot_enhancement_batch_result: The RobotEnhancementBatchResult to send
105
+ :type robot_enhancement_batch_result: RobotEnhancementBatchResult
106
+ :return: The RobotEnhancementBatchRead object from the response.
107
+ :rtype: RobotEnhancementBatchRead
108
+ """
109
+ response = self.session.post(
110
+ f"/robot-enhancement-batch/{robot_enhancement_batch_result.request_id}/results/",
111
+ json=robot_enhancement_batch_result.model_dump(mode="json"),
112
+ )
113
+ response.raise_for_status()
114
+ return RobotEnhancementBatchRead.model_validate(response.json())
115
+
116
+ def poll_robot_enhancement_batch(
117
+ self, robot_id: UUID4, limit: int = 10
118
+ ) -> RobotEnhancementBatch | None:
119
+ """
120
+ Poll for a robot enhancement batch.
121
+
122
+ Signs the request with the client's secret key.
123
+
124
+ :param robot_id: The ID of the robot to poll for
125
+ :type robot_id: UUID4
126
+ :param limit: The maximum number of pending enhancements to return
127
+ :type limit: int
128
+ :return: The RobotEnhancementBatch object from the response, or None if no
129
+ batches available
130
+ :rtype: RobotEnhancementBatch | None
131
+ """
132
+ response = self.session.post(
133
+ "/robot-enhancement-batch/",
134
+ params={"robot_id": str(robot_id), "limit": limit},
135
+ )
136
+ # HTTP 204 No Content indicates no batches available
137
+ if response.status_code == httpx.codes.NO_CONTENT:
138
+ return None
139
+
140
+ response.raise_for_status()
141
+ return RobotEnhancementBatch.model_validate(response.json())
destiny_sdk/imports.py CHANGED
@@ -19,13 +19,11 @@ class ImportRecordStatus(StrEnum):
19
19
  - `created`: Created, but no processing has started.
20
20
  - `started`: Processing has started on the batch.
21
21
  - `completed`: Processing has been completed.
22
- - `cancelled`: Processing was cancelled by calling the API.
23
22
  """
24
23
 
25
24
  CREATED = auto()
26
25
  STARTED = auto()
27
26
  COMPLETED = auto()
28
- CANCELLED = auto()
29
27
 
30
28
 
31
29
  class ImportBatchStatus(StrEnum):
@@ -35,21 +33,15 @@ class ImportBatchStatus(StrEnum):
35
33
  - `created`: Created, but no processing has started.
36
34
  - `started`: Processing has started on the batch.
37
35
  - `failed`: Processing has failed.
38
- - `retrying`: Processing has failed, but is being retried.
39
- - `indexing`: The imports have been saved and are being indexed.
40
- - `indexing_failed`: The imports have been saved but were not indexed.
36
+ - `partially_failed`: Some references succeeded while others failed.
41
37
  - `completed`: Processing has been completed.
42
- - `cancelled`: Processing was cancelled by calling the API.
43
38
  """
44
39
 
45
40
  CREATED = auto()
46
41
  STARTED = auto()
47
- RETRYING = auto()
48
42
  FAILED = auto()
49
- INDEXING = auto()
50
- INDEXING_FAILED = auto()
43
+ PARTIALLY_FAILED = auto()
51
44
  COMPLETED = auto()
52
- CANCELLED = auto()
53
45
 
54
46
 
55
47
  class CollisionStrategy(StrEnum):
@@ -96,15 +88,15 @@ class ImportResultStatus(StrEnum):
96
88
  more information.
97
89
  - `failed`: The reference failed to be created. See the result's `failure_details`
98
90
  field for more information.
99
- - `cancelled`: Processing was cancelled by calling the API.
91
+ - `retrying`: Processing has failed, but is being retried.
100
92
  """
101
93
 
102
94
  CREATED = auto()
103
95
  STARTED = auto()
104
96
  COMPLETED = auto()
105
- CANCELLED = auto()
106
97
  PARTIALLY_FAILED = auto()
107
98
  FAILED = auto()
99
+ RETRYING = auto()
108
100
 
109
101
 
110
102
  class _ImportRecordBase(BaseModel):
@@ -186,9 +178,8 @@ with each line formatted according to
186
178
  )
187
179
  callback_url: HttpUrl | None = Field(
188
180
  default=None,
189
- description="""
190
- The URL to which the processor should send a callback when the batch has been processed.
191
- """,
181
+ deprecated=True,
182
+ description="This field is currently a no-op.",
192
183
  )
193
184
 
194
185
 
destiny_sdk/robots.py CHANGED
@@ -52,6 +52,23 @@ None, the repository will assume that the result file is ready for processing.
52
52
  )
53
53
 
54
54
 
55
+ class RobotEnhancementBatchResult(BaseModel):
56
+ """Used to indicate that the robot has finished processing a batch."""
57
+
58
+ request_id: UUID4
59
+ error: RobotError | None = Field(
60
+ default=None,
61
+ description="""
62
+ Error the robot encountered while creating enhancements. If this field is populated,
63
+ we assume the entire robot enhancement batch failed,
64
+ rather than an individual reference.
65
+ If there was an error with processing an individual reference, it should be passed in
66
+ the result file and this field should be left as None. Vice-versa, if this field is
67
+ None, the repository will assume that the result file is ready for processing.
68
+ """,
69
+ )
70
+
71
+
55
72
  class RobotResultValidationEntry(_JsonlFileInputMixIn, BaseModel):
56
73
  """A single entry in the validation result file for a batch enhancement request."""
57
74
 
@@ -110,6 +127,37 @@ If the URL expires, a new one can be generated using
110
127
  )
111
128
 
112
129
 
130
+ class RobotEnhancementBatch(BaseModel):
131
+ """A robot enhancement batch from the repo to a robot."""
132
+
133
+ id: UUID4
134
+ reference_storage_url: HttpUrl = Field(
135
+ description="""
136
+ The URL at which the set of references are stored. The file is a jsonl
137
+ with each line formatted according to
138
+ :class:`Reference <libs.sdk.src.destiny_sdk.references.Reference>`, one
139
+ reference per line.
140
+ Each reference may have identifiers or enhancements attached, as
141
+ required by the robot.
142
+ If the URL expires, a new one can be generated using
143
+ ``GET /robot-enhancement-batch/{batch_id}/``.
144
+ """
145
+ )
146
+ result_storage_url: HttpUrl = Field(
147
+ description="""
148
+ The URL at which the set of enhancements are to be stored. The file is to be a jsonl
149
+ with each line formatted according to
150
+ :class:`EnhancementResultEntry <libs.sdk.src.destiny_sdk.robots.EnhancementResultEntry>`.
151
+ If the URL expires, a new one can be generated using
152
+ ``GET /robot-enhancement-batch/{batch_id}/``.
153
+ """ # noqa: E501
154
+ )
155
+ extra_fields: dict | None = Field(
156
+ default=None,
157
+ description="Extra fields to pass to the robot. TBC.",
158
+ )
159
+
160
+
113
161
  class EnhancementRequestStatus(StrEnum):
114
162
  """
115
163
  The status of an enhancement request.
@@ -117,6 +165,7 @@ class EnhancementRequestStatus(StrEnum):
117
165
  **Allowed values**:
118
166
  - `received`: Enhancement request has been received by the repo.
119
167
  - `accepted`: Enhancement request has been accepted by the robot.
168
+ - `processing`: Enhancement request is being processed by the robot.
120
169
  - `rejected`: Enhancement request has been rejected by the robot.
121
170
  - `partial_failed`: Some enhancements failed to create.
122
171
  - `failed`: All enhancements failed to create.
@@ -128,6 +177,7 @@ class EnhancementRequestStatus(StrEnum):
128
177
 
129
178
  RECEIVED = auto()
130
179
  ACCEPTED = auto()
180
+ PROCESSING = auto()
131
181
  REJECTED = auto()
132
182
  PARTIAL_FAILED = auto()
133
183
  FAILED = auto()
@@ -210,6 +260,70 @@ If the URL expires, a new one can be generated using
210
260
  )
211
261
 
212
262
 
263
+ class _RobotEnhancementBatchBase(BaseModel):
264
+ """
265
+ Base robot enhancement batch class.
266
+
267
+ A robot enhancement batch is a batch of pending enhancements the robot has picked up
268
+ for processing.
269
+ """
270
+
271
+ robot_id: UUID4 = Field(
272
+ description="The robot to be used to create the enhancements."
273
+ )
274
+ source: str | None = Field(
275
+ default=None,
276
+ description="The source of the batch enhancement request.",
277
+ )
278
+
279
+
280
+ class RobotEnhancementBatchRead(_RobotEnhancementBatchBase):
281
+ """Core robot enhancement batch class."""
282
+
283
+ id: UUID4
284
+ reference_data_url: HttpUrl | None = Field(
285
+ default=None,
286
+ description="""
287
+ The URL at which the set of references are stored. The file is a jsonl with each line
288
+ formatted according to
289
+ :class:`Reference <libs.sdk.src.destiny_sdk.references.Reference>`.
290
+ , one reference per line.
291
+ Each reference may have identifiers or enhancements attached, as
292
+ required by the robot.
293
+ If the URL expires, a new one can be generated using
294
+ ``GET /enhancement-requests/{request_id}/``.
295
+ """,
296
+ )
297
+ result_storage_url: HttpUrl | None = Field(
298
+ default=None,
299
+ description="""
300
+ The URL at which the set of enhancements are stored. The file is to be a jsonl
301
+ with each line formatted according to
302
+ :class:`EnhancementResultEntry <libs.sdk.src.destiny_sdk.robots.EnhancementResultEntry>`.
303
+ This field is only relevant to robots.
304
+ If the URL expires, a new one can be generated using
305
+ ``GET /robot-enhancement-batch/{batch_id}/``.
306
+ """, # noqa: E501
307
+ )
308
+ validation_result_url: HttpUrl | None = Field(
309
+ default=None,
310
+ description="""
311
+ The URL at which the result of the enhancement request is stored.
312
+ This file is a txt file, one line per reference, with either an error
313
+ or a success message.
314
+ If the URL expires, a new one can be generated using
315
+ ``GET /robot-enhancement-batch/{batch_id}/``.
316
+ """,
317
+ )
318
+ error: str | None = Field(
319
+ default=None,
320
+ description="Error encountered during the enhancement process. This "
321
+ "is only used if the entire enhancement batch failed, rather than an "
322
+ "individual reference. If there was an error with processing an individual "
323
+ "reference, it is passed in the validation result file.",
324
+ )
325
+
326
+
213
327
  class _RobotBase(BaseModel):
214
328
  """
215
329
  Base Robot class.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: destiny_sdk
3
- Version: 0.3.0a0
3
+ Version: 0.4.0
4
4
  Summary: A software development kit (sdk) to support interaction with the DESTINY repository
5
5
  Author-email: Adam Hamilton <adam@futureevidence.org>, Andrew Harvey <andrew@futureevidence.org>, Daniel Breves <daniel@futureevidence.org>, Jack Walmisley <jack@futureevidence.org>
6
6
  License-Expression: Apache-2.0
@@ -1,17 +1,17 @@
1
1
  destiny_sdk/__init__.py,sha256=gmmrceJX84T4msk_GSm_OjTQvCpHFZRjnlUK5_7IODE,356
2
2
  destiny_sdk/auth.py,sha256=bY72ywZEcG_67YBd9PrwgWTXkCf58rhLvVEXrtXbWtA,6247
3
- destiny_sdk/client.py,sha256=2X_z0Z0T5xPD2vRzDBXs2D-Xk-mkVGz9CRhIeJLuaaU,2906
3
+ destiny_sdk/client.py,sha256=w03l23Cph2-a8HlU7k3yLp6f7tNYH6hf_5KfasoeWaI,4900
4
4
  destiny_sdk/core.py,sha256=_FwDaczKTSaUSV_qfcnLhkBbZagh4ayFpN0qUwJ03-o,1448
5
5
  destiny_sdk/enhancements.py,sha256=_S_anq194qdaEGklgycSG1qLEJeWzKe1u3oyXNxAg54,11800
6
6
  destiny_sdk/identifiers.py,sha256=9CFEaPhZr2IHfL4RSAzOvidXhhzKLDPXiSKddBMWzwM,3606
7
- destiny_sdk/imports.py,sha256=mfC1QXbAU27iD3hO9OFTRQes352F6DS1U4fSMw26-8w,8243
7
+ destiny_sdk/imports.py,sha256=PG1rNNPdOxTeVI3-8sXFfRYi9BkCVZmr_jqr0Q9mxiU,7845
8
8
  destiny_sdk/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
9
  destiny_sdk/references.py,sha256=Dx-WKcv9gNJkKU9n52AYoEey7siTHR5_wBVBKSHND6Q,2321
10
- destiny_sdk/robots.py,sha256=aFOcAAmyWOixW2MnRfyKJORSYKf1tr0PWkyO9i3oJ4M,9605
10
+ destiny_sdk/robots.py,sha256=JqNGbLpiKZmDwUsc4P5SnGTb9wufp9K9aFDUbttkAPE,13769
11
11
  destiny_sdk/visibility.py,sha256=nDLqnWuSZSk0vG3ynzDpHAvaALsbk8cuEZujTsqf6no,684
12
12
  destiny_sdk/parsers/__init__.py,sha256=d5gS--bXla_0I7e_9wTBnGWMXt2U8b-_ndeprTPe1hk,149
13
13
  destiny_sdk/parsers/eppi_parser.py,sha256=aSTqmm8N2WK1gnkj38XvfWaEXsaf0y6je6h9qN0xvFA,5584
14
- destiny_sdk-0.3.0a0.dist-info/METADATA,sha256=R1tR-ANCbGLXJp7CXvE6AcmYbTzbzo4eoms_CzKEL9w,2442
15
- destiny_sdk-0.3.0a0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
16
- destiny_sdk-0.3.0a0.dist-info/licenses/LICENSE,sha256=6QURU4gvvTjVZ5rfp5amZ6FtFvcpPhAGUjxF5WSZAHI,9138
17
- destiny_sdk-0.3.0a0.dist-info/RECORD,,
14
+ destiny_sdk-0.4.0.dist-info/METADATA,sha256=oTlLnYBqi0Ib38srLTK-904K2Uw2IMcW20hAxa2-eJ4,2440
15
+ destiny_sdk-0.4.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
16
+ destiny_sdk-0.4.0.dist-info/licenses/LICENSE,sha256=6QURU4gvvTjVZ5rfp5amZ6FtFvcpPhAGUjxF5WSZAHI,9138
17
+ destiny_sdk-0.4.0.dist-info/RECORD,,