dyff-schema 0.24.2__py3-none-any.whl → 0.25.1__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 dyff-schema might be problematic. Click here for more details.

@@ -0,0 +1,4 @@
1
+ # SPDX-FileCopyrightText: 2024 UL Research Institutes
2
+ # SPDX-License-Identifier: Apache-2.0
3
+
4
+ from .v0.r1.commands import *
dyff/schema/v0/r1/base.py CHANGED
@@ -577,6 +577,9 @@ class DyffBaseModel(pydantic.BaseModel):
577
577
  class Config:
578
578
  extra = pydantic.Extra.forbid
579
579
 
580
+ # TODO: (DYFF-223) I think that exclude_unset=True should be the default
581
+ # for all schema objects, but I'm unsure of the consequences of making
582
+ # this change and we'll defer it until v1.
580
583
  def dict(self, *, by_alias: bool = True, **kwargs) -> _ModelAsDict:
581
584
  return super().dict(by_alias=by_alias, **kwargs)
582
585
 
@@ -0,0 +1,202 @@
1
+ # SPDX-FileCopyrightText: 2024 UL Research Institutes
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ """The command schemas describe the API for the command model.
4
+
5
+ These are used internally by the platform and users typically won't encounter them.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ from typing import Any, Literal, Union
11
+
12
+ import pydantic
13
+
14
+ from .base import DyffSchemaBaseModel
15
+ from .platform import (
16
+ Documented,
17
+ DyffEntityType,
18
+ EntityKindLiteral,
19
+ FamilyMembers,
20
+ Labeled,
21
+ SchemaVersion,
22
+ Status,
23
+ )
24
+
25
+ # ----------------------------------------------------------------------------
26
+
27
+
28
+ # mypy gets confused because 'dict' is the name of a method in DyffBaseModel
29
+ _ModelAsDict = dict[str, Any]
30
+
31
+
32
+ class EntityIdentifier(DyffSchemaBaseModel):
33
+ """Identifies a single entity."""
34
+
35
+ @staticmethod
36
+ def of(entity: DyffEntityType) -> EntityIdentifier:
37
+ """Create an identifier that identifies the given entity."""
38
+ return EntityIdentifier(kind=entity.kind, id=entity.id)
39
+
40
+ kind: EntityKindLiteral = pydantic.Field(description="The .kind of the entity.")
41
+ id: str = pydantic.Field(description="The .id of the entity.")
42
+
43
+
44
+ class FamilyIdentifier(EntityIdentifier):
45
+ """Identifies a single Family entity."""
46
+
47
+ kind: Literal["Family"] = "Family"
48
+
49
+
50
+ class Command(SchemaVersion):
51
+ """Base class for Command messages.
52
+
53
+ Commands define the API of the "command model" in our CQRS architecture.
54
+ """
55
+
56
+ command: Literal[
57
+ "AppendRevisionToHistory",
58
+ "CreateEntity",
59
+ "EditEntityDocumentation",
60
+ "EditEntityLabels",
61
+ "EditFamilyMembers",
62
+ "ForgetEntity",
63
+ "UpdateEntityStatus",
64
+ ]
65
+
66
+ # TODO: (DYFF-223) I think that exclude_unset=True should be the default
67
+ # for all schema objects, but I'm unsure of the consequences of making
68
+ # this change and we'll defer it until v1.
69
+ def dict(
70
+ self, *, by_alias: bool = True, exclude_unset=True, **kwargs
71
+ ) -> _ModelAsDict:
72
+ return super().dict(by_alias=by_alias, exclude_unset=exclude_unset, **kwargs)
73
+
74
+ def json(self, *, by_alias: bool = True, exclude_unset=True, **kwargs) -> str:
75
+ return super().json(by_alias=by_alias, exclude_unset=exclude_unset, **kwargs)
76
+
77
+
78
+ # ----------------------------------------------------------------------------
79
+
80
+
81
+ class CreateEntity(Command):
82
+ """Create a new entity."""
83
+
84
+ command: Literal["CreateEntity"] = "CreateEntity"
85
+
86
+ data: DyffEntityType = pydantic.Field(
87
+ description="The full spec of the entity to create."
88
+ )
89
+
90
+
91
+ # ----------------------------------------------------------------------------
92
+
93
+
94
+ class EditEntityDocumentationData(Documented, EntityIdentifier):
95
+ """Payload data for the EditEntityDocumentation command."""
96
+
97
+
98
+ class EditEntityDocumentation(Command):
99
+ """Edit the documentation associated with an entity.
100
+
101
+ Setting a documentation field to null/None deletes the corresponding value. To
102
+ preserve the existing value, leave the field *unset*.
103
+ """
104
+
105
+ command: Literal["EditEntityDocumentation"] = "EditEntityDocumentation"
106
+
107
+ data: EditEntityDocumentationData = pydantic.Field(description="The edit data.")
108
+
109
+
110
+ # ----------------------------------------------------------------------------
111
+
112
+
113
+ class EditEntityLabelsData(Labeled, EntityIdentifier):
114
+ """Payload data for the EditEntityLabels command."""
115
+
116
+
117
+ class EditEntityLabels(Command):
118
+ """Edit the labels associated with an entity.
119
+
120
+ Setting a label field to null/None deletes the corresponding value. To preserve the
121
+ existing value, leave the field *unset*.
122
+ """
123
+
124
+ command: Literal["EditEntityLabels"] = "EditEntityLabels"
125
+
126
+ data: EditEntityLabelsData = pydantic.Field(description="The edit data.")
127
+
128
+
129
+ # ----------------------------------------------------------------------------
130
+
131
+
132
+ class EditFamilyMembersData(FamilyMembers, FamilyIdentifier):
133
+ """Payload data for the EditFamilyMembers command."""
134
+
135
+
136
+ class EditFamilyMembers(Command):
137
+ """Edit the labels associated with an entity.
138
+
139
+ Setting a tag value to null/None deletes the corresponding value. To preserve the
140
+ existing value, leave the field *unset*.
141
+ """
142
+
143
+ command: Literal["EditFamilyMembers"] = "EditFamilyMembers"
144
+
145
+ data: EditFamilyMembersData = pydantic.Field(description="The edit data.")
146
+
147
+
148
+ # ----------------------------------------------------------------------------
149
+
150
+
151
+ class ForgetEntity(Command):
152
+ """Forget (permanently delete) an entity."""
153
+
154
+ command: Literal["ForgetEntity"] = "ForgetEntity"
155
+
156
+ data: EntityIdentifier = pydantic.Field(description="The entity to forget.")
157
+
158
+
159
+ # ----------------------------------------------------------------------------
160
+
161
+
162
+ class UpdateEntityStatusData(Status, EntityIdentifier):
163
+ """Payload data for the UpdateEntityStatus command."""
164
+
165
+
166
+ class UpdateEntityStatus(Command):
167
+ """Update the status fields of an entity."""
168
+
169
+ command: Literal["UpdateEntityStatus"] = "UpdateEntityStatus"
170
+
171
+ data: UpdateEntityStatusData = pydantic.Field(description="The status update data.")
172
+
173
+
174
+ # ----------------------------------------------------------------------------
175
+
176
+
177
+ DyffCommandType = Union[
178
+ CreateEntity,
179
+ EditEntityDocumentation,
180
+ EditEntityLabels,
181
+ EditFamilyMembers,
182
+ ForgetEntity,
183
+ UpdateEntityStatus,
184
+ ]
185
+
186
+
187
+ __all__ = [
188
+ "Command",
189
+ "CreateEntity",
190
+ "DyffCommandType",
191
+ "EditEntityDocumentation",
192
+ "EditEntityDocumentationData",
193
+ "EditEntityLabels",
194
+ "EditEntityLabelsData",
195
+ "EditFamilyMembers",
196
+ "EditFamilyMembersData",
197
+ "EntityIdentifier",
198
+ "FamilyIdentifier",
199
+ "ForgetEntity",
200
+ "UpdateEntityStatus",
201
+ "UpdateEntityStatusData",
202
+ ]
@@ -260,6 +260,29 @@ class Resources(str, enum.Enum):
260
260
  raise ValueError(f"No Resources for Entity kind: {kind}")
261
261
 
262
262
 
263
+ EntityKindLiteral = Literal[
264
+ "Analysis",
265
+ "Audit",
266
+ "AuditProcedure",
267
+ "DataSource",
268
+ "Dataset",
269
+ "Evaluation",
270
+ "Family",
271
+ "Hazard",
272
+ "History",
273
+ "InferenceService",
274
+ "InferenceSession",
275
+ "Measurement",
276
+ "Method",
277
+ "Model",
278
+ "Module",
279
+ "Report",
280
+ "Revision",
281
+ "SafetyCase",
282
+ "UseCase",
283
+ ]
284
+
285
+
263
286
  EntityID: TypeAlias = pydantic.constr(regex=entity_id_regex()) # type: ignore
264
287
 
265
288
 
@@ -412,6 +435,13 @@ class Mutable(DyffSchemaBaseModel):
412
435
  lastModificationTime: datetime
413
436
 
414
437
 
438
+ class DyffEntityMetadata(DyffSchemaBaseModel):
439
+ revision: Optional[str] = pydantic.Field(
440
+ default=None,
441
+ description="Unique identifier of the current revision of the entity.",
442
+ )
443
+
444
+
415
445
  class DyffEntity(Status, Labeled, SchemaVersion, DyffModelWithID):
416
446
  kind: Literal[
417
447
  "Analysis",
@@ -435,6 +465,11 @@ class DyffEntity(Status, Labeled, SchemaVersion, DyffModelWithID):
435
465
  "UseCase",
436
466
  ]
437
467
 
468
+ metadata: DyffEntityMetadata = pydantic.Field(
469
+ default_factory=DyffEntityMetadata,
470
+ description="Entity metadata",
471
+ )
472
+
438
473
  annotations: list[Annotation] = pydantic.Field(
439
474
  default_factory=list,
440
475
  description="A set of key-value annotations for the resource. Used to"
@@ -684,7 +719,17 @@ class Family(DyffEntity, FamilyBase, FamilyMembers):
684
719
 
685
720
 
686
721
  class RevisionMetadata(DyffSchemaBaseModel):
687
- creationTime: datetime = pydantic.Field("The time when the Revision was created")
722
+ previousRevision: Optional[str] = pydantic.Field(
723
+ description="The ID of the revision from which this revision was derived."
724
+ "If None, then this is the first revision of the entity."
725
+ )
726
+ creationTime: datetime = pydantic.Field(
727
+ description="The time when the Revision was created"
728
+ )
729
+
730
+
731
+ class ForeignRevision(RevisionMetadata):
732
+ id: str = pydantic.Field(description="Unique identifier of the entity")
688
733
 
689
734
 
690
735
  # Note: The 'Revision' class itself is defined all the way at the end of this
@@ -695,9 +740,13 @@ class RevisionMetadata(DyffSchemaBaseModel):
695
740
  class History(DyffEntity):
696
741
  kind: Literal["History"] = "History"
697
742
 
698
- latest: str = pydantic.Field(description="The ID of the latest Revision")
699
- revisions: dict[str, RevisionMetadata] = pydantic.Field(
700
- description="The set of known Revisions"
743
+ historyOf: str = pydantic.Field(
744
+ description="The ID of the entity described by this History."
745
+ )
746
+
747
+ latest: ForeignRevision = pydantic.Field(description="The latest Revision")
748
+ revisions: list[ForeignRevision] = pydantic.Field(
749
+ description="The list of known Revisions, in chronological order (newest last)."
701
750
  )
702
751
 
703
752
 
@@ -2282,7 +2331,7 @@ def entity_class(kind: Entities):
2282
2331
  return _ENTITY_CLASS[kind]
2283
2332
 
2284
2333
 
2285
- DyffEntityTypeExceptRevision = Union[
2334
+ _DyffEntityTypeRevisable = Union[
2286
2335
  Audit,
2287
2336
  AuditProcedure,
2288
2337
  DataSource,
@@ -2290,7 +2339,6 @@ DyffEntityTypeExceptRevision = Union[
2290
2339
  Evaluation,
2291
2340
  Family,
2292
2341
  Hazard,
2293
- History,
2294
2342
  InferenceService,
2295
2343
  InferenceSession,
2296
2344
  Measurement,
@@ -2303,6 +2351,18 @@ DyffEntityTypeExceptRevision = Union[
2303
2351
  ]
2304
2352
 
2305
2353
 
2354
+ class RevisionData(DyffSchemaBaseModel):
2355
+ format: Literal["Snapshot", "JsonMergePatch"]
2356
+ snapshot: Optional[_DyffEntityTypeRevisable] = pydantic.Field(
2357
+ default=None, description="A full snapshot of the entity."
2358
+ )
2359
+ jsonMergePatch: Optional[str] = pydantic.Field(
2360
+ default=None,
2361
+ description="A JsonMergePatch, serialized as a string, that will"
2362
+ " transform the *current* revision into the *previous* revision.",
2363
+ )
2364
+
2365
+
2306
2366
  # Note: This class is defined here because OpenAPI generation doesn't work
2307
2367
  # with the Python < 3.10 "ForwardDeclaration" syntax. You get an error like:
2308
2368
  #
@@ -2324,12 +2384,22 @@ DyffEntityTypeExceptRevision = Union[
2324
2384
  class Revision(DyffEntity, RevisionMetadata):
2325
2385
  kind: Literal["Revision"] = "Revision"
2326
2386
 
2327
- entity: DyffEntityTypeExceptRevision = pydantic.Field(
2328
- description="The associated entity data",
2387
+ revisionOf: str = pydantic.Field(
2388
+ description="The ID of the entity that this is a revision of"
2389
+ )
2390
+
2391
+ data: RevisionData = pydantic.Field(
2392
+ description="The associated entity revision data",
2329
2393
  )
2330
2394
 
2395
+ def dependencies(self) -> list[str]:
2396
+ return []
2397
+
2398
+ def resource_allocation(self) -> Optional[ResourceAllocation]:
2399
+ return None
2400
+
2331
2401
 
2332
- DyffEntityType = Union[DyffEntityTypeExceptRevision, Revision]
2402
+ DyffEntityType = Union[_DyffEntityTypeRevisable, History, Revision]
2333
2403
 
2334
2404
 
2335
2405
  __all__ = [
@@ -2375,6 +2445,7 @@ __all__ = [
2375
2445
  "DyffSchemaBaseModel",
2376
2446
  "Entities",
2377
2447
  "EntityID",
2448
+ "EntityKindLiteral",
2378
2449
  "Evaluation",
2379
2450
  "EvaluationBase",
2380
2451
  "EvaluationClientConfiguration",
@@ -2388,6 +2459,7 @@ __all__ = [
2388
2459
  "ForeignInferenceService",
2389
2460
  "ForeignMethod",
2390
2461
  "ForeignModel",
2462
+ "ForeignRevision",
2391
2463
  "Frameworks",
2392
2464
  "Hazard",
2393
2465
  "History",
@@ -2446,6 +2518,7 @@ __all__ = [
2446
2518
  "ReportBase",
2447
2519
  "Resources",
2448
2520
  "Revision",
2521
+ "RevisionData",
2449
2522
  "RevisionMetadata",
2450
2523
  "Role",
2451
2524
  "SafetyCase",
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: dyff-schema
3
- Version: 0.24.2
3
+ Version: 0.25.1
4
4
  Summary: Data models for the Dyff AI auditing platform.
5
5
  Author-email: Digital Safety Research Institute <contact@dsri.org>
6
6
  License: Apache-2.0
@@ -2,6 +2,7 @@ dyff/schema/__init__.py,sha256=JcpxaRHNYgLjJWLjVayLlqacb2GX49Pazpwb8m-BctM,1031
2
2
  dyff/schema/adapters.py,sha256=YMTHv_2VlLGFp-Kqwa6H51hjffHmk8gXjZilHysIF5Q,123
3
3
  dyff/schema/annotations.py,sha256=nE6Jk1PLqlShj8uqjE_EzZC9zYnTDW5AVtQcjysiK8M,10018
4
4
  dyff/schema/base.py,sha256=jvaNtsSZyFfsdUZTcY_U-yfLY5_GyrMxSXhON2R9XR0,119
5
+ dyff/schema/commands.py,sha256=hlqMJ99ZF_ElnGF6vQO_T872WM7aClFoFKkAXA66boI,123
5
6
  dyff/schema/copydoc.py,sha256=B4ZRpQmbFxi-3l9LCHvaJiVKb9VxADgC5vey804Febc,1075
6
7
  dyff/schema/errors.py,sha256=ow3yiucU4wGkeLmapUURp3eyaebwGUwDaVTXpPcrA7M,1542
7
8
  dyff/schema/ids.py,sha256=M3kdGRYGPCMnFkRRo0nzHlntdJtBrRwGJ_9R7LlN0bI,2085
@@ -23,8 +24,9 @@ dyff/schema/io/vllm.py,sha256=2q05M_-lTzq9oywKXHPPpCFCSDVCSsRQqtmERzWTtio,123
23
24
  dyff/schema/v0/__init__.py,sha256=L5y8UhRnojerPYHumsxQJRcHCNz8Hj9NM8b47mewMNs,92
24
25
  dyff/schema/v0/r1/__init__.py,sha256=L5y8UhRnojerPYHumsxQJRcHCNz8Hj9NM8b47mewMNs,92
25
26
  dyff/schema/v0/r1/adapters.py,sha256=dmQS2ecgDX4ZvTMOW-6NzV_Oq_UpaiyFd7QnSNoOnK8,33057
26
- dyff/schema/v0/r1/base.py,sha256=IpvlYDr6JjYo6tn8XW4C1Fpgd_uqzZGZsG_cuEn_gQs,19441
27
- dyff/schema/v0/r1/platform.py,sha256=dlejqiaxJIkBE_IqbNjjWX-B8bKCxANcKY_HdrIXbNU,78452
27
+ dyff/schema/v0/r1/base.py,sha256=9tzgWKeQrSlLq2HERViDzaNYW6X5m5V6Uf9t8uky_FI,19640
28
+ dyff/schema/v0/r1/commands.py,sha256=DbSSnM8ZQr409II8aqVhv1AtiYqDDUG6H9QOR40HN68,5666
29
+ dyff/schema/v0/r1/platform.py,sha256=tETIn2YMziNSTzkgWopPFXgdv0hiu80f0XdYsNd08kw,80421
28
30
  dyff/schema/v0/r1/requests.py,sha256=4TM1IKG9IP4MyprIy9E9XA_JqvkuwKAuY1ao1BbVLI0,15676
29
31
  dyff/schema/v0/r1/test.py,sha256=X6dUyVd5svcPCI-PBMOAqEfK9jv3bRDvkQTJzwS96c0,10720
30
32
  dyff/schema/v0/r1/version.py,sha256=isKAGuGxsdru8vDaYmI4YiZdJOu_wNxXK7u6QzD6FE4,392
@@ -37,9 +39,9 @@ dyff/schema/v0/r1/dataset/text.py,sha256=nLIn91Zlt0tNdXUklSgjJ-kEDxoPX32ISLkiv2D
37
39
  dyff/schema/v0/r1/dataset/vision.py,sha256=aIe0fbfM_g3DsrDTdg2K803YKLjZBpurM_VJcJFuZLc,369
38
40
  dyff/schema/v0/r1/io/__init__.py,sha256=L5y8UhRnojerPYHumsxQJRcHCNz8Hj9NM8b47mewMNs,92
39
41
  dyff/schema/v0/r1/io/vllm.py,sha256=CUE9y8KthtUI7sD49S875rDmPvKotSXVIRaBS79aBZs,5320
40
- dyff_schema-0.24.2.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
41
- dyff_schema-0.24.2.dist-info/METADATA,sha256=XzRaFplWzGHryumpgXhBmX58a0tkfkhJxQpqrl5EhrY,3482
42
- dyff_schema-0.24.2.dist-info/NOTICE,sha256=YONACu0s_Ui6jNi-wtEsVQbTU1JIkh8wvLH6d1-Ni_w,43
43
- dyff_schema-0.24.2.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
44
- dyff_schema-0.24.2.dist-info/top_level.txt,sha256=9e3VVdeX73t_sUJOPQPCcGtYO1JhoErhHIi3WoWGcFI,5
45
- dyff_schema-0.24.2.dist-info/RECORD,,
42
+ dyff_schema-0.25.1.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
43
+ dyff_schema-0.25.1.dist-info/METADATA,sha256=1UHYlxAwjETakjdSMAMrqL9Ft9yTg-b0_WZCx_ppdds,3482
44
+ dyff_schema-0.25.1.dist-info/NOTICE,sha256=YONACu0s_Ui6jNi-wtEsVQbTU1JIkh8wvLH6d1-Ni_w,43
45
+ dyff_schema-0.25.1.dist-info/WHEEL,sha256=jB7zZ3N9hIM9adW7qlTAyycLYW9npaWKLRzaoVcLKcM,91
46
+ dyff_schema-0.25.1.dist-info/top_level.txt,sha256=9e3VVdeX73t_sUJOPQPCcGtYO1JhoErhHIi3WoWGcFI,5
47
+ dyff_schema-0.25.1.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.8.0)
2
+ Generator: setuptools (75.8.2)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5