destiny_sdk 0.1.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.
@@ -0,0 +1,51 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ <http://www.apache.org/licenses/>
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
10
+
11
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
12
+
13
+ "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
14
+
15
+ "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
16
+
17
+ "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
18
+
19
+ "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
20
+
21
+ "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
22
+
23
+ "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
24
+
25
+ "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
26
+
27
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
28
+
29
+ 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
30
+
31
+ 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
32
+
33
+ 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
34
+
35
+ You must give any other recipients of the Work or Derivative Works a copy of this License; and
36
+ You must cause any modified files to carry prominent notices stating that You changed the files; and
37
+ You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
38
+ If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
39
+ You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
40
+
41
+ 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
42
+
43
+ 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
44
+
45
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
46
+
47
+ 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
48
+
49
+ 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
50
+
51
+ END OF TERMS AND CONDITIONS
@@ -0,0 +1,92 @@
1
+ Metadata-Version: 2.3
2
+ Name: destiny_sdk
3
+ Version: 0.1.0
4
+ Summary: A software development kit (sdk) to support interaction with the DESTINY repository
5
+ License: Apache 2.0
6
+ Author: Adam Hamilton
7
+ Author-email: adam@futureevidence.org
8
+ Requires-Python: >=3.12,<4.0
9
+ Classifier: License :: Other/Proprietary License
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.12
12
+ Classifier: Programming Language :: Python :: 3.13
13
+ Requires-Dist: cachetools (>=5.5.2,<6.0.0)
14
+ Requires-Dist: fastapi (>=0.115.12,<0.116.0)
15
+ Requires-Dist: httpx (>=0.28.1,<0.29.0)
16
+ Requires-Dist: pydantic (>=2.11.3,<3.0.0)
17
+ Requires-Dist: pytest (>=8.4.0,<9.0.0)
18
+ Requires-Dist: pytest-asyncio (>=1.0.0,<2.0.0)
19
+ Requires-Dist: pytest-httpx (>=0.35.0,<0.36.0)
20
+ Requires-Dist: python-jose (>=3.4.0,<4.0.0)
21
+ Description-Content-Type: text/markdown
22
+
23
+ # DESTINY SDK
24
+
25
+ SDK for interaction with the DESTINY repository. For now this just contains data models for validation and structuring, but will be built out to include convenience functions etc.
26
+
27
+ ## Documentation
28
+
29
+ The documentation for destiny-sdk is hosted [here](https://destiny-evidence.github.io/destiny-repository/sdk/sdk.html)
30
+
31
+ ## Installation from PyPI
32
+
33
+ ```sh
34
+ pip install destiny-sdk
35
+ ```
36
+
37
+ ```sh
38
+ poetry add destiny-sdk
39
+ ```
40
+
41
+ ## Development
42
+
43
+ ### Dependencies
44
+
45
+ ```sh
46
+ poetry install
47
+ ```
48
+
49
+ ### Tests
50
+
51
+ ```sh
52
+ poetry run pytest
53
+ ```
54
+
55
+ ### Installing as an editable package of another project
56
+
57
+ Run the following command in the root folder of the other project (assuming poetry as a packaging framework). Pip also has an `--editable` option that you can use.
58
+
59
+ ```sh
60
+ poetry add --editable ./PATH/TO/sdk/
61
+ ```
62
+
63
+ or replace the dependency in `pyproject.toml` with
64
+
65
+ ```toml
66
+ destiny-sdk = {path = "./PATH/TO/sdk/", develop = true}
67
+ ```
68
+
69
+ ### Installing a local wheel
70
+
71
+ If you want to use a local build of the sdk `z.whl`, do
72
+
73
+ ```sh
74
+ poetry build
75
+ poetry add ./PATH/TO/WHEEL.whl
76
+ ```
77
+
78
+ ### Publishing to test pypi
79
+
80
+ ```sh
81
+ poetry config repositories.testpypi https://test.pypi.org/legacy/
82
+ poetry config pypi-token.testpypi [YOUR_TESTPYPI_TOKEN]
83
+ poetry publish --repository testpypi
84
+ ```
85
+
86
+ ## Publishing
87
+
88
+ ```sh
89
+ poetry config pypi-token.pypi [YOUR_PYPI_TOKEN]
90
+ poetry publish
91
+ ```
92
+
@@ -0,0 +1,69 @@
1
+ # DESTINY SDK
2
+
3
+ SDK for interaction with the DESTINY repository. For now this just contains data models for validation and structuring, but will be built out to include convenience functions etc.
4
+
5
+ ## Documentation
6
+
7
+ The documentation for destiny-sdk is hosted [here](https://destiny-evidence.github.io/destiny-repository/sdk/sdk.html)
8
+
9
+ ## Installation from PyPI
10
+
11
+ ```sh
12
+ pip install destiny-sdk
13
+ ```
14
+
15
+ ```sh
16
+ poetry add destiny-sdk
17
+ ```
18
+
19
+ ## Development
20
+
21
+ ### Dependencies
22
+
23
+ ```sh
24
+ poetry install
25
+ ```
26
+
27
+ ### Tests
28
+
29
+ ```sh
30
+ poetry run pytest
31
+ ```
32
+
33
+ ### Installing as an editable package of another project
34
+
35
+ Run the following command in the root folder of the other project (assuming poetry as a packaging framework). Pip also has an `--editable` option that you can use.
36
+
37
+ ```sh
38
+ poetry add --editable ./PATH/TO/sdk/
39
+ ```
40
+
41
+ or replace the dependency in `pyproject.toml` with
42
+
43
+ ```toml
44
+ destiny-sdk = {path = "./PATH/TO/sdk/", develop = true}
45
+ ```
46
+
47
+ ### Installing a local wheel
48
+
49
+ If you want to use a local build of the sdk `z.whl`, do
50
+
51
+ ```sh
52
+ poetry build
53
+ poetry add ./PATH/TO/WHEEL.whl
54
+ ```
55
+
56
+ ### Publishing to test pypi
57
+
58
+ ```sh
59
+ poetry config repositories.testpypi https://test.pypi.org/legacy/
60
+ poetry config pypi-token.testpypi [YOUR_TESTPYPI_TOKEN]
61
+ poetry publish --repository testpypi
62
+ ```
63
+
64
+ ## Publishing
65
+
66
+ ```sh
67
+ poetry config pypi-token.pypi [YOUR_PYPI_TOKEN]
68
+ poetry publish
69
+ ```
@@ -0,0 +1,40 @@
1
+ [build-system]
2
+ build-backend = "poetry.core.masonry.api"
3
+ requires = ["poetry-core"]
4
+
5
+ [tool.poetry]
6
+ authors = [
7
+ "Adam Hamilton <adam@futureevidence.org>",
8
+ "Andrew Harvey <andrew@futureevidence.org>",
9
+ "Daniel Breves <daniel@futureevidence.org>",
10
+ "Jack Walmisley <jack@futureevidence.org>",
11
+ ]
12
+ description = "A software development kit (sdk) to support interaction with the DESTINY repository"
13
+ license = "Apache 2.0"
14
+ name = "destiny_sdk"
15
+ readme = "README.md"
16
+ version = "0.1.0"
17
+
18
+ [tool.poetry.dependencies]
19
+ cachetools = "^5.5.2"
20
+ fastapi = "^0.115.12"
21
+ httpx = "^0.28.1"
22
+ pydantic = "^2.11.3"
23
+ pytest = "^8.4.0"
24
+ pytest-asyncio = "^1.0.0"
25
+ pytest-httpx = "^0.35.0"
26
+ python = "^3.12"
27
+ python-jose = "^3.4.0"
28
+
29
+ [tool.poetry.group.dev.dependencies]
30
+ mypy = "^1.15.0"
31
+ pytest-env = "^1.1.5"
32
+ ruff = "^0.11.5"
33
+ uvloop = "^0.21.0"
34
+
35
+ [tool.pytest.ini_options]
36
+ addopts = ["--color=yes", "--import-mode=importlib", "--verbose"]
37
+ env = ["ENV=test"]
38
+ norecursedirs = ["tests/e2e"]
39
+ pythonpath = "."
40
+ testpaths = ["tests"]
@@ -0,0 +1,23 @@
1
+ """The DESTINY SDK provides files for interacting with DESTINY repository."""
2
+
3
+ from . import (
4
+ auth,
5
+ client,
6
+ enhancements,
7
+ identifiers,
8
+ imports,
9
+ references,
10
+ robots,
11
+ visibility,
12
+ )
13
+
14
+ __all__ = [
15
+ "auth",
16
+ "client",
17
+ "enhancements",
18
+ "identifiers",
19
+ "imports",
20
+ "references",
21
+ "robots",
22
+ "visibility",
23
+ ]
@@ -0,0 +1,204 @@
1
+ """HMAC authentication assistance methods."""
2
+
3
+ import hashlib
4
+ import hmac
5
+ import time
6
+ from typing import Protocol, Self
7
+ from uuid import UUID
8
+
9
+ from fastapi import HTTPException, Request, status
10
+ from pydantic import UUID4, BaseModel
11
+
12
+ FIVE_MINUTES = 60 * 5
13
+
14
+
15
+ class AuthException(HTTPException):
16
+ """
17
+ An exception related to HTTP authentication.
18
+
19
+ Raised by implementations of the AuthMethod protocol.
20
+
21
+ .. code-block:: python
22
+
23
+ raise AuthException(
24
+ status_code=status.HTTP_401_UNAUTHORIZED,
25
+ detail="Unable to parse authentication token.",
26
+ )
27
+
28
+ """
29
+
30
+
31
+ def create_signature(
32
+ secret_key: str, request_body: bytes, client_id: UUID4, timestamp: float
33
+ ) -> str:
34
+ """
35
+ Create an HMAC signature using SHA256.
36
+
37
+ :param secret_key: secret key with which to encrypt message
38
+ :type secret_key: bytes
39
+ :param request_body: request body to be encrypted
40
+ :type request_body: bytes
41
+ :param client_id: client id to include in hmac
42
+ :type: UUID4
43
+ :param timestamp: timestamp for when the request is sent
44
+ :type: float
45
+ :return: encrypted hexdigest of the request body with the secret key
46
+ :rtype: str
47
+ """
48
+ timestamp_bytes = f"{timestamp}".encode()
49
+ signature_components = b":".join([request_body, client_id.bytes, timestamp_bytes])
50
+ return hmac.new(
51
+ secret_key.encode(), signature_components, hashlib.sha256
52
+ ).hexdigest()
53
+
54
+
55
+ class HMACAuthorizationHeaders(BaseModel):
56
+ """
57
+ The HTTP authorization headers required for HMAC authentication.
58
+
59
+ Expects the following headers to be present in the request
60
+
61
+ - Authorization: Signature [request signature]
62
+ - X-Client-Id: [UUID]
63
+ - X-Request-Timestamp: [float]
64
+ """
65
+
66
+ signature: str
67
+ client_id: UUID4
68
+ timestamp: float
69
+
70
+ @classmethod
71
+ def from_request(cls, request: Request) -> Self:
72
+ """
73
+ Get the required headers for HMAC authentication.
74
+
75
+ :param request: The incoming request
76
+ :type request: Request
77
+ :raises AuthException: Authorization header is missing
78
+ :raises AuthException: Authorization type not supported
79
+ :raises AuthException: X-Client-Id header is missing
80
+ :raises AuthException: Client id format is invalid
81
+ :raises AuthException: X-Request-Timestamp header is missing
82
+ :raises AuthException: Request timestamp has expired
83
+ :return: Header values necessary for authenticating the request
84
+ :rtype: HMACAuthorizationHeaders
85
+ """
86
+ signature_header = request.headers.get("Authorization")
87
+
88
+ if not signature_header:
89
+ raise AuthException(
90
+ status_code=status.HTTP_401_UNAUTHORIZED,
91
+ detail="Authorization header missing.",
92
+ )
93
+
94
+ scheme, _, signature = signature_header.partition(" ")
95
+
96
+ if scheme != "Signature":
97
+ raise AuthException(
98
+ status_code=status.HTTP_401_UNAUTHORIZED,
99
+ detail="Authorization type not supported.",
100
+ )
101
+
102
+ client_id = request.headers.get("X-Client-Id")
103
+
104
+ if not client_id:
105
+ raise AuthException(
106
+ status_code=status.HTTP_401_UNAUTHORIZED,
107
+ detail="X-Client-Id header missing",
108
+ )
109
+
110
+ try:
111
+ UUID(client_id)
112
+ except (ValueError, TypeError) as exc:
113
+ raise AuthException(
114
+ status_code=status.HTTP_401_UNAUTHORIZED,
115
+ detail="Invalid format for client id, expected UUID4.",
116
+ ) from exc
117
+
118
+ timestamp = request.headers.get("X-Request-Timestamp")
119
+
120
+ if not timestamp:
121
+ raise AuthException(
122
+ status_code=status.HTTP_401_UNAUTHORIZED,
123
+ detail="X-Request-Timestamp header missing",
124
+ )
125
+
126
+ if (time.time() - float(timestamp)) > FIVE_MINUTES:
127
+ raise AuthException(
128
+ status_code=status.HTTP_401_UNAUTHORIZED,
129
+ detail="Request timestamp has expired.",
130
+ )
131
+
132
+ return cls(signature=signature, client_id=client_id, timestamp=timestamp)
133
+
134
+
135
+ class HMACAuthMethod(Protocol):
136
+ """
137
+ Protocol for HMAC auth methods, enforcing the implmentation of __call__().
138
+
139
+ This allows FastAPI to call class instances as depenedencies in FastAPI routes,
140
+ see https://fastapi.tiangolo.com/advanced/advanced-dependencies
141
+
142
+ .. code-block:: python
143
+
144
+ auth = HMACAuthMethod()
145
+
146
+ router = APIRouter(
147
+ prefix="/robots", tags=["robot"], dependencies=[Depends(auth)]
148
+ )
149
+ """
150
+
151
+ async def __call__(self, request: Request) -> bool:
152
+ """
153
+ Callable interface to allow use as a dependency.
154
+
155
+ :param request: The request to verify
156
+ :type request: Request
157
+ :raises NotImplementedError: __call__() method has not been implemented.
158
+ :return: True if authorization is successful.
159
+ :rtype: bool
160
+ """
161
+ raise NotImplementedError
162
+
163
+
164
+ class HMACAuth(HMACAuthMethod):
165
+ """Adds HMAC auth when used as a router or endpoint dependency."""
166
+
167
+ def __init__(self, secret_key: str) -> None:
168
+ """Initialise HMAC auth with a given secret key."""
169
+ self.secret_key = secret_key
170
+
171
+ async def __call__(self, request: Request) -> bool:
172
+ """Perform Authorization check."""
173
+ auth_headers = HMACAuthorizationHeaders.from_request(request)
174
+ request_body = await request.body()
175
+ expected_signature = create_signature(
176
+ self.secret_key,
177
+ request_body,
178
+ auth_headers.client_id,
179
+ auth_headers.timestamp,
180
+ )
181
+
182
+ if not hmac.compare_digest(auth_headers.signature, expected_signature):
183
+ raise AuthException(
184
+ status_code=status.HTTP_401_UNAUTHORIZED, detail="Signature is invalid."
185
+ )
186
+
187
+ return True
188
+
189
+
190
+ class BypassHMACAuth(HMACAuthMethod):
191
+ """
192
+ A fake auth class that will always respond successfully.
193
+
194
+ Intended for use in local environments and for testing.
195
+
196
+ Not for production use!
197
+ """
198
+
199
+ async def __call__(
200
+ self,
201
+ request: Request, # noqa: ARG002
202
+ ) -> bool:
203
+ """Bypass Authorization check."""
204
+ return True
@@ -0,0 +1,113 @@
1
+ """Send authenticated requests to Destiny Repository."""
2
+
3
+ import time
4
+ from collections.abc import Generator
5
+
6
+ import httpx
7
+ from pydantic import UUID4, HttpUrl
8
+
9
+ from destiny_sdk.robots import (
10
+ BatchEnhancementRequestRead,
11
+ BatchRobotResult,
12
+ EnhancementRequestRead,
13
+ RobotResult,
14
+ )
15
+
16
+ from .auth import create_signature
17
+
18
+
19
+ class HMACSigningAuth(httpx.Auth):
20
+ """Client that adds an HMAC signature to a request."""
21
+
22
+ requires_request_body = True
23
+
24
+ def __init__(self, secret_key: str, client_id: UUID4) -> None:
25
+ """
26
+ Initialize the client.
27
+
28
+ :param secret_key: the key to use when signing the request
29
+ :type secret_key: str
30
+ """
31
+ self.secret_key = secret_key
32
+ self.client_id = client_id
33
+
34
+ def auth_flow(
35
+ self, request: httpx.Request
36
+ ) -> Generator[httpx.Request, httpx.Response]:
37
+ """
38
+ Add a signature to the given request.
39
+
40
+ :param request: request to be sent with signature
41
+ :type request: httpx.Request
42
+ :yield: Generator for Request with signature headers set
43
+ :rtype: Generator[httpx.Request, httpx.Response]
44
+ """
45
+ timestamp = time.time()
46
+ signature = create_signature(
47
+ self.secret_key, request.content, self.client_id, timestamp
48
+ )
49
+ request.headers["Authorization"] = f"Signature {signature}"
50
+ request.headers["X-Client-Id"] = f"{self.client_id}"
51
+ request.headers["X-Request-Timestamp"] = f"{timestamp}"
52
+ yield request
53
+
54
+
55
+ class Client:
56
+ """
57
+ Client for interaction with the Destiny API.
58
+
59
+ Current implementation only supports robot results.
60
+ """
61
+
62
+ def __init__(self, base_url: HttpUrl, secret_key: str, client_id: UUID4) -> None:
63
+ """
64
+ Initialize the client.
65
+
66
+ :param base_url: The base URL for the Destiny Repository API.
67
+ :type base_url: HttpUrl
68
+ :param secret_key: The secret key for signing requests
69
+ :type auth_method: str
70
+ """
71
+ self.session = httpx.Client(
72
+ base_url=str(base_url),
73
+ headers={"Content-Type": "application/json"},
74
+ auth=HMACSigningAuth(secret_key=secret_key, client_id=client_id),
75
+ )
76
+
77
+ def send_robot_result(self, robot_result: RobotResult) -> EnhancementRequestRead:
78
+ """
79
+ Send a RobotResult to destiny repository.
80
+
81
+ Signs the request with the client's secret key.
82
+
83
+ :param robot_result: The Robot Result to send
84
+ :type robot_result: RobotResult
85
+ :return: The EnhancementRequestRead object from the response.
86
+ :rtype: EnhancementRequestRead
87
+ """
88
+ response = self.session.post(
89
+ "/robot/enhancement/single/",
90
+ json=robot_result.model_dump(mode="json"),
91
+ )
92
+ response.raise_for_status()
93
+ return EnhancementRequestRead.model_validate(response.json())
94
+
95
+ def send_batch_robot_result(
96
+ self, batch_robot_result: BatchRobotResult
97
+ ) -> BatchEnhancementRequestRead:
98
+ """
99
+ Send a BatchRobotResult to destiny repository.
100
+
101
+ Signs the request with the client's secret key.
102
+
103
+ :param batch_robot_result: The Batch Robot Result to send
104
+ :type batch_robot_result: BatchRobotResult
105
+ :return: The BatchEnhancementRequestRead object from the response.
106
+ :rtype: BatchEnhancementRequestRead
107
+ """
108
+ response = self.session.post(
109
+ "/robot/enhancement/batch/",
110
+ json=batch_robot_result.model_dump(mode="json"),
111
+ )
112
+ response.raise_for_status()
113
+ return BatchEnhancementRequestRead.model_validate(response.json())
@@ -0,0 +1,35 @@
1
+ """Core classes for the Destiny SDK, not exposed to package users."""
2
+
3
+ from typing import Self
4
+
5
+ from pydantic import BaseModel
6
+
7
+
8
+ class _JsonlFileInputMixIn(BaseModel):
9
+ """
10
+ A mixin class for models that are used at the top-level for entries in .jsonl files.
11
+
12
+ This class is used to define a common interface for file input models.
13
+ It is not intended to be used directly.
14
+ """
15
+
16
+ def to_jsonl(self) -> str:
17
+ """
18
+ Convert the model to a JSONL string.
19
+
20
+ :return: The JSONL string representation of the model.
21
+ :rtype: str
22
+ """
23
+ return self.model_dump_json(exclude_none=True)
24
+
25
+ @classmethod
26
+ def from_jsonl(cls, jsonl: str) -> Self:
27
+ """
28
+ Create an object from a JSONL string.
29
+
30
+ :param jsonl: The JSONL string to parse.
31
+ :type jsonl: str
32
+ :return: The created object.
33
+ :rtype: Self
34
+ """
35
+ return cls.model_validate_json(jsonl)