fable-model 0.3.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.3.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
@@ -23,7 +23,7 @@ Description-Content-Type: text/markdown
23
23
 
24
24
  [![PyPI](https://img.shields.io/pypi/v/fable-model?cacheSeconds=0)](https://pypi.org/project/fable-model/)
25
25
  [![Python Versions](https://img.shields.io/pypi/pyversions/fable-model?cacheSeconds=0)](https://pypi.org/project/fable-model/)
26
- ![Code Coverage](https://img.shields.io/badge/Coverage-98%25-brightgreen.svg)
26
+ ![Code Coverage](https://img.shields.io/badge/Coverage-97%25-brightgreen.svg)
27
27
  [![License](https://img.shields.io/pypi/l/fable-model?cacheSeconds=0)](https://pypi.org/project/fable-model/)
28
28
  [![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-%23FE5196?logo=conventionalcommits&logoColor=white)](https://conventionalcommits.org)
29
29
 
@@ -1,6 +1,6 @@
1
1
  [![PyPI](https://img.shields.io/pypi/v/fable-model?cacheSeconds=0)](https://pypi.org/project/fable-model/)
2
2
  [![Python Versions](https://img.shields.io/pypi/pyversions/fable-model?cacheSeconds=0)](https://pypi.org/project/fable-model/)
3
- ![Code Coverage](https://img.shields.io/badge/Coverage-98%25-brightgreen.svg)
3
+ ![Code Coverage](https://img.shields.io/badge/Coverage-97%25-brightgreen.svg)
4
4
  [![License](https://img.shields.io/pypi/l/fable-model?cacheSeconds=0)](https://pypi.org/project/fable-model/)
5
5
  [![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-%23FE5196?logo=conventionalcommits&logoColor=white)](https://conventionalcommits.org)
6
6
 
@@ -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,
@@ -75,6 +81,15 @@ from .broker import (
75
81
  ClientResultRequest,
76
82
  MatchedClientVector,
77
83
  ClientResultResponse,
84
+ SessionGetResponse,
85
+ )
86
+ from .resolver import (
87
+ MetadataAttribute,
88
+ ClientCreationRequest,
89
+ ClientMatchSession,
90
+ PseudonymsSubmissionRequest,
91
+ ResultsFetchingRequest,
92
+ PseudonymMatchResponse,
78
93
  )
79
94
 
80
95
  __all__ = [
@@ -154,4 +169,12 @@ __all__ = [
154
169
  "MatchedClientVector",
155
170
  "ClientResultResponse",
156
171
  "ServiceBaseInformation",
172
+ "SessionGetResponse",
173
+ "PseudonymizedAttributeValueEntity",
174
+ "MetadataAttribute",
175
+ "ClientCreationRequest",
176
+ "ClientMatchSession",
177
+ "PseudonymsSubmissionRequest",
178
+ "ResultsFetchingRequest",
179
+ "PseudonymMatchResponse",
157
180
  ]
@@ -1,17 +1,25 @@
1
1
  from typing import Annotated
2
2
 
3
- from pydantic import BaseModel, Field
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
 
9
9
  class BaseSessionModel(BaseModel):
10
- session: str
10
+ session: SecretStr
11
+
12
+ @field_serializer("session")
13
+ def serialize_session(self, value: SecretStr) -> str:
14
+ return value.get_secret_value()
11
15
 
12
16
 
13
17
  class BaseAuthenticatedSessionModel(BaseSessionModel):
14
- token: str
18
+ token: SecretStr
19
+
20
+ @field_serializer("token")
21
+ def serialize_token(self, value: SecretStr) -> str:
22
+ return value.get_secret_value()
15
23
 
16
24
 
17
25
  class SessionCreationRequest(BaseSessionModel):
@@ -23,25 +31,28 @@ class SessionUpdateResponse(BaseSessionModel):
23
31
  expires_at: int
24
32
 
25
33
 
26
- class SessionCreationResponse(SessionUpdateResponse):
27
- token: str
28
-
34
+ class SessionGetResponse(SessionUpdateResponse):
35
+ match_config: MatchConfig
29
36
 
30
- SessionDeletionRequest = BaseAuthenticatedSessionModel
31
- SessionUpdateRequest = BaseAuthenticatedSessionModel
32
37
 
38
+ class SessionCreationResponse(SessionUpdateResponse):
39
+ token: SecretStr
33
40
 
34
- class BitVectorMetadata(BaseModel):
35
- name: str
36
- value: str
41
+ @field_serializer("token")
42
+ def serialize_token(self, value: SecretStr) -> str:
43
+ return value.get_secret_value()
37
44
 
38
45
 
39
- class MetaBitVectorEntity(BitVectorEntity):
40
- metadata: list[BitVectorMetadata] = Field(default_factory=list)
46
+ SessionDeletionRequest = BaseAuthenticatedSessionModel
47
+ SessionUpdateRequest = BaseAuthenticatedSessionModel
41
48
 
42
49
 
43
50
  class BaseClientModel(BaseSessionModel):
44
- client: str
51
+ client: SecretStr
52
+
53
+ @field_serializer("client")
54
+ def serialize_client(self, value: SecretStr) -> str:
55
+ return value.get_secret_value()
45
56
 
46
57
 
47
58
  class ClientSubmissionRequest(BaseClientModel):
@@ -49,16 +60,24 @@ class ClientSubmissionRequest(BaseClientModel):
49
60
 
50
61
 
51
62
  class ClientVectorBatch(BaseModel):
52
- client: str
63
+ client: SecretStr
53
64
  ids: list[str]
54
65
 
66
+ @field_serializer("client")
67
+ def serialize_client(self, value: SecretStr) -> str:
68
+ return value.get_secret_value()
69
+
55
70
 
56
71
  class VectorMatchBatch(BaseModel):
57
72
  domain: ClientVectorBatch
58
73
  range: list[ClientVectorBatch]
59
- session: str
74
+ session: SecretStr
60
75
  config: MatchConfig
61
76
 
77
+ @field_serializer("session")
78
+ def serialize_session(self, value: SecretStr) -> str:
79
+ return value.get_secret_value()
80
+
62
81
 
63
82
  class ClientResultRequest(BaseClientModel):
64
83
  show_unfinished_results: bool = False
@@ -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.3.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