datamasque-python 1.2.1__py3-none-any.whl → 1.2.3__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.
@@ -81,6 +81,7 @@ from datamasque.client.models.discovery import (
81
81
  SchemaDiscoveryRequest,
82
82
  SchemaDiscoveryResult,
83
83
  TableConstraints,
84
+ ValueCountStatus,
84
85
  )
85
86
  from datamasque.client.models.discovery_config import DiscoveryConfig, DiscoveryConfigId, DiscoveryConfigType
86
87
  from datamasque.client.models.discovery_config_library import DiscoveryConfigLibrary, DiscoveryConfigLibraryId
@@ -319,4 +320,5 @@ __all__ = [
319
320
  "ValidationErrorDetails",
320
321
  "ValidationErrorType",
321
322
  "ValidationStatus",
323
+ "ValueCountStatus",
322
324
  ]
@@ -76,15 +76,19 @@ class DiscoveryConfigLibraryClient(BaseClient):
76
76
  Creates a new discovery config library on the server.
77
77
 
78
78
  Sets the library's server-assigned fields
79
- (`id`, `is_valid`, `validation_error`, `created`, `modified`) and returns the library.
79
+ (`id`, `is_valid`, `validation_error`, `usage_count`, `created`, `modified`) and returns the library.
80
80
  """
81
81
 
82
+ if not library.yaml:
83
+ raise ValueError("Cannot create a discovery config library without YAML content (yaml is empty)")
84
+
82
85
  data = library.model_dump(exclude_none=True, by_alias=True, mode="json")
83
86
  response = self.make_request("POST", "/api/discovery/config-libraries/", data=data)
84
87
  created = DiscoveryConfigLibrary.model_validate(response.json())
85
88
  library.id = created.id
86
89
  library.is_valid = created.is_valid
87
90
  library.validation_error = created.validation_error
91
+ library.usage_count = created.usage_count
88
92
  library.created = created.created
89
93
  library.modified = created.modified
90
94
  logger.info('Creation of discovery config library "%s" successful', library.name)
@@ -101,9 +105,9 @@ class DiscoveryConfigLibraryClient(BaseClient):
101
105
  if library.id is None:
102
106
  raise ValueError("Cannot update a discovery config library that has not been created yet (id is None)")
103
107
 
104
- if library.yaml is None:
108
+ if not library.yaml:
105
109
  raise ValueError(
106
- "Cannot update a discovery config library without YAML content (yaml is None); "
110
+ "Cannot update a discovery config library without YAML content (yaml is empty or unset); "
107
111
  "list results omit YAML, so fetch the full library with `get_discovery_config_library` first"
108
112
  )
109
113
 
@@ -112,6 +116,7 @@ class DiscoveryConfigLibraryClient(BaseClient):
112
116
  updated = DiscoveryConfigLibrary.model_validate(response.json())
113
117
  library.is_valid = updated.is_valid
114
118
  library.validation_error = updated.validation_error
119
+ library.usage_count = updated.usage_count
115
120
  library.modified = updated.modified
116
121
  logger.debug('Update of discovery config library "%s" successful', library.name)
117
122
  return library
@@ -75,15 +75,20 @@ class DiscoveryConfigClient(BaseClient):
75
75
  Creates a new discovery config on the server.
76
76
 
77
77
  Sets the config's server-assigned fields
78
- (`id`, `is_valid`, `validation_error`, `created`, `modified`) and returns the config.
78
+ (`id`, `is_valid`, `validation_error`, `validation_error_details`, `created`, `modified`)
79
+ and returns the config.
79
80
  """
80
81
 
82
+ if not config.yaml:
83
+ raise ValueError("Cannot create a discovery config without YAML content (yaml is empty)")
84
+
81
85
  data = config.model_dump(exclude_none=True, by_alias=True, mode="json")
82
86
  response = self.make_request("POST", "/api/discovery/configs/", data=data)
83
87
  created = DiscoveryConfig.model_validate(response.json())
84
88
  config.id = created.id
85
89
  config.is_valid = created.is_valid
86
90
  config.validation_error = created.validation_error
91
+ config.validation_error_details = created.validation_error_details
87
92
  config.created = created.created
88
93
  config.modified = created.modified
89
94
  logger.info('Creation of discovery config "%s" successful', config.name)
@@ -94,17 +99,24 @@ class DiscoveryConfigClient(BaseClient):
94
99
  Performs a full update of the discovery config.
95
100
 
96
101
  The config must have its `id` set
