quantumapi 0.24.0__tar.gz → 0.25.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.
Files changed (57) hide show
  1. {quantumapi-0.24.0/quantumapi.egg-info → quantumapi-0.25.0}/PKG-INFO +94 -1
  2. {quantumapi-0.24.0 → quantumapi-0.25.0}/README.md +93 -0
  3. {quantumapi-0.24.0 → quantumapi-0.25.0}/pyproject.toml +1 -1
  4. {quantumapi-0.24.0 → quantumapi-0.25.0}/quantumapi/__init__.py +1 -1
  5. {quantumapi-0.24.0 → quantumapi-0.25.0}/quantumapi/client/__init__.py +6 -0
  6. {quantumapi-0.24.0 → quantumapi-0.25.0}/quantumapi/client/async_client.py +6 -0
  7. {quantumapi-0.24.0 → quantumapi-0.25.0}/quantumapi/client/base.py +70 -5
  8. quantumapi-0.25.0/quantumapi/client/compliance.py +103 -0
  9. quantumapi-0.25.0/quantumapi/client/log_streams.py +178 -0
  10. {quantumapi-0.24.0 → quantumapi-0.25.0}/quantumapi/client/sync_client.py +5 -1
  11. quantumapi-0.25.0/quantumapi/client/usage.py +25 -0
  12. {quantumapi-0.24.0 → quantumapi-0.25.0}/quantumapi/models/__init__.py +53 -0
  13. quantumapi-0.25.0/quantumapi/models/compliance.py +144 -0
  14. quantumapi-0.25.0/quantumapi/models/log_streams.py +151 -0
  15. quantumapi-0.25.0/quantumapi/models/usage.py +62 -0
  16. {quantumapi-0.24.0 → quantumapi-0.25.0/quantumapi.egg-info}/PKG-INFO +94 -1
  17. {quantumapi-0.24.0 → quantumapi-0.25.0}/quantumapi.egg-info/SOURCES.txt +7 -0
  18. quantumapi-0.25.0/tests/test_compliance_logstreams_usage.py +645 -0
  19. {quantumapi-0.24.0 → quantumapi-0.25.0}/LICENSE +0 -0
  20. {quantumapi-0.24.0 → quantumapi-0.25.0}/quantumapi/client/applications.py +0 -0
  21. {quantumapi-0.24.0 → quantumapi-0.25.0}/quantumapi/client/audit.py +0 -0
  22. {quantumapi-0.24.0 → quantumapi-0.25.0}/quantumapi/client/encryption.py +0 -0
  23. {quantumapi-0.24.0 → quantumapi-0.25.0}/quantumapi/client/end_users.py +0 -0
  24. {quantumapi-0.24.0 → quantumapi-0.25.0}/quantumapi/client/health.py +0 -0
  25. {quantumapi-0.24.0 → quantumapi-0.25.0}/quantumapi/client/keys.py +0 -0
  26. {quantumapi-0.24.0 → quantumapi-0.25.0}/quantumapi/client/qrng.py +0 -0
  27. {quantumapi-0.24.0 → quantumapi-0.25.0}/quantumapi/client/resource_groups.py +0 -0
  28. {quantumapi-0.24.0 → quantumapi-0.25.0}/quantumapi/client/roles.py +0 -0
  29. {quantumapi-0.24.0 → quantumapi-0.25.0}/quantumapi/client/secrets.py +0 -0
  30. {quantumapi-0.24.0 → quantumapi-0.25.0}/quantumapi/client/transit.py +0 -0
  31. {quantumapi-0.24.0 → quantumapi-0.25.0}/quantumapi/errors/__init__.py +0 -0
  32. {quantumapi-0.24.0 → quantumapi-0.25.0}/quantumapi/errors/exceptions.py +0 -0
  33. {quantumapi-0.24.0 → quantumapi-0.25.0}/quantumapi/models/applications.py +0 -0
  34. {quantumapi-0.24.0 → quantumapi-0.25.0}/quantumapi/models/audit.py +0 -0
  35. {quantumapi-0.24.0 → quantumapi-0.25.0}/quantumapi/models/encryption.py +0 -0
  36. {quantumapi-0.24.0 → quantumapi-0.25.0}/quantumapi/models/end_users.py +0 -0
  37. {quantumapi-0.24.0 → quantumapi-0.25.0}/quantumapi/models/health.py +0 -0
  38. {quantumapi-0.24.0 → quantumapi-0.25.0}/quantumapi/models/keys.py +0 -0
  39. {quantumapi-0.24.0 → quantumapi-0.25.0}/quantumapi/models/qrng.py +0 -0
  40. {quantumapi-0.24.0 → quantumapi-0.25.0}/quantumapi/models/resource_groups.py +0 -0
  41. {quantumapi-0.24.0 → quantumapi-0.25.0}/quantumapi/models/roles.py +0 -0
  42. {quantumapi-0.24.0 → quantumapi-0.25.0}/quantumapi/models/secrets.py +0 -0
  43. {quantumapi-0.24.0 → quantumapi-0.25.0}/quantumapi/models/transit.py +0 -0
  44. {quantumapi-0.24.0 → quantumapi-0.25.0}/quantumapi/py.typed +0 -0
  45. {quantumapi-0.24.0 → quantumapi-0.25.0}/quantumapi.egg-info/dependency_links.txt +0 -0
  46. {quantumapi-0.24.0 → quantumapi-0.25.0}/quantumapi.egg-info/requires.txt +0 -0
  47. {quantumapi-0.24.0 → quantumapi-0.25.0}/quantumapi.egg-info/top_level.txt +0 -0
  48. {quantumapi-0.24.0 → quantumapi-0.25.0}/setup.cfg +0 -0
  49. {quantumapi-0.24.0 → quantumapi-0.25.0}/tests/test_audit.py +0 -0
  50. {quantumapi-0.24.0 → quantumapi-0.25.0}/tests/test_data_keys.py +0 -0
  51. {quantumapi-0.24.0 → quantumapi-0.25.0}/tests/test_end_users.py +0 -0
  52. {quantumapi-0.24.0 → quantumapi-0.25.0}/tests/test_exceptions.py +0 -0
  53. {quantumapi-0.24.0 → quantumapi-0.25.0}/tests/test_models.py +0 -0
  54. {quantumapi-0.24.0 → quantumapi-0.25.0}/tests/test_parity.py +0 -0
  55. {quantumapi-0.24.0 → quantumapi-0.25.0}/tests/test_qrng.py +0 -0
  56. {quantumapi-0.24.0 → quantumapi-0.25.0}/tests/test_secret_history_share.py +0 -0
  57. {quantumapi-0.24.0 → quantumapi-0.25.0}/tests/test_transit.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: quantumapi
