quba-sensitive-data-protection 0.0.8__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.
quba_sdp/__init__.py ADDED
@@ -0,0 +1,8 @@
1
+ """A client library for accessing Sensitive Data Protection API"""
2
+
3
+ from .client import AuthenticatedClient, Client
4
+
5
+ __all__ = (
6
+ "AuthenticatedClient",
7
+ "Client",
8
+ )
@@ -0,0 +1 @@
1
+ """Contains methods for accessing the API"""
@@ -0,0 +1,206 @@
1
+ from http import HTTPStatus
2
+ from typing import Any
3
+
4
+ import httpx
5
+
6
+ from .. import errors
7
+ from ..client import AuthenticatedClient, Client
8
+ from ..models.anonymize_request_body import AnonymizeRequestBody
9
+ from ..models.anonymize_response_body import AnonymizeResponseBody
10
+ from ..models.http_validation_error import HTTPValidationError
11
+ from ..types import Response
12
+
13
+
14
+ def _get_kwargs(
15
+ *,
16
+ body: AnonymizeRequestBody,
17
+ ) -> dict[str, Any]:
18
+ headers: dict[str, Any] = {}
19
+
20
+ _kwargs: dict[str, Any] = {
21
+ "method": "post",
22
+ "url": "/anonymize",
23
+ }
24
+
25
+ _kwargs["json"] = body.to_dict()
26
+
27
+ headers["Content-Type"] = "application/json"
28
+
29
+ _kwargs["headers"] = headers
30
+ return _kwargs
31
+
32
+
33
+ def _parse_response(
34
+ *, client: AuthenticatedClient | Client, response: httpx.Response
35
+ ) -> AnonymizeResponseBody | HTTPValidationError | None:
36
+ if response.status_code == 200:
37
+ response_200 = AnonymizeResponseBody.from_dict(response.json())
38
+
39
+ return response_200
40
+
41
+ if response.status_code == 422:
42
+ response_422 = HTTPValidationError.from_dict(response.json())
43
+
44
+ return response_422
45
+
46
+ if client.raise_on_unexpected_status:
47
+ raise errors.UnexpectedStatus(response.status_code, response.content)
48
+ else:
49
+ return None
50
+
51
+
52
+ def _build_response(
53
+ *, client: AuthenticatedClient | Client, response: httpx.Response
54
+ ) -> Response[AnonymizeResponseBody | HTTPValidationError]:
55
+ return Response(
56
+ status_code=HTTPStatus(response.status_code),
57
+ content=response.content,
58
+ headers=response.headers,
59
+ parsed=_parse_response(client=client, response=response),
60
+ )
61
+
62
+
63
+ def sync_detailed(
64
+ *,
65
+ client: AuthenticatedClient | Client,
66
+ body: AnonymizeRequestBody,
67
+ ) -> Response[AnonymizeResponseBody | HTTPValidationError]:
68
+ """Anonymize Text
69
+
70
+ Anonymize sensitive data in text.
71
+
72
+ Scans the request text for the entities targeted by each supplied rule and
73
+ applies that rule's operation (replace, redact, mask, hash, or encrypt) to
74
+ every match. Returns the anonymized text together with a record of each
75
+ transformation, including the original and resulting character ranges.
76
+
77
+ Args:
78
+ body (AnonymizeRequestBody): Request body for the anonymize endpoint.
79
+
80
+ Carries the text to anonymize and the list of de-identification rules to
81
+ apply. See ``AnonymizationCommand`` for field-level details.
82
+
83
+ Raises:
84
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
85
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
86
+
87
+ Returns:
88
+ Response[AnonymizeResponseBody | HTTPValidationError]
89
+ """
90
+
91
+ kwargs = _get_kwargs(
92
+ body=body,
93
+ )
94
+
95
+ response = client.get_httpx_client().request(
96
+ **kwargs,
97
+ )
98
+
99
+ return _build_response(client=client, response=response)
100
+
101
+
102
+ def sync(
103
+ *,
104
+ client: AuthenticatedClient | Client,
105
+ body: AnonymizeRequestBody,
106
+ ) -> AnonymizeResponseBody | HTTPValidationError | None:
107
+ """Anonymize Text
108
+
109
+ Anonymize sensitive data in text.
110
+
111
+ Scans the request text for the entities targeted by each supplied rule and
112
+ applies that rule's operation (replace, redact, mask, hash, or encrypt) to
113
+ every match. Returns the anonymized text together with a record of each
114
+ transformation, including the original and resulting character ranges.
115
+
116
+ Args:
117
+ body (AnonymizeRequestBody): Request body for the anonymize endpoint.
118
+
119
+ Carries the text to anonymize and the list of de-identification rules to
120
+ apply. See ``AnonymizationCommand`` for field-level details.
121
+
122
+ Raises:
123
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
124
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
125
+
126
+ Returns:
127
+ AnonymizeResponseBody | HTTPValidationError
128
+ """
129
+
130
+ return sync_detailed(
131
+ client=client,
132
+ body=body,
133
+ ).parsed
134
+
135
+
136
+ async def asyncio_detailed(
137
+ *,
138
+ client: AuthenticatedClient | Client,
139
+ body: AnonymizeRequestBody,
140
+ ) -> Response[AnonymizeResponseBody | HTTPValidationError]:
141
+ """Anonymize Text
142
+
143
+ Anonymize sensitive data in text.
144
+
145
+ Scans the request text for the entities targeted by each supplied rule and
146
+ applies that rule's operation (replace, redact, mask, hash, or encrypt) to
147
+ every match. Returns the anonymized text together with a record of each
148
+ transformation, including the original and resulting character ranges.
149
+
150
+ Args:
151
+ body (AnonymizeRequestBody): Request body for the anonymize endpoint.
152
+
153
+ Carries the text to anonymize and the list of de-identification rules to
154
+ apply. See ``AnonymizationCommand`` for field-level details.
155
+
156
+ Raises:
157
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
158
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
159
+
160
+ Returns:
161
+ Response[AnonymizeResponseBody | HTTPValidationError]
162
+ """
163
+
164
+ kwargs = _get_kwargs(
165
+ body=body,
166
+ )
167
+
168
+ response = await client.get_async_httpx_client().request(**kwargs)
169
+
170
+ return _build_response(client=client, response=response)
171
+
172
+
173
+ async def asyncio(
174
+ *,
175
+ client: AuthenticatedClient | Client,
176
+ body: AnonymizeRequestBody,
177
+ ) -> AnonymizeResponseBody | HTTPValidationError | None:
178
+ """Anonymize Text
179
+
180
+ Anonymize sensitive data in text.
181
+
182
+ Scans the request text for the entities targeted by each supplied rule and
183
+ applies that rule's operation (replace, redact, mask, hash, or encrypt) to
184
+ every match. Returns the anonymized text together with a record of each
185
+ transformation, including the original and resulting character ranges.
186
+
187
+ Args:
188
+ body (AnonymizeRequestBody): Request body for the anonymize endpoint.
189
+
190
+ Carries the text to anonymize and the list of de-identification rules to
191
+ apply. See ``AnonymizationCommand`` for field-level details.
192
+
193
+ Raises:
194
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
195
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
196
+
197
+ Returns:
198
+ AnonymizeResponseBody | HTTPValidationError
199
+ """
200
+
201
+ return (
202
+ await asyncio_detailed(
203
+ client=client,
204
+ body=body,
205
+ )
206
+ ).parsed
@@ -0,0 +1,142 @@
1
+ from http import HTTPStatus
2
+ from typing import Any, cast
3
+
4
+ import httpx
5
+
6
+ from .. import errors
7
+ from ..client import AuthenticatedClient, Client
8
+ from ..types import Response
9
+
10
+
11
+ def _get_kwargs() -> dict[str, Any]:
12
+
13
+ _kwargs: dict[str, Any] = {
14
+ "method": "get",
15
+ "url": "/health",
16
+ }
17
+
18
+ return _kwargs
19
+
20
+
21
+ def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> str | None:
22
+ if response.status_code == 200:
23
+ response_200 = cast(str, response.json())
24
+ return response_200
25
+
26
+ if client.raise_on_unexpected_status:
27
+ raise errors.UnexpectedStatus(response.status_code, response.content)
28
+ else:
29
+ return None
30
+
31
+
32
+ def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[str]:
33
+ return Response(
34
+ status_code=HTTPStatus(response.status_code),
35
+ content=response.content,
36
+ headers=response.headers,
37
+ parsed=_parse_response(client=client, response=response),
38
+ )
39
+
40
+
41
+ def sync_detailed(
42
+ *,
43
+ client: AuthenticatedClient | Client,
44
+ ) -> Response[str]:
45
+ """Health
46
+
47
+ Health check.
48
+
49
+ Returns a plain-text message confirming the service is running. Use this as
50
+ a liveness/readiness probe.
51
+
52
+ Raises:
53
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
54
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
55
+
56
+ Returns:
57
+ Response[str]
58
+ """
59
+
60
+ kwargs = _get_kwargs()
61
+
62
+ response = client.get_httpx_client().request(
63
+ **kwargs,
64
+ )
65
+
66
+ return _build_response(client=client, response=response)
67
+
68
+
69
+ def sync(
70
+ *,
71
+ client: AuthenticatedClient | Client,
72
+ ) -> str | None:
73
+ """Health
74
+
75
+ Health check.
76
+
77
+ Returns a plain-text message confirming the service is running. Use this as
78
+ a liveness/readiness probe.
79
+
80
+ Raises:
81
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
82
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
83
+
84
+ Returns:
85
+ str
86
+ """
87
+
88
+ return sync_detailed(
89
+ client=client,
90
+ ).parsed
91
+
92
+
93
+ async def asyncio_detailed(
94
+ *,
95
+ client: AuthenticatedClient | Client,
96
+ ) -> Response[str]:
97
+ """Health
98
+
99
+ Health check.
100
+
101
+ Returns a plain-text message confirming the service is running. Use this as
102
+ a liveness/readiness probe.
103
+
104
+ Raises:
105
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
106
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
107
+
108
+ Returns:
109
+ Response[str]
110
+ """
111
+
112
+ kwargs = _get_kwargs()
113
+
114
+ response = await client.get_async_httpx_client().request(**kwargs)
115
+
116
+ return _build_response(client=client, response=response)
117
+
118
+
119
+ async def asyncio(
120
+ *,
121
+ client: AuthenticatedClient | Client,
122
+ ) -> str | None:
123
+ """Health
124
+
125
+ Health check.
126
+
127
+ Returns a plain-text message confirming the service is running. Use this as
128
+ a liveness/readiness probe.
129
+
130
+ Raises:
131
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
132
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
133
+
134
+ Returns:
135
+ str
136
+ """
137
+
138
+ return (
139
+ await asyncio_detailed(
140
+ client=client,
141
+ )
142
+ ).parsed
@@ -0,0 +1,194 @@
1
+ from http import HTTPStatus
2
+ from typing import Any
3
+
4
+ import httpx
5
+
6
+ from .. import errors
7
+ from ..client import AuthenticatedClient, Client
8
+ from ..models.http_validation_error import HTTPValidationError
9
+ from ..models.scan_request_body import ScanRequestBody
10
+ from ..models.scan_response_body import ScanResponseBody
11
+ from ..types import Response
12
+
13
+
14
+ def _get_kwargs(
15
+ *,
16
+ body: ScanRequestBody,
17
+ ) -> dict[str, Any]:
18
+ headers: dict[str, Any] = {}
19
+
20
+ _kwargs: dict[str, Any] = {
21
+ "method": "post",
22
+ "url": "/scan",
23
+ }
24
+
25
+ _kwargs["json"] = body.to_dict()
26
+
27
+ headers["Content-Type"] = "application/json"
28
+
29
+ _kwargs["headers"] = headers
30
+ return _kwargs
31
+
32
+
33
+ def _parse_response(
34
+ *, client: AuthenticatedClient | Client, response: httpx.Response
35
+ ) -> HTTPValidationError | ScanResponseBody | None:
36
+ if response.status_code == 200:
37
+ response_200 = ScanResponseBody.from_dict(response.json())
38
+
39
+ return response_200
40
+
41
+ if response.status_code == 422:
42
+ response_422 = HTTPValidationError.from_dict(response.json())
43
+
44
+ return response_422
45
+
46
+ if client.raise_on_unexpected_status:
47
+ raise errors.UnexpectedStatus(response.status_code, response.content)
48
+ else:
49
+ return None
50
+
51
+
52
+ def _build_response(
53
+ *, client: AuthenticatedClient | Client, response: httpx.Response
54
+ ) -> Response[HTTPValidationError | ScanResponseBody]:
55
+ return Response(
56
+ status_code=HTTPStatus(response.status_code),
57
+ content=response.content,
58
+ headers=response.headers,
59
+ parsed=_parse_response(client=client, response=response),
60
+ )
61
+
62
+
63
+ def sync_detailed(
64
+ *,
65
+ client: AuthenticatedClient | Client,
66
+ body: ScanRequestBody,
67
+ ) -> Response[HTTPValidationError | ScanResponseBody]:
68
+ """Scan Text
69
+
70
+ Scan text for sensitive data.
71
+
72
+ Runs the configured detection entities over the request text and returns
73
+ every match as a character range with its entity type and confidence score.
74
+ Detections below the confidence threshold are omitted.
75
+
76
+ Args:
77
+ body (ScanRequestBody): Request body for the scan endpoint: the text to inspect and which
78
+ entity types to detect.
79
+
80
+ Raises:
81
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
82
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
83
+
84
+ Returns:
85
+ Response[HTTPValidationError | ScanResponseBody]
86
+ """
87
+
88
+ kwargs = _get_kwargs(
89
+ body=body,
90
+ )
91
+
92
+ response = client.get_httpx_client().request(
93
+ **kwargs,
94
+ )
95
+
96
+ return _build_response(client=client, response=response)
97
+
98
+
99
+ def sync(
100
+ *,
101
+ client: AuthenticatedClient | Client,
102
+ body: ScanRequestBody,
103
+ ) -> HTTPValidationError | ScanResponseBody | None:
104
+ """Scan Text
105
+
106
+ Scan text for sensitive data.
107
+
108
+ Runs the configured detection entities over the request text and returns
109
+ every match as a character range with its entity type and confidence score.
110
+ Detections below the confidence threshold are omitted.
111
+
112
+ Args:
113
+ body (ScanRequestBody): Request body for the scan endpoint: the text to inspect and which
114
+ entity types to detect.
115
+
116
+ Raises:
117
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
118
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
119
+
120
+ Returns:
121
+ HTTPValidationError | ScanResponseBody
122
+ """
123
+
124
+ return sync_detailed(
125
+ client=client,
126
+ body=body,
127
+ ).parsed
128
+
129
+
130
+ async def asyncio_detailed(
131
+ *,
132
+ client: AuthenticatedClient | Client,
133
+ body: ScanRequestBody,
134
+ ) -> Response[HTTPValidationError | ScanResponseBody]:
135
+ """Scan Text
136
+
137
+ Scan text for sensitive data.
138
+
139
+ Runs the configured detection entities over the request text and returns
140
+ every match as a character range with its entity type and confidence score.
141
+ Detections below the confidence threshold are omitted.
142
+
143
+ Args:
144
+ body (ScanRequestBody): Request body for the scan endpoint: the text to inspect and which
145
+ entity types to detect.
146
+
147
+ Raises:
148
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
149
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
150
+
151
+ Returns:
152
+ Response[HTTPValidationError | ScanResponseBody]
153
+ """
154
+
155
+ kwargs = _get_kwargs(
156
+ body=body,
157
+ )
158
+
159
+ response = await client.get_async_httpx_client().request(**kwargs)
160
+
161
+ return _build_response(client=client, response=response)
162
+
163
+
164
+ async def asyncio(
165
+ *,
166
+ client: AuthenticatedClient | Client,
167
+ body: ScanRequestBody,
168
+ ) -> HTTPValidationError | ScanResponseBody | None:
169
+ """Scan Text
170
+
171
+ Scan text for sensitive data.
172
+
173
+ Runs the configured detection entities over the request text and returns
174
+ every match as a character range with its entity type and confidence score.
175
+ Detections below the confidence threshold are omitted.
176
+
177
+ Args:
178
+ body (ScanRequestBody): Request body for the scan endpoint: the text to inspect and which
179
+ entity types to detect.
180
+
181
+ Raises:
182
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
183
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
184
+
185
+ Returns:
186
+ HTTPValidationError | ScanResponseBody
187
+ """
188
+
189
+ return (
190
+ await asyncio_detailed(
191
+ client=client,
192
+ body=body,
193
+ )
194
+ ).parsed