97
- (i.e., it must have been previously created or retrieved from the server).
102
+ and its `yaml` content present.
98
103
  """
99
104
 
100
105
  if config.id is None:
101
106
  raise ValueError("Cannot update a discovery config that has not been created yet (id is None)")
102
107
 
108
+ if not config.yaml:
109
+ raise ValueError(
110
+ "Cannot update a discovery config without YAML content (yaml is empty or unset); "
111
+ "list results omit YAML, so fetch the full config with `get_discovery_config` first"
112
+ )
113
+
103
114
  data = config.model_dump(exclude_none=True, by_alias=True, mode="json")
104
115
  response = self.make_request("PUT", f"/api/discovery/configs/{config.id}/", data=data)
105
116
  updated = DiscoveryConfig.model_validate(response.json())
106
117
  config.is_valid = updated.is_valid
107
118
  config.validation_error = updated.validation_error
119
+ config.validation_error_details = updated.validation_error_details
108
120
  config.modified = updated.modified
109
121
  logger.debug('Update of discovery config "%s" successful', config.name)
110
122
  return config
@@ -1,5 +1,6 @@
1
1
  """Models related to data selection in endpoints such as /api/async-generate-ruleset."""
2
2
 
3
+ import json
3
4
  from typing import Optional, Union
4
5
 
5
6
  from pydantic import BaseModel, ConfigDict
@@ -19,6 +20,33 @@ A locator identifying a masked value within a file.
19
20
  """
20
21
 
21
22
 
23
+ def serialize_locator(locator: Locator) -> str:
24
+ """
25
+ Returns the string form of `locator` that the API uses as a key, such as in `FileDiscoveryFile.value_counts`.
26
+
27
+ A string locator is its own key.
28
+ A :data:`JsonPath` becomes compact JSON, e.g. `'["employees","*","email"]'`.
29
+ """
30
+
31
+ if isinstance(locator, str):
32
+ return locator
33
+ return json.dumps(locator, separators=(",", ":"), ensure_ascii=False)
34
+
35
+
36
+ def deserialize_locator(key: str) -> Locator:
37
+ """
38
+ Returns the `Locator` that `key`, a serialized locator from the API, identifies.
39
+
40
+ A key that holds no JSON array names a column, and comes back as a string.
41
+ """
42
+
43
+ try:
44
+ parsed = json.loads(key)
45
+ except json.JSONDecodeError:
46
+ return key
47
+ return parsed if isinstance(parsed, list) else key
48
+
49
+
22
50
  class UserSelection(BaseModel):
23
51
  """Information about selected files and locators for file masking ruleset generation."""
24
52
 
@@ -6,7 +6,13 @@ from typing import Any, Optional, Union
6
6
  from pydantic import BaseModel, ConfigDict, Field, field_validator, model_validator
7
7
 
8
8
  from datamasque.client.models.connection import ConnectionConfig, ConnectionId, unwrap_connection_id
9
- from datamasque.client.models.data_selection import HashColumnsTableConfig, Locator, UserSelection
9
+ from datamasque.client.models.data_selection import (
10
+ HashColumnsTableConfig,
11
+ Locator,
12
+ UserSelection,
13
+ deserialize_locator,
14
+ serialize_locator,
15
+ )
10
16
  from datamasque.client.models.discovery_config import DiscoveryConfig, DiscoveryConfigId, unwrap_discovery_config_id
11
17
  from datamasque.client.models.pagination import Page
12
18
  from datamasque.client.models.rg_config import RGConfig, RGConfigId, unwrap_rg_config_id
@@ -434,6 +440,14 @@ class FileDiscoveryMatch(BaseModel):
434
440
  hit_ratio: Optional[int] = None # None for metadata matches, percentage 0-100 for IDD matches.
435
441
 
436
442
 
443
+ class ValueCountStatus(Enum):
444
+ """Whether a file's values were counted, and when they were not, why."""
445
+
446
+ counted = "counted"
447
+ in_data_discovery_disabled = "in_data_discovery_disabled"
448
+ file_type_has_no_values = "file_type_has_no_values"
449
+
450
+
437
451
  class FileDiscoveryLocatorResult(BaseModel):
438
452
  """A locator (column/path) within a discovered file."""
439
453
 
@@ -443,6 +457,7 @@ class FileDiscoveryLocatorResult(BaseModel):
443
457
  matches: list[FileDiscoveryMatch]
444
458
  data_types: list[str]
445
459
  safe_data_preview: Optional[SafeDataPreview] = None
460
+ value_count: Optional[int] = None
446
461
 
447
462
 
448
463
  class FileDiscoveryFile(BaseModel):
@@ -454,6 +469,23 @@ class FileDiscoveryFile(BaseModel):
454
469
  file_type: str
455
470
  delimiter: Optional[str] = None
456
471
  encoding: Optional[str] = None