3
- Version: 0.24.0
3
+ Version: 0.25.0
4
4
  Summary: Official Python SDK for QuantumAPI - Quantum-safe encryption and identity platform
5
5
  Author-email: QuantumAPI Team <developers@quantumapi.eu>
6
6
  License-Expression: MIT
@@ -441,6 +441,99 @@ batch = await client.transit.batch_encrypt("orders", [b"a", b"b"]) # up to 10
441
441
  Errors: `KeyRevokedError` (403 `key_revoked`) and `InsufficientScopeError` (403 `insufficient_scope`),
442
442
  both subclasses of `PermissionError`.
443
443
 
444
+ ### Compliance Client
445
+
446
+ Scores for GDPR, NIS2, DORA and eIDAS 2 (`gdpr`, `nis2`, `dora`, `eidas2`), plus risk
447
+ acceptances of failing or warning checks. Tenant owner/admin only. Risk acceptances need
448
+ platform 0.27.0 or later.
449
+
450
+ ```python
451
+ from datetime import datetime, timezone
452
+ from quantumapi.models import ComplianceCheckStatus
453
+
454
+ overview = await client.compliance.get_overview()
455
+ for fw in overview.frameworks:
456
+ print(fw.framework, fw.score, fw.fail_count, fw.risk_accepted_count)
457
+
458
+ report = await client.compliance.get_report("dora")
459
+ for check in report.checks:
460
+ # status: Pass, Warning, Fail, NotApplicable or RiskAccepted (unknown future values stay strings).
461
+ # evaluated_status is the status before applying a risk acceptance.
462
+ print(check.id, check.status, check.evaluated_status)
463
+
464
+ # Accept the risk of a failing/warning check (justification 10-2000 chars, review_date in the future).
465
+ # Accepting again replaces the earlier acceptance. ConflictError (409) if the check is passing,
466
+ # NotFoundError (404) for an unknown check.
467
+ acceptance = await client.compliance.accept_risk(
468
+ "dora",
469
+ "operational-monitoring",
470
+ "Logs are shipped by our on-prem collector; SIEM integration planned for Q1.",
471
+ review_date=datetime(2027, 1, 31, tzinfo=timezone.utc),
472
+ )
473
+
474
+ # Revoke it (returns the revoked acceptance; NotFoundError if none is open)
475
+ revoked = await client.compliance.revoke_risk_acceptance("dora", "operational-monitoring")
476
+
477
+ # Full history, newest first, including revoked and expired acceptances
478
+ history = await client.compliance.list_risk_acceptances()
479
+ for a in history.items:
480
+ print(a.check_id, a.accepted_by, a.is_active, a.is_expired)
481
+ ```
482
+
483
+ ### Log Streams Client
484
+
485
+ Streams authentication logs to a Webhook, Datadog, Splunk or the built-in File destination
486
+ (daily gzip NDJSON archives you download). Tenant owner/admin only. The File destination needs
487
+ platform 0.27.0 or later. `config_json` is a JSON-encoded string on the wire.
488
+
489
+ ```python
490
+ from datetime import date
491
+ from quantumapi.models import LogStreamType, file_stream_config
492
+
493
+ # File destination: retention 7, 30 (default) or 365 days. file_stream_config raises ValueError otherwise.
494
+ stream = await client.log_streams.create("SIEM archive", LogStreamType.FILE, file_stream_config(365))
495
+ print(stream.retention_days) # 365
496
+
497
+ # Other destinations take their own config string
498
+ await client.log_streams.create("SIEM", "Webhook", '{"url": "https://siem.example.com/ingest"}')
499
+
500
+ streams = await client.log_streams.list()
501
+ await client.log_streams.update(stream.id, "SIEM archive", "File", file_stream_config(30))
502
+ result = await client.log_streams.test(stream.id) # File: checks the destination is writable
503
+ await client.log_streams.deactivate(stream.id)
504
+ await client.log_streams.activate(stream.id)
505
+
506
+ # Daily archives (UTC days), newest first
507
+ files = await client.log_streams.list_files(stream.id)
508
+ for d in files.days:
509
+ print(d.day, d.line_count, d.size_bytes)
510
+
511
+ # Download one day as raw gzip bytes (not decompressed; may hold several gzip members,
512
+ # which gzip.decompress handles). day is a datetime.date or "YYYY-MM-DD".
513
+ data = await client.log_streams.download_file(stream.id, date(2026, 10, 24))
514
+
515
+ # Or write it to disk. A directory gets the default name auth-logs-<day>.ndjson.gz.
516
+ path = await client.log_streams.download_file_to(stream.id, "2026-10-24", "./archives")
517
+
518
+ await client.log_streams.delete(stream.id)
519
+ ```
520
+
521
+ ### Usage Client
522
+
523
+ Storage occupied by the tenant this month, in total and per category (`secrets`, `keys`,
524
+ `certificates`, `attachments`, `log_archives`). Any tenant role. Informative only: not invoiced
525
+ or enforced yet. Usage is priced by space occupied, never per user, key or secret. Needs platform
526
+ 0.27.0 or later.
527
+
528
+ ```python
529
+ storage = await client.usage.get_storage()
530
+ print(storage.period_start, storage.period_end, storage.as_of)
531
+ print(storage.total_bytes, storage.month_average_bytes, storage.gb_months_accrued) # 1 GB = 2^30 bytes
532
+ for c in storage.categories:
533
+ print(c.id, c.bytes, c.items, c.gb_months_accrued)
534
+ print(storage.category("log_archives"))
535
+ ```
536
+
444
537
  ## Error Handling
