fable-model 0.4.0__tar.gz → 0.5.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fable-model
3
- Version: 0.4.0
3
+ Version: 0.5.0
4
4
  Summary: Data models utilized in the FABLE ecosystem's HTTP-based services.
5
5
  License-Expression: MIT
6
6
  License-File: LICENSE
@@ -1,4 +1,12 @@
1
- from .common import BitVectorEntity, AttributeValueEntity, HealthResponse, ServiceBaseInformation
1
+ from .common import (
2
+ BitVectorEntity,
3
+ AttributeValueEntity,
4
+ HealthResponse,
5
+ ServiceBaseInformation,
6
+ BitVectorMetadata,
7
+ MetaBitVectorEntity,
8
+ PseudonymizedAttributeValueEntity,
9
+ )
2
10
  from .mask import (
3
11
  HashStrategy,
4
12
  DoubleHash,
@@ -66,8 +74,6 @@ from .broker import (
66
74
  SessionCreationResponse,
67
75
  SessionDeletionRequest,
68
76
  SessionUpdateResponse,
69
- BitVectorMetadata,
70
- MetaBitVectorEntity,
71
77
  BaseClientModel,
72
78
  ClientSubmissionRequest,
73
79
  ClientVectorBatch,
@@ -77,6 +83,14 @@ from .broker import (
77
83
  ClientResultResponse,
78
84
  SessionGetResponse,
79
85
  )
86
+ from .resolver import (
87
+ MetadataAttribute,
88
+ ClientCreationRequest,
89
+ ClientMatchSession,
90
+ PseudonymsSubmissionRequest,
91
+ ResultsFetchingRequest,
92
+ PseudonymMatchResponse,
93
+ )
80
94
 
81
95
  __all__ = [
82
96
  "BitVectorEntity",
@@ -156,4 +170,11 @@ __all__ = [
156
170
  "ClientResultResponse",
157
171
  "ServiceBaseInformation",
158
172
  "SessionGetResponse",
173
+ "PseudonymizedAttributeValueEntity",
174
+ "MetadataAttribute",
175
+ "ClientCreationRequest",
176
+ "ClientMatchSession",
177
+ "PseudonymsSubmissionRequest",
178
+ "ResultsFetchingRequest",
179
+ "PseudonymMatchResponse",
159
180
  ]
@@ -2,7 +2,7 @@ from typing import Annotated
2
2
 
3
3
  from pydantic import BaseModel, Field, SecretStr, field_serializer
4
4
 
5
- from fable_model.common import BitVectorEntity
5
+ from fable_model.common import BitVectorMetadata, MetaBitVectorEntity
6
6
  from fable_model.match import MatchConfig
7
7
 
8
8
 
@@ -47,15 +47,6 @@ SessionDeletionRequest = BaseAuthenticatedSessionModel
47
47
  SessionUpdateRequest = BaseAuthenticatedSessionModel
48
48
 
49
49
 
50
- class BitVectorMetadata(BaseModel):
51
- name: str
52
- value: str
53
-
54
-
55
- class MetaBitVectorEntity(BitVectorEntity):
56
- metadata: list[BitVectorMetadata] = Field(default_factory=list)
57
-
58
-
59
50
  class BaseClientModel(BaseSessionModel):
60
51
  client: SecretStr
61
52
 
@@ -1,7 +1,7 @@
1
1
  from typing import Annotated, Literal
2
2
 
3
3
  from packaging.version import Version, InvalidVersion
4
- from pydantic import BaseModel, ConfigDict, BeforeValidator
4
+ from pydantic import BaseModel, ConfigDict, BeforeValidator, Field
5
5
 
6
6
 
7
7
  class ParentModel(BaseModel):
@@ -13,11 +13,28 @@ class AttributeValueEntity(ParentModel):
13
13
  attributes: dict[str, str]
14
14
 
15
15
 
16
+ class BitVectorMetadata(BaseModel):
17
+ name: str
18
+ value: str
19
+
20
+
21
+ class PseudonymizedAttributeValueEntity(AttributeValueEntity):
22
+ pseudonym: str
23
+ metadata: list[BitVectorMetadata] = Field(default_factory=list)
24
+
25
+ def to_attribute_value_entity(self) -> AttributeValueEntity:
26
+ return AttributeValueEntity(id=self.id, attributes=self.attributes)
27
+
28
+
16
29
  class BitVectorEntity(ParentModel):
17
30
  id: str
18
31
  value: str
19
32
 
20
33
 
34
+ class MetaBitVectorEntity(BitVectorEntity):
35
+ metadata: list[BitVectorMetadata] = Field(default_factory=list)
36
+
37
+
21
38
  class HealthResponse(ParentModel):
22
39
  status: Literal["ok"] = "ok"
23
40
 
@@ -162,7 +162,7 @@ class WeightedAttributeConfig(ParentModel):
162
162
 
163
163
  class BaseMaskRequest(ParentModel):
164
164
  config: MaskConfig
165
- attributes: Annotated[list[WeightedAttributeConfig] | list[StaticAttributeConfig], Field(default_factory=list)]
165
+ attributes: list[WeightedAttributeConfig] | list[StaticAttributeConfig] = Field(default_factory=list, min_length=1)
166
166
 
167
167
  def with_entities(self, entities: list[AttributeValueEntity]) -> "EntityMaskRequest":
168
168
  return EntityMaskRequest(
@@ -0,0 +1,64 @@
1
+ from functools import cached_property
2
+ from typing import Self
3
+
4
+ from pydantic import BaseModel, Field, SecretStr, model_validator, computed_field, field_serializer
5
+
6
+ from fable_model.broker import BaseSessionModel, ClientResultResponse
7
+ from fable_model.common import BitVectorMetadata
8
+ from fable_model.mask import BaseMaskRequest
9
+ from fable_model.transform import BaseTransformRequest
10
+
11
+
12
+ class MetadataAttribute(BaseModel):
13
+ name: str
14
+ attribute: str
15
+
16
+ def to_metadata(self, value: str) -> BitVectorMetadata:
17
+ return BitVectorMetadata(name=self.name, value=value)
18
+
19
+
20
+ class PseudonymsSubmissionRequest(BaseSessionModel):
21
+ pseudonyms: list[str]
22
+
23
+
24
+ class ClientCreationRequest(BaseSessionModel):
25
+ transformation: BaseTransformRequest
26
+ masking: BaseMaskRequest
27
+ data_source_domain: str
28
+ metadata_attributes: list[MetadataAttribute] = Field(default_factory=list)
29
+
30
+ @model_validator(mode="after")
31
+ def validate_attributes(self) -> Self:
32
+ transform_attributes = {
33
+ transformer.attribute_name for transformer in self.transformation.attribute_transformers
34
+ }
35
+ mask_attributes = {attr.attribute_name for attr in self.masking.attributes}
36
+ diff = transform_attributes - mask_attributes
37
+
38
+ if len(diff) != 0:
39
+ raise ValueError(
40
+ f"There are attributes configured to be transformed that are not configured to be masked, {diff}."
41
+ )
42
+
43
+ return self
44
+
45
+ @computed_field
46
+ @cached_property
47
+ def attributes(self) -> list[str]:
48
+ return list({attr.attribute_name for attr in self.masking.attributes})
49
+
50
+
51
+ class ClientMatchSession(ClientCreationRequest):
52
+ client: SecretStr
53
+ session_expires_at: int
54
+
55
+ @field_serializer("client")
56
+ def serialize_client(self, value: SecretStr) -> str:
57
+ return value.get_secret_value()
58
+
59
+
60
+ class ResultsFetchingRequest(BaseSessionModel):
61
+ show_unfinished_results: bool = False
62
+
63
+
64
+ PseudonymMatchResponse = ClientResultResponse
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "fable-model"
3
- version = "0.4.0"
3
+ version = "0.5.0"
4
4
  description = "Data models utilized in the FABLE ecosystem's HTTP-based services."
5
5
  authors = [
6
6
  {name = "Maximilian Jugl"},
File without changes
File without changes