472
+ value_counts: dict[str, int] = Field(default_factory=dict)
473
+ value_count_status: Optional[ValueCountStatus] = None
474
+
475
+ @field_validator("value_count_status", mode="before")
476
+ @classmethod
477
+ def _blank_status_is_none(cls, value: Any) -> Any:
478
+ return value or None
479
+
480
+ def get_value_count_of_locator(self, locator: Locator) -> Optional[int]:
481
+ """Returns how many values this file holds at `locator`, or `None` if this file holds no count for it."""
482
+
483
+ return self.value_counts.get(serialize_locator(locator))
484
+
485
+ def parse_value_counts(self) -> list[tuple[Locator, int]]:
486
+ """Returns this file's value counts, with each locator in the form that the discovery results use."""
487
+
488
+ return [(deserialize_locator(key), count) for key, count in self.value_counts.items()]
457
489
 
458
490
 
459
491
  class FileDiscoveryResult(BaseModel):
@@ -2,9 +2,9 @@ import enum
2
2
  from datetime import datetime
3
3
  from typing import Any, NewType, Optional
4
4
 
5
- from pydantic import BaseModel, ConfigDict, Field
5
+ from pydantic import AliasChoices, AliasPath, BaseModel, ConfigDict, Field
6
6
 
7
- from datamasque.client.models.status import ValidationStatus
7
+ from datamasque.client.models.status import ValidationErrorDetails, ValidationStatus
8
8
 
9
9
  DiscoveryConfigId = NewType("DiscoveryConfigId", str)
10
10
 
@@ -49,5 +49,14 @@ class DiscoveryConfig(BaseModel):
49
49
  """Validation status; may be `in_progress` briefly after creating a large config."""
50
50
  validation_error: Optional[str] = Field(default=None, exclude=True)
51
51
  """Human-readable validation error, or `None` when valid."""
52
+ # Deliberately not `validation_errors`:
53
+ # this is a different shape to `Ruleset.validation_errors`,
54
+ # and would sit one character from `validation_error` above.
55
+ validation_error_details: list[ValidationErrorDetails] = Field(
56
+ default_factory=list,
57
+ exclude=True,
58
+ validation_alias=AliasChoices(AliasPath("errors", "config_yaml"), "validation_error_details"),
59
+ )
60
+ """Structured, positional validation errors."""
52
61
  created: Optional[datetime] = Field(default=None, exclude=True)
53
62
  modified: Optional[datetime] = Field(default=None, exclude=True)
@@ -27,5 +27,7 @@ class DiscoveryConfigLibrary(BaseModel):
27
27
  """Validation status; libraries are validated synchronously on create/update."""
28
28
  validation_error: Optional[str] = Field(default=None, exclude=True)
29
29
  """Human-readable validation error, or `None` when valid."""
30
+ usage_count: Optional[int] = Field(default=None, exclude=True)
31
+ """Number of active discovery configs that import this library."""
30
32
  created: Optional[datetime] = Field(default=None, exclude=True)
31
33
  modified: Optional[datetime] = Field(default=None, exclude=True)
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.5
2
2
  Name: datamasque-python
3
- Version: 1.2.1
3
+ Version: 1.2.3
4
4
  Summary: Official Python client for the DataMasque data-masking API.
5
5
  Project-URL: Homepage, https://datamasque.com/
6
6
  Project-URL: Documentation, https://datamasque-python.readthedocs.io/
@@ -1,9 +1,9 @@
1
- datamasque/client/__init__.py,sha256=2PVF5FrXkPAv51EMxSvfpYelJpbOg_Tlx-Wo7p2-0jo,8661
1
+ datamasque/client/__init__.py,sha256=bw_5NEF3vLuOLKrT-z7UCkWaR_nFVkhE_RmY3Q9Y7sw,8707
2
2
  datamasque/client/base.py,sha256=cXU4dluL9e1N1F2pV48iIvebv6OHt7Kh4Ka2y9vkOPo,14296
3
3
  datamasque/client/connections.py,sha256=EFinx8fJRme0mTxuWY3d29UnmUFbsQhMaUQT0Ma2PK4,2885
4
4
  datamasque/client/discovery.py,sha256=xidiAj5LdVSGQy6pjta_2Z_aJmuPPohblyNDfua_Mxk,28859
5
- datamasque/client/discovery_config_libraries.py,sha256=bwuBTCnJUSnOyTz_I-_D6uS3wcRJh3ZRtfv2AOyMnmY,7024
6
- datamasque/client/discovery_configs.py,sha256=G-W-X_KizjjQLa-Rb6ixLjlkxbkCe4WGCOfYZrGtxIk,6420
5
+ datamasque/client/discovery_config_libraries.py,sha256=K6kFi7kL4SGIPKNIg1TBMIwHUeyfXI3Lyg5sknMMCD4,7285
6
+ datamasque/client/discovery_configs.py,sha256=-iSDi7g8PAYXJ8aGCusGOVtE1UWD4D_pNxf68IdRei4,6967
7
7
  datamasque/client/dmclient.py,sha256=0W6s26gUl9EZRL1kdk0R_7hgZSAOesY3H5wd-tN-QIE,1940