445
538
 
446
539
  The SDK provides typed exceptions for all error scenarios:
@@ -400,6 +400,99 @@ batch = await client.transit.batch_encrypt("orders", [b"a", b"b"]) # up to 10
400
400
  Errors: `KeyRevokedError` (403 `key_revoked`) and `InsufficientScopeError` (403 `insufficient_scope`),
401
401
  both subclasses of `PermissionError`.
402
402
 
403
+ ### Compliance Client
404
+
405
+ Scores for GDPR, NIS2, DORA and eIDAS 2 (`gdpr`, `nis2`, `dora`, `eidas2`), plus risk
406
+ acceptances of failing or warning checks. Tenant owner/admin only. Risk acceptances need
407
+ platform 0.27.0 or later.
408
+
409
+ ```python
410
+ from datetime import datetime, timezone
411
+ from quantumapi.models import ComplianceCheckStatus
412
+
413
+ overview = await client.compliance.get_overview()
414
+ for fw in overview.frameworks:
415
+ print(fw.framework, fw.score, fw.fail_count, fw.risk_accepted_count)
416
+
417
+ report = await client.compliance.get_report("dora")
418
+ for check in report.checks:
419
+ # status: Pass, Warning, Fail, NotApplicable or RiskAccepted (unknown future values stay strings).
420
+ # evaluated_status is the status before applying a risk acceptance.
421
+ print(check.id, check.status, check.evaluated_status)
422
+
423
+ # Accept the risk of a failing/warning check (justification 10-2000 chars, review_date in the future).
424
+ # Accepting again replaces the earlier acceptance. ConflictError (409) if the check is passing,
425
+ # NotFoundError (404) for an unknown check.
426
+ acceptance = await client.compliance.accept_risk(
427
+ "dora",
428
+ "operational-monitoring",
429
+ "Logs are shipped by our on-prem collector; SIEM integration planned for Q1.",
430
+ review_date=datetime(2027, 1, 31, tzinfo=timezone.utc),
431
+ )
432
+
433
+ # Revoke it (returns the revoked acceptance; NotFoundError if none is open)
434
+ revoked = await client.compliance.revoke_risk_acceptance("dora", "operational-monitoring")
435
+
436
+ # Full history, newest first, including revoked and expired acceptances
437
+ history = await client.compliance.list_risk_acceptances()
438
+ for a in history.items:
439
+ print(a.check_id, a.accepted_by, a.is_active, a.is_expired)
440
+ ```
441
+
442
+ ### Log Streams Client
443
+
444
+ Streams authentication logs to a Webhook, Datadog, Splunk or the built-in File destination
445
+ (daily gzip NDJSON archives you download). Tenant owner/admin only. The File destination needs
446
+ platform 0.27.0 or later. `config_json` is a JSON-encoded string on the wire.
447
+
448
+ ```python
449
+ from datetime import date
450
+ from quantumapi.models import LogStreamType, file_stream_config
451
+
452
+ # File destination: retention 7, 30 (default) or 365 days. file_stream_config raises ValueError otherwise.
453
+ stream = await client.log_streams.create("SIEM archive", LogStreamType.FILE, file_stream_config(365))
454
+ print(stream.retention_days) # 365
455
+
456
+ # Other destinations take their own config string
457
+ await client.log_streams.create("SIEM", "Webhook", '{"url": "https://siem.example.com/ingest"}')
458
+
459
+ streams = await client.log_streams.list()
460
+ await client.log_streams.update(stream.id, "SIEM archive", "File", file_stream_config(30))
461
+ result = await client.log_streams.test(stream.id) # File: checks the destination is writable
462
+ await client.log_streams.deactivate(stream.id)
463
+ await client.log_streams.activate(stream.id)
464
+
465
+ # Daily archives (UTC days), newest first
466
+ files = await client.log_streams.list_files(stream.id)
467
+ for d in files.days:
468
+ print(d.day, d.line_count, d.size_bytes)
469
+
470
+ # Download one day as raw gzip bytes (not decompressed; may hold several gzip members,
471
+ # which gzip.decompress handles). day is a datetime.date or "YYYY-MM-DD".
472
+ data = await client.log_streams.download_file(stream.id, date(2026, 10, 24))
473
+
474
+ # Or write it to disk. A directory gets the default name auth-logs-<day>.ndjson.gz.
475
+ path = await client.log_streams.download_file_to(stream.id, "2026-10-24", "./archives")
476
+
477
+ await client.log_streams.delete(stream.id)
478
+ ```
479
+
480
+ ### Usage Client
481
+
482
+ Storage occupied by the tenant this month, in total and per category (`secrets`, `keys`,
483
+ `certificates`, `attachments`, `log_archives`). Any tenant role. Informative only: not invoiced
484
+ or enforced yet. Usage is priced by space occupied, never per user, key or secret. Needs platform
485
+ 0.27.0 or later.
486
+
487
+ ```python
488
+ storage = await client.usage.get_storage()
489
+ print(storage.period_start, storage.period_end, storage.as_of)
490
+ print(storage.total_bytes, storage.month_average_bytes, storage.gb_months_accrued) # 1 GB = 2^30 bytes
491
+ for c in storage.categories:
492
+ print(c.id, c.bytes, c.items, c.gb_months_accrued)
493
+ print(storage.category("log_archives"))
494
+ ```
495
+
403
496
  ## Error Handling
