labqoat 0.1.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.
- labqoat/__init__.py +416 -0
- labqoat/analytics/__init__.py +192 -0
- labqoat/analytics_contracts.py +508 -0
- labqoat/api.py +68 -0
- labqoat/argument_codec.py +551 -0
- labqoat/assets/__init__.py +58 -0
- labqoat/assets/cache.py +226 -0
- labqoat/assets/derivations.py +142 -0
- labqoat/assets/domain.py +183 -0
- labqoat/assets/namespace.py +539 -0
- labqoat/assets/service.py +321 -0
- labqoat/assets/store.py +106 -0
- labqoat/async_client.py +107 -0
- labqoat/auth.py +146 -0
- labqoat/aws_identity.py +329 -0
- labqoat/checkpoint_contracts.py +350 -0
- labqoat/checkpoints.py +156 -0
- labqoat/client.py +93 -0
- labqoat/contract_artifacts.py +178 -0
- labqoat/contract_registry.py +140 -0
- labqoat/contracts/__init__.py +101 -0
- labqoat/contracts/attestation.py +168 -0
- labqoat/contracts/audio.py +166 -0
- labqoat/contracts/compatibility.py +288 -0
- labqoat/contracts/compiler.py +927 -0
- labqoat/contracts/declarations.py +210 -0
- labqoat/contracts/fixtures.py +23 -0
- labqoat/contracts/validation.py +415 -0
- labqoat/dataset_contracts.py +320 -0
- labqoat/datasets/__init__.py +832 -0
- labqoat/deployment.py +27 -0
- labqoat/errors.py +98 -0
- labqoat/evaluation_worker.py +177 -0
- labqoat/evaluations/__init__.py +398 -0
- labqoat/events.py +300 -0
- labqoat/identity.py +446 -0
- labqoat/images.py +63 -0
- labqoat/import_worker.py +208 -0
- labqoat/imports/__init__.py +368 -0
- labqoat/imports/sources.py +235 -0
- labqoat/migration/__init__.py +53 -0
- labqoat/model_contracts.py +898 -0
- labqoat/model_registry_client.py +483 -0
- labqoat/models/__init__.py +329 -0
- labqoat/nodes.py +478 -0
- labqoat/platform.py +191 -0
- labqoat/publication_contracts.py +566 -0
- labqoat/py.typed +1 -0
- labqoat/references.py +261 -0
- labqoat/resources.py +83 -0
- labqoat/retry.py +212 -0
- labqoat/run_contracts.py +505 -0
- labqoat/runs.py +990 -0
- labqoat/staging.py +243 -0
- labqoat/training/__init__.py +414 -0
- labqoat/training/runtime.py +396 -0
- labqoat/training_worker.py +196 -0
- labqoat/transform_worker.py +182 -0
- labqoat/transforms/__init__.py +555 -0
- labqoat/transport.py +198 -0
- labqoat/wire.py +87 -0
- labqoat/workload_client.py +664 -0
- labqoat/workload_contracts.py +136 -0
- labqoat/workloads.py +239 -0
- labqoat-0.1.0.dist-info/METADATA +86 -0
- labqoat-0.1.0.dist-info/RECORD +85 -0
- labqoat-0.1.0.dist-info/WHEEL +4 -0
- labqoat-0.1.0.dist-info/entry_points.txt +2 -0
- labqoat-0.1.0.dist-info/licenses/LICENSE +4 -0
- labqoat_cli/__init__.py +1 -0
- labqoat_cli/asset_download.py +78 -0
- labqoat_cli/cloud_builder.py +562 -0
- labqoat_cli/commands.py +1360 -0
- labqoat_cli/connection.py +325 -0
- labqoat_cli/evaluation_arguments.py +436 -0
- labqoat_cli/image_builder.py +58 -0
- labqoat_cli/local_context.py +314 -0
- labqoat_cli/main.py +3001 -0
- labqoat_cli/model_development.py +399 -0
- labqoat_cli/project.py +150 -0
- labqoat_cli/py.typed +1 -0
- labqoat_cli/rendering.py +181 -0
- labqoat_cli/scaffolding.py +563 -0
- labqoat_cli/verification.py +126 -0
- labqoat_cli/workspace.py +91 -0
labqoat/__init__.py
ADDED
|
@@ -0,0 +1,416 @@
|
|
|
1
|
+
"""Typed Python SDK for the Labqoat private ML platform."""
|
|
2
|
+
|
|
3
|
+
from labqoat.analytics import (
|
|
4
|
+
AnalyticsNamespace,
|
|
5
|
+
AnalyticsQuery,
|
|
6
|
+
AnalyticsResult,
|
|
7
|
+
AsyncAnalyticsNamespace,
|
|
8
|
+
LocalSnapshotMetadata,
|
|
9
|
+
QueryFilter,
|
|
10
|
+
QueryFilterOperator,
|
|
11
|
+
QueryMeasure,
|
|
12
|
+
QueryMeasureFunction,
|
|
13
|
+
QueryOrderDirection,
|
|
14
|
+
QueryOrdering,
|
|
15
|
+
QueryReceipt,
|
|
16
|
+
QueryScalar,
|
|
17
|
+
QueryValue,
|
|
18
|
+
)
|
|
19
|
+
from labqoat.async_client import AsyncLabqoatClient
|
|
20
|
+
from labqoat.auth import (
|
|
21
|
+
AsyncSessionProvider,
|
|
22
|
+
ClientEnvironment,
|
|
23
|
+
PlatformSession,
|
|
24
|
+
SessionProvider,
|
|
25
|
+
StaticAsyncSessionProvider,
|
|
26
|
+
StaticSessionProvider,
|
|
27
|
+
)
|
|
28
|
+
from labqoat.checkpoint_contracts import (
|
|
29
|
+
Checkpoint,
|
|
30
|
+
CheckpointMember,
|
|
31
|
+
CheckpointRole,
|
|
32
|
+
)
|
|
33
|
+
from labqoat.client import LabqoatClient
|
|
34
|
+
from labqoat.contract_artifacts import ContractArtifact
|
|
35
|
+
from labqoat.contracts import (
|
|
36
|
+
Between,
|
|
37
|
+
ContractDefinition,
|
|
38
|
+
ContractKind,
|
|
39
|
+
Field,
|
|
40
|
+
Length,
|
|
41
|
+
NonEmpty,
|
|
42
|
+
Positive,
|
|
43
|
+
dataset_contract,
|
|
44
|
+
model_request_contract,
|
|
45
|
+
model_response_contract,
|
|
46
|
+
)
|
|
47
|
+
from labqoat.dataset_contracts import (
|
|
48
|
+
DatasetCard,
|
|
49
|
+
DatasetRepositoryRecord,
|
|
50
|
+
DatasetRepositorySpec,
|
|
51
|
+
)
|
|
52
|
+
from labqoat.datasets import (
|
|
53
|
+
DatasetInspection,
|
|
54
|
+
DatasetLineage,
|
|
55
|
+
DatasetRevisionSummary,
|
|
56
|
+
DatasetTag,
|
|
57
|
+
DatasetValidation,
|
|
58
|
+
)
|
|
59
|
+
from labqoat.errors import (
|
|
60
|
+
AuthenticationRequired,
|
|
61
|
+
CapacityUnavailable,
|
|
62
|
+
Conflict,
|
|
63
|
+
ContractIncompatible,
|
|
64
|
+
ErrorDetail,
|
|
65
|
+
InvalidRequest,
|
|
66
|
+
LabqoatError,
|
|
67
|
+
NetworkUnavailable,
|
|
68
|
+
NotFound,
|
|
69
|
+
OperationFailed,
|
|
70
|
+
RateLimited,
|
|
71
|
+
TransportFailure,
|
|
72
|
+
)
|
|
73
|
+
from labqoat.evaluations import (
|
|
74
|
+
AsyncEvaluationsNamespace,
|
|
75
|
+
Evaluation,
|
|
76
|
+
EvaluationContext,
|
|
77
|
+
EvaluationProgress,
|
|
78
|
+
EvaluationRunRef,
|
|
79
|
+
EvaluationsNamespace,
|
|
80
|
+
EvaluationState,
|
|
81
|
+
EvaluationSubmitter,
|
|
82
|
+
TrainingWithEvaluationsProgress,
|
|
83
|
+
)
|
|
84
|
+
from labqoat.events import (
|
|
85
|
+
CheckpointPublished,
|
|
86
|
+
EvaluationSubmitted,
|
|
87
|
+
RunEvent,
|
|
88
|
+
RunEventPage,
|
|
89
|
+
RunProgressed,
|
|
90
|
+
RunStateChanged,
|
|
91
|
+
)
|
|
92
|
+
from labqoat.identity import (
|
|
93
|
+
AuthChallenge,
|
|
94
|
+
AuthResult,
|
|
95
|
+
AwsIdentity,
|
|
96
|
+
DiagnosticCheck,
|
|
97
|
+
DiagnosticStatus,
|
|
98
|
+
Doctor,
|
|
99
|
+
HumanAuthenticator,
|
|
100
|
+
PlatformSessionExchange,
|
|
101
|
+
SignedAwsAssertion,
|
|
102
|
+
)
|
|
103
|
+
from labqoat.imports import (
|
|
104
|
+
AsyncImportsNamespace,
|
|
105
|
+
ExternalParquetAdapter,
|
|
106
|
+
FrozenManifestObject,
|
|
107
|
+
FrozenParquetObject,
|
|
108
|
+
FrozenSourceObject,
|
|
109
|
+
ImmutableManifestAdapter,
|
|
110
|
+
ImportContext,
|
|
111
|
+
ImportJob,
|
|
112
|
+
ImportRunRef,
|
|
113
|
+
ImportsNamespace,
|
|
114
|
+
ImportSourceError,
|
|
115
|
+
PublicationFinalizer,
|
|
116
|
+
SourceInspection,
|
|
117
|
+
SourceKind,
|
|
118
|
+
)
|
|
119
|
+
from labqoat.migration import DatasetResolution, DatasetStorageBackend
|
|
120
|
+
from labqoat.model_contracts import (
|
|
121
|
+
ModelBuild,
|
|
122
|
+
ModelBuildSpec,
|
|
123
|
+
ModelDefinition,
|
|
124
|
+
ModelDefinitionSpec,
|
|
125
|
+
ModelInvocationResult,
|
|
126
|
+
ModelInvocationSpec,
|
|
127
|
+
ModelPromotion,
|
|
128
|
+
ModelRelease,
|
|
129
|
+
ModelReleaseSpec,
|
|
130
|
+
ModelReleaseView,
|
|
131
|
+
ReleaseState,
|
|
132
|
+
)
|
|
133
|
+
from labqoat.models import ModelBuildManifest, ModelReleaseManifest
|
|
134
|
+
from labqoat.nodes import (
|
|
135
|
+
AsyncNodesNamespace,
|
|
136
|
+
CandidateEvaluation,
|
|
137
|
+
CapacityLimit,
|
|
138
|
+
CapacityPool,
|
|
139
|
+
ClusterNode,
|
|
140
|
+
NodeProvider,
|
|
141
|
+
NodesNamespace,
|
|
142
|
+
NodeState,
|
|
143
|
+
PlacementExplanation,
|
|
144
|
+
)
|
|
145
|
+
from labqoat.platform import (
|
|
146
|
+
PlatformDeployment,
|
|
147
|
+
PlatformPanel,
|
|
148
|
+
PlatformStatus,
|
|
149
|
+
resolve_panel_endpoint,
|
|
150
|
+
)
|
|
151
|
+
from labqoat.publication_contracts import (
|
|
152
|
+
DatasetPublication,
|
|
153
|
+
PublicationAttestation,
|
|
154
|
+
PublicationFile,
|
|
155
|
+
PublicationLineage,
|
|
156
|
+
PublicationReceipt,
|
|
157
|
+
PublicationShard,
|
|
158
|
+
PublicationSplit,
|
|
159
|
+
PublicationStatistics,
|
|
160
|
+
)
|
|
161
|
+
from labqoat.references import (
|
|
162
|
+
ArtifactRef,
|
|
163
|
+
AssetRef,
|
|
164
|
+
AudioRef,
|
|
165
|
+
CheckpointRef,
|
|
166
|
+
ContractRef,
|
|
167
|
+
DatasetRef,
|
|
168
|
+
ModelRef,
|
|
169
|
+
ResolvedDatasetRef,
|
|
170
|
+
ResourceId,
|
|
171
|
+
Sha256,
|
|
172
|
+
)
|
|
173
|
+
from labqoat.resources import CpuResources, GpuModel, GpuResources, Placement
|
|
174
|
+
from labqoat.runs import (
|
|
175
|
+
ModelDependency,
|
|
176
|
+
Run,
|
|
177
|
+
RunDefinition,
|
|
178
|
+
RunExecution,
|
|
179
|
+
RunLog,
|
|
180
|
+
RunLogPage,
|
|
181
|
+
RunOutput,
|
|
182
|
+
RunShard,
|
|
183
|
+
RunState,
|
|
184
|
+
RunSubmission,
|
|
185
|
+
ShardState,
|
|
186
|
+
WorkloadKind,
|
|
187
|
+
canonical_parameter_sha256,
|
|
188
|
+
)
|
|
189
|
+
from labqoat.staging import ParquetStager, S3ParquetStager, S3PutClient
|
|
190
|
+
from labqoat.training import (
|
|
191
|
+
AsyncTrainingNamespace,
|
|
192
|
+
TrainingContext,
|
|
193
|
+
TrainingJob,
|
|
194
|
+
TrainingNamespace,
|
|
195
|
+
TrainingRunRef,
|
|
196
|
+
)
|
|
197
|
+
from labqoat.transforms import (
|
|
198
|
+
AsyncTransformsNamespace,
|
|
199
|
+
BatchTransform,
|
|
200
|
+
FailurePolicy,
|
|
201
|
+
FlatMapTransform,
|
|
202
|
+
IdentifiedRow,
|
|
203
|
+
MapTransform,
|
|
204
|
+
TransformContext,
|
|
205
|
+
TransformJob,
|
|
206
|
+
TransformRunRef,
|
|
207
|
+
TransformsNamespace,
|
|
208
|
+
dataset_flat_map,
|
|
209
|
+
dataset_map,
|
|
210
|
+
dataset_map_batches,
|
|
211
|
+
)
|
|
212
|
+
from labqoat.workload_client import WorkerClient, WorkerEnvironment, WorkerInput
|
|
213
|
+
from labqoat.workloads import (
|
|
214
|
+
HeartbeatReceipt,
|
|
215
|
+
LogSeverity,
|
|
216
|
+
WorkerAssignment,
|
|
217
|
+
WorkerContext,
|
|
218
|
+
WorkerControl,
|
|
219
|
+
WorkerLog,
|
|
220
|
+
WorkerProgress,
|
|
221
|
+
WorkerProtocolError,
|
|
222
|
+
)
|
|
223
|
+
|
|
224
|
+
__all__ = [
|
|
225
|
+
"AnalyticsNamespace",
|
|
226
|
+
"AnalyticsQuery",
|
|
227
|
+
"AnalyticsResult",
|
|
228
|
+
"ArtifactRef",
|
|
229
|
+
"AssetRef",
|
|
230
|
+
"AsyncAnalyticsNamespace",
|
|
231
|
+
"AsyncEvaluationsNamespace",
|
|
232
|
+
"AsyncImportsNamespace",
|
|
233
|
+
"AsyncLabqoatClient",
|
|
234
|
+
"AsyncNodesNamespace",
|
|
235
|
+
"AsyncSessionProvider",
|
|
236
|
+
"AsyncTrainingNamespace",
|
|
237
|
+
"AsyncTransformsNamespace",
|
|
238
|
+
"AudioRef",
|
|
239
|
+
"AuthChallenge",
|
|
240
|
+
"AuthResult",
|
|
241
|
+
"AuthenticationRequired",
|
|
242
|
+
"AwsIdentity",
|
|
243
|
+
"BatchTransform",
|
|
244
|
+
"Between",
|
|
245
|
+
"CandidateEvaluation",
|
|
246
|
+
"CapacityLimit",
|
|
247
|
+
"CapacityPool",
|
|
248
|
+
"CapacityUnavailable",
|
|
249
|
+
"Checkpoint",
|
|
250
|
+
"CheckpointMember",
|
|
251
|
+
"CheckpointPublished",
|
|
252
|
+
"CheckpointRef",
|
|
253
|
+
"CheckpointRole",
|
|
254
|
+
"ClientEnvironment",
|
|
255
|
+
"ClusterNode",
|
|
256
|
+
"Conflict",
|
|
257
|
+
"ContractArtifact",
|
|
258
|
+
"ContractDefinition",
|
|
259
|
+
"ContractIncompatible",
|
|
260
|
+
"ContractKind",
|
|
261
|
+
"ContractRef",
|
|
262
|
+
"CpuResources",
|
|
263
|
+
"DatasetCard",
|
|
264
|
+
"DatasetInspection",
|
|
265
|
+
"DatasetLineage",
|
|
266
|
+
"DatasetPublication",
|
|
267
|
+
"DatasetRef",
|
|
268
|
+
"DatasetRepositoryRecord",
|
|
269
|
+
"DatasetRepositorySpec",
|
|
270
|
+
"DatasetResolution",
|
|
271
|
+
"DatasetRevisionSummary",
|
|
272
|
+
"DatasetStorageBackend",
|
|
273
|
+
"DatasetTag",
|
|
274
|
+
"DatasetValidation",
|
|
275
|
+
"DiagnosticCheck",
|
|
276
|
+
"DiagnosticStatus",
|
|
277
|
+
"Doctor",
|
|
278
|
+
"ErrorDetail",
|
|
279
|
+
"Evaluation",
|
|
280
|
+
"EvaluationContext",
|
|
281
|
+
"EvaluationProgress",
|
|
282
|
+
"EvaluationRunRef",
|
|
283
|
+
"EvaluationState",
|
|
284
|
+
"EvaluationSubmitted",
|
|
285
|
+
"EvaluationSubmitter",
|
|
286
|
+
"EvaluationsNamespace",
|
|
287
|
+
"ExternalParquetAdapter",
|
|
288
|
+
"FailurePolicy",
|
|
289
|
+
"Field",
|
|
290
|
+
"FlatMapTransform",
|
|
291
|
+
"FrozenManifestObject",
|
|
292
|
+
"FrozenParquetObject",
|
|
293
|
+
"FrozenSourceObject",
|
|
294
|
+
"GpuModel",
|
|
295
|
+
"GpuResources",
|
|
296
|
+
"HeartbeatReceipt",
|
|
297
|
+
"HumanAuthenticator",
|
|
298
|
+
"IdentifiedRow",
|
|
299
|
+
"ImmutableManifestAdapter",
|
|
300
|
+
"ImportContext",
|
|
301
|
+
"ImportJob",
|
|
302
|
+
"ImportRunRef",
|
|
303
|
+
"ImportSourceError",
|
|
304
|
+
"ImportsNamespace",
|
|
305
|
+
"InvalidRequest",
|
|
306
|
+
"LabqoatClient",
|
|
307
|
+
"LabqoatError",
|
|
308
|
+
"Length",
|
|
309
|
+
"LocalSnapshotMetadata",
|
|
310
|
+
"LogSeverity",
|
|
311
|
+
"MapTransform",
|
|
312
|
+
"ModelBuild",
|
|
313
|
+
"ModelBuildManifest",
|
|
314
|
+
"ModelBuildSpec",
|
|
315
|
+
"ModelDefinition",
|
|
316
|
+
"ModelDefinitionSpec",
|
|
317
|
+
"ModelDependency",
|
|
318
|
+
"ModelInvocationResult",
|
|
319
|
+
"ModelInvocationSpec",
|
|
320
|
+
"ModelPromotion",
|
|
321
|
+
"ModelRef",
|
|
322
|
+
"ModelRelease",
|
|
323
|
+
"ModelReleaseManifest",
|
|
324
|
+
"ModelReleaseSpec",
|
|
325
|
+
"ModelReleaseView",
|
|
326
|
+
"NetworkUnavailable",
|
|
327
|
+
"NodeProvider",
|
|
328
|
+
"NodeState",
|
|
329
|
+
"NodesNamespace",
|
|
330
|
+
"NonEmpty",
|
|
331
|
+
"NotFound",
|
|
332
|
+
"OperationFailed",
|
|
333
|
+
"ParquetStager",
|
|
334
|
+
"Placement",
|
|
335
|
+
"PlacementExplanation",
|
|
336
|
+
"PlatformDeployment",
|
|
337
|
+
"PlatformPanel",
|
|
338
|
+
"PlatformSession",
|
|
339
|
+
"PlatformSessionExchange",
|
|
340
|
+
"PlatformStatus",
|
|
341
|
+
"Positive",
|
|
342
|
+
"PublicationAttestation",
|
|
343
|
+
"PublicationFile",
|
|
344
|
+
"PublicationFinalizer",
|
|
345
|
+
"PublicationLineage",
|
|
346
|
+
"PublicationReceipt",
|
|
347
|
+
"PublicationShard",
|
|
348
|
+
"PublicationSplit",
|
|
349
|
+
"PublicationStatistics",
|
|
350
|
+
"QueryFilter",
|
|
351
|
+
"QueryFilterOperator",
|
|
352
|
+
"QueryMeasure",
|
|
353
|
+
"QueryMeasureFunction",
|
|
354
|
+
"QueryOrderDirection",
|
|
355
|
+
"QueryOrdering",
|
|
356
|
+
"QueryReceipt",
|
|
357
|
+
"QueryScalar",
|
|
358
|
+
"QueryValue",
|
|
359
|
+
"RateLimited",
|
|
360
|
+
"ReleaseState",
|
|
361
|
+
"ResolvedDatasetRef",
|
|
362
|
+
"ResourceId",
|
|
363
|
+
"Run",
|
|
364
|
+
"RunDefinition",
|
|
365
|
+
"RunEvent",
|
|
366
|
+
"RunEventPage",
|
|
367
|
+
"RunExecution",
|
|
368
|
+
"RunLog",
|
|
369
|
+
"RunLogPage",
|
|
370
|
+
"RunOutput",
|
|
371
|
+
"RunProgressed",
|
|
372
|
+
"RunShard",
|
|
373
|
+
"RunState",
|
|
374
|
+
"RunStateChanged",
|
|
375
|
+
"RunSubmission",
|
|
376
|
+
"S3ParquetStager",
|
|
377
|
+
"S3PutClient",
|
|
378
|
+
"SessionProvider",
|
|
379
|
+
"Sha256",
|
|
380
|
+
"ShardState",
|
|
381
|
+
"SignedAwsAssertion",
|
|
382
|
+
"SourceInspection",
|
|
383
|
+
"SourceKind",
|
|
384
|
+
"StaticAsyncSessionProvider",
|
|
385
|
+
"StaticSessionProvider",
|
|
386
|
+
"TrainingContext",
|
|
387
|
+
"TrainingJob",
|
|
388
|
+
"TrainingNamespace",
|
|
389
|
+
"TrainingRunRef",
|
|
390
|
+
"TrainingWithEvaluationsProgress",
|
|
391
|
+
"TransformContext",
|
|
392
|
+
"TransformJob",
|
|
393
|
+
"TransformRunRef",
|
|
394
|
+
"TransformsNamespace",
|
|
395
|
+
"TransportFailure",
|
|
396
|
+
"WorkerAssignment",
|
|
397
|
+
"WorkerClient",
|
|
398
|
+
"WorkerContext",
|
|
399
|
+
"WorkerControl",
|
|
400
|
+
"WorkerEnvironment",
|
|
401
|
+
"WorkerInput",
|
|
402
|
+
"WorkerLog",
|
|
403
|
+
"WorkerProgress",
|
|
404
|
+
"WorkerProtocolError",
|
|
405
|
+
"WorkloadKind",
|
|
406
|
+
"canonical_parameter_sha256",
|
|
407
|
+
"dataset_contract",
|
|
408
|
+
"dataset_flat_map",
|
|
409
|
+
"dataset_map",
|
|
410
|
+
"dataset_map_batches",
|
|
411
|
+
"model_request_contract",
|
|
412
|
+
"model_response_contract",
|
|
413
|
+
"resolve_panel_endpoint",
|
|
414
|
+
]
|
|
415
|
+
|
|
416
|
+
__version__ = "0.1.0"
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
"""Snapshot-consistent analytics client namespaces and public contracts."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import TYPE_CHECKING
|
|
6
|
+
|
|
7
|
+
from labqoat.analytics_contracts import (
|
|
8
|
+
AnalyticsQuery,
|
|
9
|
+
AnalyticsResult,
|
|
10
|
+
LocalSnapshotMetadata,
|
|
11
|
+
QueryFilter,
|
|
12
|
+
QueryFilterOperator,
|
|
13
|
+
QueryMeasure,
|
|
14
|
+
QueryMeasureFunction,
|
|
15
|
+
QueryOrderDirection,
|
|
16
|
+
QueryOrdering,
|
|
17
|
+
QueryReceipt,
|
|
18
|
+
QueryScalar,
|
|
19
|
+
QueryValue,
|
|
20
|
+
analytics_query_document,
|
|
21
|
+
analytics_result_document,
|
|
22
|
+
analytics_sample_document,
|
|
23
|
+
parse_analytics_query,
|
|
24
|
+
parse_analytics_result,
|
|
25
|
+
parse_analytics_sample,
|
|
26
|
+
)
|
|
27
|
+
from labqoat.transport import HttpMethod, RequestTimeout, TransportRequest
|
|
28
|
+
|
|
29
|
+
if TYPE_CHECKING:
|
|
30
|
+
from labqoat.auth import AsyncSessionProvider, SessionProvider
|
|
31
|
+
from labqoat.references import DatasetRef
|
|
32
|
+
from labqoat.retry import AsyncRequestExecutor, SyncRequestExecutor
|
|
33
|
+
|
|
34
|
+
_QUERY_TIMEOUT = RequestTimeout(connect_seconds=5, total_seconds=120)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class AnalyticsNamespace:
|
|
38
|
+
"""Blocking snapshot-consistent analytics operations."""
|
|
39
|
+
|
|
40
|
+
__slots__ = ("_executor", "_sessions")
|
|
41
|
+
|
|
42
|
+
def __init__(
|
|
43
|
+
self,
|
|
44
|
+
executor: SyncRequestExecutor,
|
|
45
|
+
sessions: SessionProvider,
|
|
46
|
+
) -> None:
|
|
47
|
+
self._executor = executor
|
|
48
|
+
self._sessions = sessions
|
|
49
|
+
|
|
50
|
+
def query[RowT](
|
|
51
|
+
self,
|
|
52
|
+
dataset: DatasetRef[RowT],
|
|
53
|
+
query: AnalyticsQuery,
|
|
54
|
+
*,
|
|
55
|
+
idempotency_key: str,
|
|
56
|
+
) -> AnalyticsResult:
|
|
57
|
+
"""Execute one bounded validated query against a resolved snapshot."""
|
|
58
|
+
response = self._executor.execute(
|
|
59
|
+
_query_request(
|
|
60
|
+
dataset,
|
|
61
|
+
query,
|
|
62
|
+
idempotency_key,
|
|
63
|
+
self._sessions.session().authorization_header(),
|
|
64
|
+
)
|
|
65
|
+
)
|
|
66
|
+
return parse_analytics_result(response.body)
|
|
67
|
+
|
|
68
|
+
def sample[RowT](
|
|
69
|
+
self,
|
|
70
|
+
dataset: DatasetRef[RowT],
|
|
71
|
+
*,
|
|
72
|
+
limit: int = 10,
|
|
73
|
+
idempotency_key: str,
|
|
74
|
+
) -> AnalyticsResult:
|
|
75
|
+
"""Return bounded complete records from one resolved snapshot."""
|
|
76
|
+
response = self._executor.execute(
|
|
77
|
+
_sample_request(
|
|
78
|
+
dataset,
|
|
79
|
+
limit,
|
|
80
|
+
idempotency_key,
|
|
81
|
+
self._sessions.session().authorization_header(),
|
|
82
|
+
)
|
|
83
|
+
)
|
|
84
|
+
return parse_analytics_result(response.body)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
class AsyncAnalyticsNamespace:
|
|
88
|
+
"""Non-blocking snapshot-consistent analytics operations."""
|
|
89
|
+
|
|
90
|
+
__slots__ = ("_executor", "_sessions")
|
|
91
|
+
|
|
92
|
+
def __init__(
|
|
93
|
+
self,
|
|
94
|
+
executor: AsyncRequestExecutor,
|
|
95
|
+
sessions: AsyncSessionProvider,
|
|
96
|
+
) -> None:
|
|
97
|
+
self._executor = executor
|
|
98
|
+
self._sessions = sessions
|
|
99
|
+
|
|
100
|
+
async def query[RowT](
|
|
101
|
+
self,
|
|
102
|
+
dataset: DatasetRef[RowT],
|
|
103
|
+
query: AnalyticsQuery,
|
|
104
|
+
*,
|
|
105
|
+
idempotency_key: str,
|
|
106
|
+
) -> AnalyticsResult:
|
|
107
|
+
"""Execute one bounded validated query without blocking."""
|
|
108
|
+
session = await self._sessions.session()
|
|
109
|
+
response = await self._executor.execute(
|
|
110
|
+
_query_request(
|
|
111
|
+
dataset,
|
|
112
|
+
query,
|
|
113
|
+
idempotency_key,
|
|
114
|
+
session.authorization_header(),
|
|
115
|
+
)
|
|
116
|
+
)
|
|
117
|
+
return parse_analytics_result(response.body)
|
|
118
|
+
|
|
119
|
+
async def sample[RowT](
|
|
120
|
+
self,
|
|
121
|
+
dataset: DatasetRef[RowT],
|
|
122
|
+
*,
|
|
123
|
+
limit: int = 10,
|
|
124
|
+
idempotency_key: str,
|
|
125
|
+
) -> AnalyticsResult:
|
|
126
|
+
"""Return bounded complete records from one resolved snapshot."""
|
|
127
|
+
session = await self._sessions.session()
|
|
128
|
+
response = await self._executor.execute(
|
|
129
|
+
_sample_request(
|
|
130
|
+
dataset,
|
|
131
|
+
limit,
|
|
132
|
+
idempotency_key,
|
|
133
|
+
session.authorization_header(),
|
|
134
|
+
)
|
|
135
|
+
)
|
|
136
|
+
return parse_analytics_result(response.body)
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def _query_request[RowT](
|
|
140
|
+
dataset: DatasetRef[RowT],
|
|
141
|
+
query: AnalyticsQuery,
|
|
142
|
+
idempotency_key: str,
|
|
143
|
+
authorization: tuple[str, str],
|
|
144
|
+
) -> TransportRequest:
|
|
145
|
+
return TransportRequest(
|
|
146
|
+
method=HttpMethod.POST,
|
|
147
|
+
path="/v1/analytics/query",
|
|
148
|
+
timeout=_QUERY_TIMEOUT,
|
|
149
|
+
headers=(authorization,),
|
|
150
|
+
body=analytics_query_document(dataset, query),
|
|
151
|
+
idempotency_key=idempotency_key,
|
|
152
|
+
)
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def _sample_request[RowT](
|
|
156
|
+
dataset: DatasetRef[RowT],
|
|
157
|
+
limit: int,
|
|
158
|
+
idempotency_key: str,
|
|
159
|
+
authorization: tuple[str, str],
|
|
160
|
+
) -> TransportRequest:
|
|
161
|
+
return TransportRequest(
|
|
162
|
+
method=HttpMethod.POST,
|
|
163
|
+
path="/v1/analytics/sample",
|
|
164
|
+
timeout=_QUERY_TIMEOUT,
|
|
165
|
+
headers=(authorization,),
|
|
166
|
+
body=analytics_sample_document(dataset, limit),
|
|
167
|
+
idempotency_key=idempotency_key,
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
__all__ = [
|
|
172
|
+
"AnalyticsNamespace",
|
|
173
|
+
"AnalyticsQuery",
|
|
174
|
+
"AnalyticsResult",
|
|
175
|
+
"AsyncAnalyticsNamespace",
|
|
176
|
+
"LocalSnapshotMetadata",
|
|
177
|
+
"QueryFilter",
|
|
178
|
+
"QueryFilterOperator",
|
|
179
|
+
"QueryMeasure",
|
|
180
|
+
"QueryMeasureFunction",
|
|
181
|
+
"QueryOrderDirection",
|
|
182
|
+
"QueryOrdering",
|
|
183
|
+
"QueryReceipt",
|
|
184
|
+
"QueryScalar",
|
|
185
|
+
"QueryValue",
|
|
186
|
+
"analytics_query_document",
|
|
187
|
+
"analytics_result_document",
|
|
188
|
+
"analytics_sample_document",
|
|
189
|
+
"parse_analytics_query",
|
|
190
|
+
"parse_analytics_result",
|
|
191
|
+
"parse_analytics_sample",
|
|
192
|
+
]
|