8
8
  datamasque/client/exceptions.py,sha256=3JI_LU8K3P2BCJDjGewzj3yg6oMd_7KuQ-zwSLR8Bfs,3956
9
9
  datamasque/client/files.py,sha256=vc2tZgT8RdwuCObIQ7H-Qjb80H1PBFqD0nG5Y1tOA_o,3503
@@ -20,10 +20,10 @@ datamasque/client/table_references.py,sha256=dPyB59Sz4iLuF1lc7xffgf9qeNTFA5srT55
20
20
  datamasque/client/users.py,sha256=VCUo2CJyOw4-aO_3mp_w_0BcSoa6-h1HcReMcAMyumw,3701
21
21
  datamasque/client/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
22
22
  datamasque/client/models/connection.py,sha256=loLy4RCiIfY9kvBFspSqJSRhHqhcJxm_mQzXwMRS4VU,17529
23
- datamasque/client/models/data_selection.py,sha256=406yyUZ5NmLBSql2lYM1gsTWY5GWmnutmF-DjznAoLc,1904
24
- datamasque/client/models/discovery.py,sha256=Ejtrmja_wjHRxCWZel5Q5nZz4M20F2zdtBsdhWI1BnA,16791
25
- datamasque/client/models/discovery_config.py,sha256=1CHMgSxMXuarPGfRcz9wX7jeZLn1SDw0UEe-L5naE54,1917
26
- datamasque/client/models/discovery_config_library.py,sha256=NW4bhrlpps_SyJcX07W-dfQ_i9C0OH3O0b9TQcXPl1w,1298
23
+ datamasque/client/models/data_selection.py,sha256=9hRpkQQIQlKGFYDYQCrreggsv96dh6DelppCpCE4S2U,2725
24
+ datamasque/client/models/discovery.py,sha256=J_cAXuIpoQTzHh_-1zvBwXsFnbKI2hRywALb5Yfc5vI,17955
25
+ datamasque/client/models/discovery_config.py,sha256=8sqs9x_X0H_hR1fJDEFmOdJyGRDwgbdb3eddEAe98WE,2420
26
+ datamasque/client/models/discovery_config_library.py,sha256=m0wI51Q4aHysLNHyNTWH3KrDLV_rxtoLNeKQsF9RYFk,1436
27
27
  datamasque/client/models/dm_instance.py,sha256=6h0WNlI1qt6jkrYFapIvuSJFkhRCcwbpx0PLG5NsrGw,2219
28
28
  datamasque/client/models/files.py,sha256=7hG3Q1-XYb1PF88l3ppsmBp2tjNtvQvv-RNTrOa7Nts,2784
29
29
  datamasque/client/models/git.py,sha256=F0KdMFe2vMyL-9tp3SGKGeOlbD1gbcjQn0jpOzNzybc,1782
@@ -38,7 +38,7 @@ datamasque/client/models/safe_data_preview.py,sha256=BiI9d13KdQrTin2JfbjiRiODjns
38
38
  datamasque/client/models/status.py,sha256=WiSMEy_YxdcIA46ioYpAEu8OK8UNDoXpV1W7IUhhyVY,3219
39
39
  datamasque/client/models/table_reference.py,sha256=55fKdHjC2TQnUmbp0XiWqfeFGXqcq4wXjbWgMaN3p3c,3835
40
40
  datamasque/client/models/user.py,sha256=UGAUzgJkf78m24_zFXXoA99zdut48BXkX_ivV8yq1Vc,2043
41
- datamasque_python-1.2.1.dist-info/METADATA,sha256=zTFqfTv2d-IILIIaCglzlraCNgZ3wwHP95mpvK0AYnI,4497
42
- datamasque_python-1.2.1.dist-info/WHEEL,sha256=lCkmxWfQsSc9CfIClYeavTdQeEX2toPqufh9gI35EQA,87
43
- datamasque_python-1.2.1.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
44
- datamasque_python-1.2.1.dist-info/RECORD,,
41
+ datamasque_python-1.2.3.dist-info/METADATA,sha256=KTptpM3k1aj8jSZNhq1UKTIlyjvyjdK9j0pITk0kRFI,4497
42
+ datamasque_python-1.2.3.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
43
+ datamasque_python-1.2.3.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
44
+ datamasque_python-1.2.3.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: hatchling 1.31.0
2
+ Generator: hatchling 1.32.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any