404
497
 
405
498
  The SDK provides typed exceptions for all error scenarios:
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "quantumapi"
7
- version = "0.24.0"
7
+ version = "0.25.0"
8
8
  description = "Official Python SDK for QuantumAPI - Quantum-safe encryption and identity platform"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.9"
@@ -9,7 +9,7 @@ Example:
9
9
  >>> secret = await client.secrets.create(name="test", value="secret")
10
10
  """
11
11
 
12
- __version__ = "0.1.0-beta"
12
+ __version__ = "0.25.0"
13
13
  __author__ = "QuantumAPI Team"
14
14
  __email__ = "developers@quantumapi.eu"
15
15
 
@@ -2,14 +2,17 @@
2
2
 
3
3
  from quantumapi.client.applications import ApplicationsClient
4
4
  from quantumapi.client.async_client import QuantumAPIClient
5
+ from quantumapi.client.compliance import ComplianceClient
5
6
  from quantumapi.client.encryption import EncryptionClient
6
7
  from quantumapi.client.end_users import EndUsersClient
7
8
  from quantumapi.client.health import HealthClient
8
9
  from quantumapi.client.audit import AuditClient
9
10
  from quantumapi.client.keys import KeysClient
11
+ from quantumapi.client.log_streams import LogStreamsClient
10
12
  from quantumapi.client.qrng import QrngClient
11
13
  from quantumapi.client.secrets import SecretsClient
12
14
  from quantumapi.client.sync_client import QuantumAPISyncClient
15
+ from quantumapi.client.usage import UsageClient
13
16
 
14
17
  __all__ = [
15
18
  "QuantumAPIClient",
@@ -22,4 +25,7 @@ __all__ = [
22
25
  "QrngClient",
23
26
  "SecretsClient",
24
27
  "HealthClient",
28
+ "ComplianceClient",
29
+ "LogStreamsClient",
30
+ "UsageClient",
25
31
  ]
@@ -5,16 +5,19 @@ from typing import Optional
5
5
 
6
6
  from quantumapi.client.applications import ApplicationsClient
7
7
  from quantumapi.client.base import BaseClient
8
+ from quantumapi.client.compliance import ComplianceClient
8
9
  from quantumapi.client.encryption import EncryptionClient
9
10
  from quantumapi.client.end_users import EndUsersClient
10
11
  from quantumapi.client.health import HealthClient
11
12
  from quantumapi.client.audit import AuditClient
12
13
  from quantumapi.client.keys import KeysClient
14
+ from quantumapi.client.log_streams import LogStreamsClient
13
15
  from quantumapi.client.qrng import QrngClient
14
16
  from quantumapi.client.resource_groups import ResourceGroupsClient
15
17
  from quantumapi.client.roles import RolesClient
16
18
  from quantumapi.client.secrets import SecretsClient
17
19
  from quantumapi.client.transit import TransitClient
20
+ from quantumapi.client.usage import UsageClient
18
21
 
19
22
 
20
23
  class QuantumAPIClient:
@@ -93,6 +96,9 @@ class QuantumAPIClient:
93
96
  self.health = HealthClient(self._base_client)
94
97
  self.qrng = QrngClient(self._base_client)
95
98
  self.transit = TransitClient(self._base_client)
99
+ self.compliance = ComplianceClient(self._base_client)
100
+ self.log_streams = LogStreamsClient(self._base_client)
101
+ self.usage = UsageClient(self._base_client)
96
102
 
97
103
  async def close(self) -> None:
98
104
  """
@@ -1,12 +1,13 @@
1
1
  """Base HTTP client with retry logic and error handling."""
2
2
 
3
3
  import logging
4
- from typing import Any, Dict, Optional
4
+ from typing import Any, Dict, NoReturn, Optional, Union, cast
5
5
  from urllib.parse import urljoin
6
6
 
7
7
  import httpx
8
8
  from httpx import Response
9
9
 
10
+ from quantumapi import __version__
10
11
  from quantumapi.errors import (
11
12
  AuthenticationError,
12
13
  ConflictError,
@@ -69,7 +70,7 @@ class BaseClient:
69
70
  "X-Api-Key": self.api_key,
70
71
  "Content-Type": "application/json",
71
72
  "Accept": "application/json",
72
- "User-Agent": "quantumapi-python/0.1.0-beta",
73
+ "User-Agent": f"quantumapi-python/{__version__}",
73
74
  }
74
75
 
75
76
  def _build_url(self, endpoint: str) -> str:
@@ -112,11 +113,39 @@ class BaseClient:
112
113
  return {}
113
114
  return response.json()
114
115
 
115
- # Error responses
116
+ self._raise_for_error(response)
117
+
118
+ async def _handle_binary_response(self, response: Response) -> bytes:
119
+ """
120
+ Handle an HTTP response whose success body is binary (e.g. a gzip download).
121
+
122
+ Returns:
123
+ The raw response body, untouched (not decompressed)
124
+
125
+ Raises:
126
+ QuantumAPIError: On API errors (the error body is parsed like a JSON response)
127
+ """
128
+ if self.enable_logging:
129
+ logger.debug(
130
+ f"Response: {response.status_code} {response.request.method} "
131
+ f"{response.request.url}"
132
+ )
133
+ if 200 <= response.status_code < 300:
134
+ return response.content
135
+ self._raise_for_error(response)
136
+
137
+ def _raise_for_error(self, response: Response) -> NoReturn:
138
+ """Map a non-2xx response to the matching QuantumAPIError subclass and raise it."""
116
139
  try:
117
140
  error_data = response.json()
118
141
  error_code = error_data.get("error", "unknown_error")
119
- error_message = error_data.get("message", "An error occurred")
142
+ # Plain {"error", "message"} bodies, ProblemDetails ({"title", "detail"}) and
143
+ # {"error": "<human readable sentence>"} bodies all yield a useful message.
144
+ error_message = error_data.get("message") or error_data.get("detail")
145
+ if not error_message and isinstance(error_code, str) and " " in error_code:
146
+ error_message = error_code
147
+ if not error_message:
148
+ error_message = error_data.get("title") or "An error occurred"
120
149
  error_details = error_data.get("details")
121
150
  except Exception:
122
151
  error_code = None
@@ -208,6 +237,19 @@ class BaseClient:
208
237
  params: Optional[Dict[str, Any]] = None,
209
238
  headers: Optional[Dict[str, str]] = None,
210
239
  ) -> Dict[str, Any]:
240
+ """Make an HTTP request with retry logic and return the parsed JSON body."""
241
+ result = await self._execute(method, endpoint, json_data, params, headers, binary=False)
242
+ return cast(Dict[str, Any], result)
243
+
244
+ async def _execute(
245
+ self,
246
+ method: str,
247
+ endpoint: str,
248
+ json_data: Optional[Dict[str, Any]] = None,
249
+ params: Optional[Dict[str, Any]] = None,
250
+ headers: Optional[Dict[str, str]] = None,
251
+ binary: bool = False,
252
+ ) -> Union[Dict[str, Any], bytes]:
211
253
  """
212
254
  Make HTTP request with retry logic.
213
255
 
@@ -217,9 +259,10 @@ class BaseClient:
217
259
  json_data: JSON request body
218
260
  params: URL query parameters
219
261
  headers: Additional headers
262
+ binary: Return the raw body bytes instead of parsing JSON
220
263
 
221
264
  Returns:
222
- Parsed JSON response
265
+ Parsed JSON response, or the raw body when ``binary`` is True
223
266
 
224
267
  Raises:
225
268
  QuantumAPIError: On API errors
@@ -249,6 +292,8 @@ class BaseClient:
249
292
  params=params,
250
293
  headers=request_headers,
251
294
  )
295
+ if binary:
296
+ return await self._handle_binary_response(response)
252
297
  return await self._handle_response(response)
253
298
 
254
299
  except httpx.TimeoutException as e:
@@ -305,6 +350,26 @@ class BaseClient:
305
350
  """Make GET request."""
306
351
  return await self._request("GET", endpoint, params=params, headers=headers)
307
352
 
353
+ async def get_bytes(
354
+ self,
355
+ endpoint: str,
356
+ params: Optional[Dict[str, Any]] = None,
357
+ headers: Optional[Dict[str, str]] = None,
358
+ ) -> bytes:
359
+ """
360
+ Make GET request for a binary download and return the raw body.
361
+
362
+ The body is returned as sent (a gzip file stays compressed). Errors are mapped
363
+ to exceptions exactly as for JSON requests.
364
+ """
365
+ request_headers = {"Accept": "*/*"}
366
+ if headers:
367
+ request_headers.update(headers)
368
+ result = await self._execute(
369
+ "GET", endpoint, params=params, headers=request_headers, binary=True
370
+ )
371
+ return cast(bytes, result)
372
+
308
373
  async def post(
309
374
  self,
310
375
  endpoint: str,
@@ -0,0 +1,103 @@
1
+ """Compliance dashboard client for QuantumAPI SDK (GDPR, NIS2, DORA, eIDAS 2)."""
2
+
3
+ from datetime import datetime
4
+ from typing import Optional
5
+ from urllib.parse import quote
6
+
7
+ from quantumapi.client.base import BaseClient
8
+ from quantumapi.models.compliance import (
9
+ AcceptRiskRequest,
10
+ ComplianceOverview,
11
+ ComplianceReport,
12
+ ComplianceRiskAcceptance,
13
+ ComplianceRiskAcceptanceListResponse,
14
+ )
15
+
16
+
17
+ def _segment(value: str) -> str:
18
+ return quote(str(value), safe="")
19
+
20
+
21
+ class ComplianceClient:
22
+ """
23
+ Client for the compliance dashboard and its risk acceptances.
24
+
25
+ Requires a tenant owner or admin (403 otherwise). Frameworks: ``gdpr``, ``nis2``,
26
+ ``dora``, ``eidas2`` (case-insensitive). Requires platform 0.27.0 or later for risk
27
+ acceptances.
28
+ """
29
+
30
+ def __init__(self, base_client: BaseClient) -> None:
31
+ self._client = base_client
32
+
33
+ async def get_overview(self) -> ComplianceOverview:
34
+ """
35
+ Get the score of every framework (``GET /api/v1/compliance``).
36
+
37
+ Example:
38
+ >>> overview = await client.compliance.get_overview()
39
+ >>> for fw in overview.frameworks:
40
+ ... print(fw.framework, fw.score, fw.risk_accepted_count)
41
+ """
42
+ response = await self._client.get("/api/v1/compliance")
43
+ return ComplianceOverview(**response)
44
+
45
+ async def get_report(self, framework: str) -> ComplianceReport:
46
+ """
47
+ Get the checks of one framework (``GET /api/v1/compliance/{framework}``).
48
+
49
+ Raises:
50
+ ValidationError: Unknown framework (400)
51
+ """
52
+ response = await self._client.get(f"/api/v1/compliance/{_segment(framework)}")
53
+ return ComplianceReport(**response)
54
+
55
+ async def accept_risk(
56
+ self,
57
+ framework: str,
58
+ check_id: str,
59
+ justification: str,
60
+ review_date: Optional[datetime] = None,
61
+ ) -> ComplianceRiskAcceptance:
62
+ """
63
+ Accept the risk of a failing or warning check; it then reports ``RiskAccepted``.
64
+
65
+ Accepting again replaces (revokes) an earlier open acceptance of the same check.
66
+
67
+ Args:
68
+ framework: gdpr, nis2, dora or eidas2
69
+ check_id: Stable check ID (``ComplianceCheck.id``), e.g. ``"operational-monitoring"``
70
+ justification: 10-2000 characters after trimming
71
+ review_date: Optional future date at which the acceptance expires. Use a
72
+ timezone-aware datetime (a naive one is sent without offset).
73
+
74
+ Raises:
75
+ ValidationError: Invalid justification, review date in the past or unknown framework (400)
76
+ NotFoundError: Unknown check (404)
77
+ ConflictError: The check is not failing or warning (409)
78
+ """
79
+ request = AcceptRiskRequest(justification=justification, reviewDate=review_date)
80
+ response = await self._client.post(
81
+ f"/api/v1/compliance/{_segment(framework)}/checks/{_segment(check_id)}/risk-acceptance",
82
+ json_data=request.model_dump(mode="json", by_alias=True, exclude_none=True),
83
+ )
84
+ return ComplianceRiskAcceptance(**response)
85
+
86
+ async def revoke_risk_acceptance(
87
+ self, framework: str, check_id: str
88
+ ) -> ComplianceRiskAcceptance:
89
+ """
90
+ Revoke the open risk acceptance of a check and return it (``revoked_by``/``revoked_at`` set).
91
+
92
+ Raises:
93
+ NotFoundError: The check has no open acceptance (404)
94
+ """
95
+ response = await self._client.delete(
96
+ f"/api/v1/compliance/{_segment(framework)}/checks/{_segment(check_id)}/risk-acceptance"
97
+ )
98
+ return ComplianceRiskAcceptance(**response)
99
+
100
+ async def list_risk_acceptances(self) -> ComplianceRiskAcceptanceListResponse:
101
+ """List every risk acceptance, newest first, including revoked and expired ones."""
102
+ response = await self._client.get("/api/v1/compliance/risk-acceptances")
103
+ return ComplianceRiskAcceptanceListResponse(**response)