fvs-client 0.1.0__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.
@@ -0,0 +1,1069 @@
1
+ """The asynchronous ``AsyncClient``."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import os
6
+ import warnings
7
+ from collections.abc import Awaitable, Callable, Iterable, Mapping, Sequence
8
+ from types import TracebackType
9
+ from typing import BinaryIO, Literal, Protocol, Self, TypeVar, overload
10
+
11
+ import anyio
12
+ import httpx
13
+
14
+ from fvs_client._async.transport import AsyncTransport
15
+ from fvs_client._config import DEFAULT_TIMEOUT, check_extra_headers, check_timeout, resolve_settings
16
+ from fvs_client._inputs import (
17
+ Resource,
18
+ prepare_archive,
19
+ prepare_batch,
20
+ resolve_validation_options,
21
+ )
22
+ from fvs_client._parsing import (
23
+ finalize,
24
+ parse_context_access,
25
+ parse_dependencies,
26
+ parse_exclude,
27
+ parse_files,
28
+ parse_health,
29
+ parse_ig_package,
30
+ parse_include,
31
+ parse_liveness,
32
+ parse_package_access,
33
+ parse_readiness,
34
+ validation_parser,
35
+ )
36
+ from fvs_client._requests import (
37
+ RequestSpec,
38
+ build_context_update,
39
+ build_dependencies,
40
+ build_exclude,
41
+ build_files,
42
+ build_health,
43
+ build_include,
44
+ build_liveness,
45
+ build_package_update,
46
+ build_readiness,
47
+ build_register,
48
+ build_upload,
49
+ build_validate,
50
+ )
51
+ from fvs_client.errors import FVSError
52
+ from fvs_client.models import (
53
+ AccessChange,
54
+ ContextAccessResult,
55
+ ExcludeResult,
56
+ FhirVersion,
57
+ HealthReport,
58
+ IgInput,
59
+ IgPackageResult,
60
+ IncludeResult,
61
+ LivenessReport,
62
+ OperationOutcomeResult,
63
+ PackageAccessResult,
64
+ PackageDependencies,
65
+ PackageFiles,
66
+ RawResponse,
67
+ ReadinessReport,
68
+ ResultFormat,
69
+ RetryConfig,
70
+ TerminologyMode,
71
+ TerminologySettings,
72
+ ValidationOptions,
73
+ ValidationResult,
74
+ )
75
+
76
+ T = TypeVar("T")
77
+
78
+ _T = TypeVar("_T")
79
+
80
+
81
+ class _Request(Protocol):
82
+ """The client's request entry point, handed to its sub-clients."""
83
+
84
+ def __call__(
85
+ self,
86
+ spec: RequestSpec,
87
+ parser: Callable[[RawResponse], _T],
88
+ *,
89
+ raw: bool = False,
90
+ timeout: float | httpx.Timeout | None = None,
91
+ extra_headers: Mapping[str, str] | None = None,
92
+ retries: int | None = None,
93
+ ) -> Awaitable[_T | RawResponse]: ...
94
+
95
+
96
+ class AsyncClient:
97
+ """Asynchronous client for the FHIR Validation Service (same API as ``Client``).
98
+
99
+ Args:
100
+ base_url: Service base URL, e.g. ``https://fvs.example.org``. Defaults to the
101
+ ``FVS_BASE_URL`` environment variable.
102
+ api_key: API key sent as ``Authorization: Bearer``. Defaults to ``FVS_API_KEY``; may be
103
+ omitted for health checks or a deployment with access control disabled.
104
+ timeout: Seconds, or an ``httpx.Timeout`` bounding every phase. Default 60 s (10 s to
105
+ connect). ``None`` is not allowed.
106
+ retries: A ``RetryConfig``, or an ``int`` setting ``max_retries`` for safe operations.
107
+ headers: Extra headers for every request (``Authorization`` is not allowed here).
108
+ user_agent_suffix: Appended to the ``User-Agent`` header.
109
+ http_client: Your own ``httpx.AsyncClient`` (proxies, custom TLS, mocking). It is used
110
+ as-is and never closed by this client.
111
+
112
+ Use it as an async context manager, or call :meth:`aclose`::
113
+
114
+ async with AsyncClient("https://fvs.example.org", api_key="…") as fvs:
115
+ result = await fvs.validate({"resourceType": "Patient"}, fhir_version="R4")
116
+
117
+ Errors & retries:
118
+ Every error derives from ``FVSError``. Local argument checks raise ``InputError``
119
+ before anything is sent; an unreachable or slow service raises ``FVSConnectionError``
120
+ / ``FVSTimeoutError``; an error status raises an ``APIError`` subclass carrying the
121
+ RFC 9457 problem (``problem_type``, ``request_id``, ``response``).
122
+
123
+ 429 and 503 responses are retried, waiting ``Retry-After`` when the service gives it
124
+ (longer than ``RetryConfig.max_retry_after`` → raised at once) and a full-jitter
125
+ backoff otherwise. Connection failures are retried for safe operations only;
126
+ timeouts are never retried. Safe operations (validation, health, package reads) retry
127
+ up to ``RetryConfig.max_retries`` (default 2); administrative operations don't retry
128
+ unless ``admin_max_retries`` or a per-call ``retries=`` says so.
129
+
130
+ Raises:
131
+ InputError: an argument is invalid (for example no base URL anywhere).
132
+ """
133
+
134
+ def __init__(
135
+ self,
136
+ base_url: str | None = None,
137
+ *,
138
+ api_key: str | None = None,
139
+ timeout: float | httpx.Timeout = DEFAULT_TIMEOUT,
140
+ retries: RetryConfig | int | None = None,
141
+ headers: Mapping[str, str] | None = None,
142
+ user_agent_suffix: str | None = None,
143
+ http_client: httpx.AsyncClient | None = None,
144
+ ) -> None:
145
+ self._settings = resolve_settings(
146
+ base_url=base_url,
147
+ api_key=api_key,
148
+ timeout=timeout,
149
+ headers=headers,
150
+ user_agent_suffix=user_agent_suffix,
151
+ retries=retries,
152
+ )
153
+ self._owns_http = http_client is None
154
+ self._http = (
155
+ http_client
156
+ if http_client is not None
157
+ else httpx.AsyncClient(timeout=self._settings.timeout, follow_redirects=False)
158
+ )
159
+ self._transport = AsyncTransport(self._http, self._settings)
160
+ self._contexts = AsyncContexts(self._request)
161
+ self._packages = AsyncPackages(self._request)
162
+ self._health = AsyncHealth(self._request)
163
+
164
+ @property
165
+ def base_url(self) -> str:
166
+ """The service base URL."""
167
+ return self._settings.base_url
168
+
169
+ @property
170
+ def contexts(self) -> AsyncContexts:
171
+ """Validator-context administration (``include``, ``exclude``, ``update``)."""
172
+ return self._contexts
173
+
174
+ @property
175
+ def health(self) -> AsyncHealth:
176
+ """Health, liveness and readiness checks (no API key needed)."""
177
+ return self._health
178
+
179
+ @property
180
+ def packages(self) -> AsyncPackages:
181
+ """IG package operations (``upload``, ``register``, ``update``, ``dependencies``)."""
182
+ return self._packages
183
+
184
+ async def aclose(self) -> None:
185
+ """Release network connections (a caller-supplied ``http_client`` is left open)."""
186
+ if self._owns_http:
187
+ await self._http.aclose()
188
+
189
+ async def __aenter__(self) -> Self:
190
+ return self
191
+
192
+ async def __aexit__(
193
+ self,
194
+ exc_type: type[BaseException] | None,
195
+ exc: BaseException | None,
196
+ tb: TracebackType | None,
197
+ ) -> None:
198
+ await self.aclose()
199
+
200
+ def __repr__(self) -> str:
201
+ key = "'**********'" if self._settings.api_key is not None else "None"
202
+ return f"{type(self).__name__}(base_url={self._settings.base_url!r}, api_key={key})"
203
+
204
+ async def _request(
205
+ self,
206
+ spec: RequestSpec,
207
+ parser: Callable[[RawResponse], T],
208
+ *,
209
+ raw: bool = False,
210
+ timeout: float | httpx.Timeout | None = None,
211
+ extra_headers: Mapping[str, str] | None = None,
212
+ retries: int | None = None,
213
+ ) -> T | RawResponse:
214
+ effective_timeout = self._settings.timeout if timeout is None else check_timeout(timeout)
215
+ headers = check_extra_headers(extra_headers)
216
+ response = await self._transport.send(
217
+ spec, timeout=effective_timeout, extra_headers=headers, retries=retries
218
+ )
219
+ return finalize(response, parser, want_raw=raw, report_on_503=spec.report_on_503)
220
+
221
+ # ----------------------------------------------------------------------- validation
222
+
223
+ @overload
224
+ async def validate(
225
+ self,
226
+ resource: Resource,
227
+ *,
228
+ fhir_version: FhirVersion | str,
229
+ ig: IgInput | None = None,
230
+ profiles: Sequence[str] = (),
231
+ tx: str | None = None,
232
+ tx_mode: TerminologyMode | str | None = None,
233
+ result_format: ResultFormat | str = ResultFormat.SUMMARY,
234
+ content_type: str | None = None,
235
+ options: ValidationOptions | None = None,
236
+ raw: Literal[True],
237
+ timeout: float | httpx.Timeout | None = None,
238
+ extra_headers: Mapping[str, str] | None = None,
239
+ ) -> RawResponse: ...
240
+
241
+ @overload
242
+ async def validate(
243
+ self,
244
+ resource: Resource,
245
+ *,
246
+ fhir_version: FhirVersion | str,
247
+ ig: IgInput | None = None,
248
+ profiles: Sequence[str] = (),
249
+ tx: str | None = None,
250
+ tx_mode: TerminologyMode | str | None = None,
251
+ result_format: Literal[ResultFormat.SUMMARY] = ResultFormat.SUMMARY,
252
+ content_type: str | None = None,
253
+ options: None = None,
254
+ raw: Literal[False] = False,
255
+ timeout: float | httpx.Timeout | None = None,
256
+ extra_headers: Mapping[str, str] | None = None,
257
+ ) -> ValidationResult: ...
258
+
259
+ @overload
260
+ async def validate(
261
+ self,
262
+ resource: Resource,
263
+ *,
264
+ fhir_version: FhirVersion | str,
265
+ ig: IgInput | None = None,
266
+ profiles: Sequence[str] = (),
267
+ tx: str | None = None,
268
+ tx_mode: TerminologyMode | str | None = None,
269
+ result_format: Literal[
270
+ ResultFormat.OPERATION_OUTCOME_JSON, ResultFormat.OPERATION_OUTCOME_XML
271
+ ],
272
+ content_type: str | None = None,
273
+ options: None = None,
274
+ raw: Literal[False] = False,
275
+ timeout: float | httpx.Timeout | None = None,
276
+ extra_headers: Mapping[str, str] | None = None,
277
+ ) -> OperationOutcomeResult: ...
278
+
279
+ @overload
280
+ async def validate(
281
+ self,
282
+ resource: Resource,
283
+ *,
284
+ fhir_version: FhirVersion | str,
285
+ ig: IgInput | None = None,
286
+ profiles: Sequence[str] = (),
287
+ tx: str | None = None,
288
+ tx_mode: TerminologyMode | str | None = None,
289
+ result_format: ResultFormat | str = ResultFormat.SUMMARY,
290
+ content_type: str | None = None,
291
+ options: ValidationOptions | None = None,
292
+ raw: bool = False,
293
+ timeout: float | httpx.Timeout | None = None,
294
+ extra_headers: Mapping[str, str] | None = None,
295
+ ) -> ValidationResult | OperationOutcomeResult | RawResponse: ...
296
+
297
+ async def validate(
298
+ self,
299
+ resource: Resource,
300
+ *,
301
+ fhir_version: FhirVersion | str,
302
+ ig: IgInput | None = None,
303
+ profiles: Sequence[str] = (),
304
+ tx: str | None = None,
305
+ tx_mode: TerminologyMode | str | None = None,
306
+ result_format: ResultFormat | str = ResultFormat.SUMMARY,
307
+ content_type: str | None = None,
308
+ options: ValidationOptions | None = None,
309
+ raw: bool = False,
310
+ timeout: float | httpx.Timeout | None = None,
311
+ extra_headers: Mapping[str, str] | None = None,
312
+ ) -> ValidationResult | OperationOutcomeResult | RawResponse:
313
+ """Validate one FHIR resource.
314
+
315
+ A completed validation is always a result, whether the resource is valid or not:
316
+ check ``result.valid`` / ``result.errors``. Errors are raised only when the service
317
+ refuses the request (see :mod:`fvs_client.errors`).
318
+
319
+ Args:
320
+ resource: A dict, a JSON or XML ``str``/``bytes``, or a path to a ``.json``/``.xml``
321
+ file (streamed from disk).
322
+ fhir_version: ``STU3``, ``R4``, ``R4B`` or ``R5`` (any case).
323
+ ig: IG package to validate against: ``"name"``, ``"name#version"``,
324
+ ``"name#latest"``, an ``IgRef``, or two exact IGs (``"a#1.0.0|b#2.0.0"`` or a
325
+ tuple of two ``IgRef``). Default: the core specification only.
326
+ profiles: Extra profile URLs (at most 10 distinct).
327
+ tx: Terminology server for this request only.
328
+ tx_mode: ``none``, ``server`` or ``ecosystem`` for this request only.
329
+ result_format: ``SUMMARY`` (default) → ``ValidationResult``;
330
+ ``OPERATION_OUTCOME_JSON``/``_XML`` → ``OperationOutcomeResult``.
331
+ content_type: Override the detected ``Content-Type`` of ``resource``.
332
+ options: A ``ValidationOptions`` instead of the keyword options above.
333
+ raw: Return the unparsed ``RawResponse`` (error statuses still raise).
334
+ timeout: Per-call timeout; ``None`` uses the client's.
335
+ extra_headers: Extra headers for this call (``Authorization`` is not allowed).
336
+
337
+ Returns:
338
+ ``ValidationResult``, ``OperationOutcomeResult`` or ``RawResponse``.
339
+
340
+ Raises:
341
+ InputError: a local check failed; nothing was sent.
342
+ APIError: the service refused the request (subclass per status/problem type).
343
+ TransportError: the service could not be reached or did not answer in time.
344
+
345
+ Example:
346
+ >>> patient = {"resourceType": "Patient"}
347
+ >>> result = await client.validate(patient, fhir_version="R4") # doctest: +SKIP
348
+ >>> result.valid, [i.message for i in result.errors] # doctest: +SKIP
349
+ """
350
+ opts = resolve_validation_options(
351
+ options,
352
+ ig=ig,
353
+ profiles=profiles,
354
+ tx=tx,
355
+ tx_mode=tx_mode,
356
+ result_format=result_format,
357
+ content_type=content_type,
358
+ )
359
+ spec = build_validate(fhir_version, resource, opts)
360
+ parser = validation_parser(ResultFormat.parse(opts.result_format))
361
+ return await self._request(
362
+ spec, parser, raw=raw, timeout=timeout, extra_headers=extra_headers
363
+ )
364
+
365
+ async def validate_many(
366
+ self,
367
+ resources: Iterable[Resource],
368
+ *,
369
+ fhir_version: FhirVersion | str,
370
+ concurrency: int = 8,
371
+ ig: IgInput | None = None,
372
+ profiles: Sequence[str] = (),
373
+ tx: str | None = None,
374
+ tx_mode: TerminologyMode | str | None = None,
375
+ result_format: ResultFormat | str = ResultFormat.SUMMARY,
376
+ content_type: str | None = None,
377
+ options: ValidationOptions | None = None,
378
+ raw: bool = False,
379
+ timeout: float | httpx.Timeout | None = None,
380
+ extra_headers: Mapping[str, str] | None = None,
381
+ ) -> list[ValidationResult | OperationOutcomeResult | RawResponse | FVSError]:
382
+ """Validate many resources concurrently; one outcome per input, in input order.
383
+
384
+ Each slot holds the result (as ``validate`` would return it) or the ``FVSError`` that
385
+ resource raised (including a per-resource ``InputError``), so one failure never stops
386
+ the others. Unexpected non-SDK exceptions propagate. Options shared by every resource
387
+ are checked first and raise ``InputError`` before anything is sent.
388
+
389
+ Args:
390
+ resources: The resources (anything ``validate`` accepts).
391
+ fhir_version: ``STU3``, ``R4``, ``R4B`` or ``R5``.
392
+ concurrency: Maximum requests in flight (default 8).
393
+ ig: See ``validate``.
394
+ profiles: See ``validate``.
395
+ tx: See ``validate``.
396
+ tx_mode: See ``validate``.
397
+ result_format: See ``validate``.
398
+ content_type: See ``validate``.
399
+ options: See ``validate``.
400
+ raw: See ``validate``.
401
+ timeout: See ``validate``.
402
+ extra_headers: See ``validate``.
403
+
404
+ Returns:
405
+ One ``ValidationResult`` / ``OperationOutcomeResult`` / ``RawResponse`` or
406
+ ``FVSError`` per input, in input order.
407
+
408
+ Raises:
409
+ InputError: ``concurrency`` < 1 or invalid shared options; nothing was sent.
410
+ """
411
+ batch = prepare_batch(
412
+ concurrency,
413
+ fhir_version,
414
+ options,
415
+ ig=ig,
416
+ profiles=profiles,
417
+ tx=tx,
418
+ tx_mode=tx_mode,
419
+ result_format=result_format,
420
+ content_type=content_type,
421
+ timeout=timeout,
422
+ extra_headers=extra_headers,
423
+ )
424
+ items = list(resources)
425
+
426
+ results: list[ValidationResult | OperationOutcomeResult | RawResponse | FVSError | None]
427
+ results = [None] * len(items)
428
+ limiter = anyio.CapacityLimiter(concurrency)
429
+
430
+ async def one(index: int, resource: Resource) -> None:
431
+ async with limiter:
432
+ try:
433
+ results[index] = await self.validate(
434
+ resource,
435
+ fhir_version=batch.fhir_version,
436
+ options=batch.options,
437
+ raw=raw,
438
+ timeout=timeout,
439
+ extra_headers=extra_headers,
440
+ )
441
+ except FVSError as exc:
442
+ results[index] = exc
443
+
444
+ async with anyio.create_task_group() as tg:
445
+ for index, resource in enumerate(items):
446
+ tg.start_soon(one, index, resource)
447
+ return [r for r in results if r is not None]
448
+
449
+
450
+ class AsyncContexts:
451
+ """Validator-context administration: ``client.contexts`` (ADMIN key)."""
452
+
453
+ def __init__(self, request: _Request) -> None:
454
+ self._send = request
455
+
456
+ @overload
457
+ async def include(
458
+ self,
459
+ fhir_version: FhirVersion | str,
460
+ ig: IgInput,
461
+ *,
462
+ shareable: bool | None = None,
463
+ terminology: TerminologySettings | None = None,
464
+ raw: Literal[False] = False,
465
+ timeout: float | httpx.Timeout | None = None,
466
+ extra_headers: Mapping[str, str] | None = None,
467
+ retries: int | None = None,
468
+ ) -> IncludeResult: ...
469
+ @overload
470
+ async def include(
471
+ self,
472
+ fhir_version: FhirVersion | str,
473
+ ig: IgInput,
474
+ *,
475
+ shareable: bool | None = None,
476
+ terminology: TerminologySettings | None = None,
477
+ raw: Literal[True],
478
+ timeout: float | httpx.Timeout | None = None,
479
+ extra_headers: Mapping[str, str] | None = None,
480
+ retries: int | None = None,
481
+ ) -> RawResponse: ...
482
+ async def include(
483
+ self,
484
+ fhir_version: FhirVersion | str,
485
+ ig: IgInput,
486
+ *,
487
+ shareable: bool | None = None,
488
+ terminology: TerminologySettings | None = None,
489
+ raw: bool = False,
490
+ timeout: float | httpx.Timeout | None = None,
491
+ extra_headers: Mapping[str, str] | None = None,
492
+ retries: int | None = None,
493
+ ) -> IncludeResult | RawResponse:
494
+ """Include (pre-build) a validator context for one or two stored IG versions.
495
+
496
+ Args:
497
+ fhir_version: FHIR version of the context.
498
+ ig: One IG (``"name"``, ``"name#1.2.0"``, ``"name#latest"``, ``"name#1.2.x"``, an
499
+ ``IgRef``) or two (``"a#1|b#2"`` or a tuple of two ``IgRef``) for a two-IG
500
+ context. Nothing is downloaded; the versions must be stored.
501
+ shareable: Sharing of a newly included context (default: shareable).
502
+ terminology: Terminology setting of the new context.
503
+ raw: Return the unparsed ``RawResponse``.
504
+ timeout: Per-call timeout; ``None`` uses the client's.
505
+ extra_headers: Extra headers for this call.
506
+ retries: Retries for this call (429/503 only); default ``admin_max_retries``.
507
+
508
+ Returns:
509
+ ``IncludeResult`` (or ``RawResponse``).
510
+
511
+ Raises:
512
+ InputError: invalid IG reference; nothing was sent.
513
+ APIError: e.g. ``NotFoundError`` (not stored), ``ConflictError`` (alias conflict),
514
+ ``PermissionDeniedError`` (not an ADMIN key).
515
+ """
516
+ spec = build_include(fhir_version, ig, shareable=shareable, terminology=terminology)
517
+ return await self._send(
518
+ spec,
519
+ parse_include,
520
+ raw=raw,
521
+ timeout=timeout,
522
+ extra_headers=extra_headers,
523
+ retries=retries,
524
+ )
525
+
526
+ @overload
527
+ async def exclude(
528
+ self,
529
+ fhir_version: FhirVersion | str,
530
+ ig: IgInput,
531
+ *,
532
+ raw: Literal[False] = False,
533
+ timeout: float | httpx.Timeout | None = None,
534
+ extra_headers: Mapping[str, str] | None = None,
535
+ retries: int | None = None,
536
+ ) -> ExcludeResult: ...
537
+ @overload
538
+ async def exclude(
539
+ self,
540
+ fhir_version: FhirVersion | str,
541
+ ig: IgInput,
542
+ *,
543
+ raw: Literal[True],
544
+ timeout: float | httpx.Timeout | None = None,
545
+ extra_headers: Mapping[str, str] | None = None,
546
+ retries: int | None = None,
547
+ ) -> RawResponse: ...
548
+ async def exclude(
549
+ self,
550
+ fhir_version: FhirVersion | str,
551
+ ig: IgInput,
552
+ *,
553
+ raw: bool = False,
554
+ timeout: float | httpx.Timeout | None = None,
555
+ extra_headers: Mapping[str, str] | None = None,
556
+ retries: int | None = None,
557
+ ) -> ExcludeResult | RawResponse:
558
+ """Exclude (stop pre-building) an included validator context; the package stays stored.
559
+
560
+ Args:
561
+ fhir_version: FHIR version of the context.
562
+ ig: Exact ``name#version``, or a two-IG key ``A#a|B#b``; no ``latest``/series.
563
+ raw: Return the unparsed ``RawResponse``.
564
+ timeout: Per-call timeout; ``None`` uses the client's.
565
+ extra_headers: Extra headers for this call.
566
+ retries: Retries for this call (429/503 only); default ``admin_max_retries``.
567
+
568
+ Returns:
569
+ ``ExcludeResult`` (or ``RawResponse``).
570
+ """
571
+ spec = build_exclude(fhir_version, ig)
572
+ return await self._send(
573
+ spec,
574
+ parse_exclude,
575
+ raw=raw,
576
+ timeout=timeout,
577
+ extra_headers=extra_headers,
578
+ retries=retries,
579
+ )
580
+
581
+ @overload
582
+ async def update(
583
+ self,
584
+ fhir_version: FhirVersion | str,
585
+ ig: IgInput,
586
+ change: AccessChange,
587
+ *,
588
+ raw: Literal[False] = False,
589
+ timeout: float | httpx.Timeout | None = None,
590
+ extra_headers: Mapping[str, str] | None = None,
591
+ retries: int | None = None,
592
+ ) -> ContextAccessResult: ...
593
+ @overload
594
+ async def update(
595
+ self,
596
+ fhir_version: FhirVersion | str,
597
+ ig: IgInput,
598
+ change: AccessChange,
599
+ *,
600
+ raw: Literal[True],
601
+ timeout: float | httpx.Timeout | None = None,
602
+ extra_headers: Mapping[str, str] | None = None,
603
+ retries: int | None = None,
604
+ ) -> RawResponse: ...
605
+ async def update(
606
+ self,
607
+ fhir_version: FhirVersion | str,
608
+ ig: IgInput,
609
+ change: AccessChange,
610
+ *,
611
+ raw: bool = False,
612
+ timeout: float | httpx.Timeout | None = None,
613
+ extra_headers: Mapping[str, str] | None = None,
614
+ retries: int | None = None,
615
+ ) -> ContextAccessResult | RawResponse:
616
+ """Change sharing, ownership or terminology of an included validator context.
617
+
618
+ Args:
619
+ fhir_version: FHIR version of the context.
620
+ ig: Exact ``name#version``, or a two-IG key ``A#a|B#b``.
621
+ change: What to change (``AccessChange``).
622
+ raw: Return the unparsed ``RawResponse``.
623
+ timeout: Per-call timeout; ``None`` uses the client's.
624
+ extra_headers: Extra headers for this call.
625
+ retries: Retries for this call (429/503 only); default ``admin_max_retries``.
626
+
627
+ Returns:
628
+ ``ContextAccessResult`` (or ``RawResponse``).
629
+ """
630
+ spec = build_context_update(fhir_version, ig, change)
631
+ return await self._send(
632
+ spec,
633
+ parse_context_access,
634
+ raw=raw,
635
+ timeout=timeout,
636
+ extra_headers=extra_headers,
637
+ retries=retries,
638
+ )
639
+
640
+
641
+ class AsyncPackages:
642
+ """IG package operations: ``client.packages``."""
643
+
644
+ def __init__(self, request: _Request) -> None:
645
+ self._send = request
646
+
647
+ @overload
648
+ async def upload(
649
+ self,
650
+ archive: os.PathLike[str] | BinaryIO,
651
+ *,
652
+ shareable: bool = True,
653
+ raw: Literal[False] = False,
654
+ timeout: float | httpx.Timeout | None = None,
655
+ extra_headers: Mapping[str, str] | None = None,
656
+ retries: int | None = None,
657
+ ) -> IgPackageResult: ...
658
+ @overload
659
+ async def upload(
660
+ self,
661
+ archive: os.PathLike[str] | BinaryIO,
662
+ *,
663
+ shareable: bool = True,
664
+ raw: Literal[True],
665
+ timeout: float | httpx.Timeout | None = None,
666
+ extra_headers: Mapping[str, str] | None = None,
667
+ retries: int | None = None,
668
+ ) -> RawResponse: ...
669
+ async def upload(
670
+ self,
671
+ archive: os.PathLike[str] | BinaryIO,
672
+ *,
673
+ shareable: bool = True,
674
+ raw: bool = False,
675
+ timeout: float | httpx.Timeout | None = None,
676
+ extra_headers: Mapping[str, str] | None = None,
677
+ retries: int | None = None,
678
+ ) -> IgPackageResult | RawResponse:
679
+ """Upload and store an IG package archive (``.tgz``), streamed from disk (ADMIN key).
680
+
681
+ Args:
682
+ archive: Path to the archive, or a file opened in binary mode.
683
+ shareable: Sharing of the stored package (ignored if already stored).
684
+ raw: Return the unparsed ``RawResponse``.
685
+ timeout: Per-call timeout; ``None`` uses the client's.
686
+ extra_headers: Extra headers for this call.
687
+ retries: Retries for this call (429/503 only); default ``admin_max_retries``.
688
+
689
+ Returns:
690
+ ``IgPackageResult`` (or ``RawResponse``).
691
+ """
692
+ filename, handle, should_close = prepare_archive(archive)
693
+ try:
694
+ spec = build_upload(filename, handle, shareable=shareable)
695
+ return await self._send(
696
+ spec,
697
+ parse_ig_package,
698
+ raw=raw,
699
+ timeout=timeout,
700
+ extra_headers=extra_headers,
701
+ retries=retries,
702
+ )
703
+ finally:
704
+ if should_close:
705
+ handle.close()
706
+
707
+ @overload
708
+ async def register(
709
+ self,
710
+ name: str | None = None,
711
+ version: str = "latest",
712
+ *,
713
+ download_url: str | None = None,
714
+ include_dependencies: bool = True,
715
+ shareable: bool = True,
716
+ raw: Literal[False] = False,
717
+ timeout: float | httpx.Timeout | None = None,
718
+ extra_headers: Mapping[str, str] | None = None,
719
+ retries: int | None = None,
720
+ ) -> IgPackageResult: ...
721
+ @overload
722
+ async def register(
723
+ self,
724
+ name: str | None = None,
725
+ version: str = "latest",
726
+ *,
727
+ download_url: str | None = None,
728
+ include_dependencies: bool = True,
729
+ shareable: bool = True,
730
+ raw: Literal[True],
731
+ timeout: float | httpx.Timeout | None = None,
732
+ extra_headers: Mapping[str, str] | None = None,
733
+ retries: int | None = None,
734
+ ) -> RawResponse: ...
735
+ async def register(
736
+ self,
737
+ name: str | None = None,
738
+ version: str = "latest",
739
+ *,
740
+ download_url: str | None = None,
741
+ include_dependencies: bool = True,
742
+ shareable: bool = True,
743
+ raw: bool = False,
744
+ timeout: float | httpx.Timeout | None = None,
745
+ extra_headers: Mapping[str, str] | None = None,
746
+ retries: int | None = None,
747
+ ) -> IgPackageResult | RawResponse:
748
+ """Fetch and store an IG package from the package registry or an approved URL (ADMIN key).
749
+
750
+ Args:
751
+ name: Package id (exactly one of ``name`` and ``download_url``).
752
+ version: Exact version, ``latest`` (default) or a series (``1.2.x``).
753
+ download_url: Archive URL on a host the operator allows.
754
+ include_dependencies: Also fetch the package's dependencies.
755
+ shareable: Sharing of every package newly stored by this call.
756
+ raw: Return the unparsed ``RawResponse``.
757
+ timeout: Per-call timeout; ``None`` uses the client's.
758
+ extra_headers: Extra headers for this call.
759
+ retries: Retries for this call (429/503 only); default ``admin_max_retries``.
760
+
761
+ Returns:
762
+ ``IgPackageResult`` (or ``RawResponse``): ``version`` is the concrete version.
763
+ """
764
+ spec = build_register(
765
+ name,
766
+ version,
767
+ download_url,
768
+ include_dependencies=include_dependencies,
769
+ shareable=shareable,
770
+ )
771
+ return await self._send(
772
+ spec,
773
+ parse_ig_package,
774
+ raw=raw,
775
+ timeout=timeout,
776
+ extra_headers=extra_headers,
777
+ retries=retries,
778
+ )
779
+
780
+ @overload
781
+ async def update(
782
+ self,
783
+ name: str,
784
+ version: str,
785
+ change: AccessChange,
786
+ *,
787
+ raw: Literal[False] = False,
788
+ timeout: float | httpx.Timeout | None = None,
789
+ extra_headers: Mapping[str, str] | None = None,
790
+ retries: int | None = None,
791
+ ) -> PackageAccessResult: ...
792
+ @overload
793
+ async def update(
794
+ self,
795
+ name: str,
796
+ version: str,
797
+ change: AccessChange,
798
+ *,
799
+ raw: Literal[True],
800
+ timeout: float | httpx.Timeout | None = None,
801
+ extra_headers: Mapping[str, str] | None = None,
802
+ retries: int | None = None,
803
+ ) -> RawResponse: ...
804
+ async def update(
805
+ self,
806
+ name: str,
807
+ version: str,
808
+ change: AccessChange,
809
+ *,
810
+ raw: bool = False,
811
+ timeout: float | httpx.Timeout | None = None,
812
+ extra_headers: Mapping[str, str] | None = None,
813
+ retries: int | None = None,
814
+ ) -> PackageAccessResult | RawResponse:
815
+ """Change sharing or transfer ownership of a stored IG package (ADMIN key).
816
+
817
+ Args:
818
+ name: Package id.
819
+ version: Package version.
820
+ change: ``AccessChange`` with ``shareable`` and/or ``owner`` (no ``terminology``).
821
+ raw: Return the unparsed ``RawResponse``.
822
+ timeout: Per-call timeout; ``None`` uses the client's.
823
+ extra_headers: Extra headers for this call.
824
+ retries: Retries for this call (429/503 only); default ``admin_max_retries``.
825
+
826
+ Returns:
827
+ ``PackageAccessResult`` (or ``RawResponse``).
828
+ """
829
+ spec = build_package_update(name, version, change)
830
+ return await self._send(
831
+ spec,
832
+ parse_package_access,
833
+ raw=raw,
834
+ timeout=timeout,
835
+ extra_headers=extra_headers,
836
+ retries=retries,
837
+ )
838
+
839
+ @overload
840
+ async def dependencies(
841
+ self,
842
+ name: str,
843
+ version: str,
844
+ *,
845
+ raw: Literal[False] = False,
846
+ timeout: float | httpx.Timeout | None = None,
847
+ extra_headers: Mapping[str, str] | None = None,
848
+ ) -> PackageDependencies: ...
849
+ @overload
850
+ async def dependencies(
851
+ self,
852
+ name: str,
853
+ version: str,
854
+ *,
855
+ raw: Literal[True],
856
+ timeout: float | httpx.Timeout | None = None,
857
+ extra_headers: Mapping[str, str] | None = None,
858
+ ) -> RawResponse: ...
859
+ async def dependencies(
860
+ self,
861
+ name: str,
862
+ version: str,
863
+ *,
864
+ raw: bool = False,
865
+ timeout: float | httpx.Timeout | None = None,
866
+ extra_headers: Mapping[str, str] | None = None,
867
+ ) -> PackageDependencies | RawResponse:
868
+ """Declared dependencies of a stored IG package.
869
+
870
+ Args:
871
+ name: Package id.
872
+ version: Package version.
873
+ raw: Return the unparsed ``RawResponse``.
874
+ timeout: Per-call timeout; ``None`` uses the client's.
875
+ extra_headers: Extra headers for this call.
876
+
877
+ Returns:
878
+ ``PackageDependencies`` (or ``RawResponse``).
879
+ """
880
+ spec = build_dependencies(name, version)
881
+ return await self._send(
882
+ spec, parse_dependencies, raw=raw, timeout=timeout, extra_headers=extra_headers
883
+ )
884
+
885
+ @overload
886
+ async def files(
887
+ self,
888
+ name: str,
889
+ version: str,
890
+ *,
891
+ raw: Literal[False] = False,
892
+ timeout: float | httpx.Timeout | None = None,
893
+ extra_headers: Mapping[str, str] | None = None,
894
+ ) -> PackageFiles: ...
895
+ @overload
896
+ async def files(
897
+ self,
898
+ name: str,
899
+ version: str,
900
+ *,
901
+ raw: Literal[True],
902
+ timeout: float | httpx.Timeout | None = None,
903
+ extra_headers: Mapping[str, str] | None = None,
904
+ ) -> RawResponse: ...
905
+ async def files(
906
+ self,
907
+ name: str,
908
+ version: str,
909
+ *,
910
+ raw: bool = False,
911
+ timeout: float | httpx.Timeout | None = None,
912
+ extra_headers: Mapping[str, str] | None = None,
913
+ ) -> PackageFiles | RawResponse:
914
+ """File listing of a stored IG package.
915
+
916
+ .. deprecated:: 0.1.0
917
+ The service deprecated this operation (it is not a conformance report).
918
+
919
+ Args:
920
+ name: Package id.
921
+ version: Package version.
922
+ raw: Return the unparsed ``RawResponse``.
923
+ timeout: Per-call timeout; ``None`` uses the client's.
924
+ extra_headers: Extra headers for this call.
925
+
926
+ Returns:
927
+ ``PackageFiles`` (or ``RawResponse``).
928
+ """
929
+ warnings.warn(
930
+ "packages.files() is deprecated by the FHIR Validation Service",
931
+ DeprecationWarning,
932
+ stacklevel=2,
933
+ )
934
+ spec = build_files(name, version)
935
+ return await self._send(
936
+ spec, parse_files, raw=raw, timeout=timeout, extra_headers=extra_headers
937
+ )
938
+
939
+
940
+ class AsyncHealth:
941
+ """Health checks: ``client.health`` (no API key needed)."""
942
+
943
+ def __init__(self, request: _Request) -> None:
944
+ self._send = request
945
+
946
+ @overload
947
+ async def check(
948
+ self,
949
+ *,
950
+ raw: Literal[False] = False,
951
+ timeout: float | httpx.Timeout | None = None,
952
+ extra_headers: Mapping[str, str] | None = None,
953
+ ) -> HealthReport: ...
954
+ @overload
955
+ async def check(
956
+ self,
957
+ *,
958
+ raw: Literal[True],
959
+ timeout: float | httpx.Timeout | None = None,
960
+ extra_headers: Mapping[str, str] | None = None,
961
+ ) -> RawResponse: ...
962
+ async def check(
963
+ self,
964
+ *,
965
+ raw: bool = False,
966
+ timeout: float | httpx.Timeout | None = None,
967
+ extra_headers: Mapping[str, str] | None = None,
968
+ ) -> HealthReport | RawResponse:
969
+ """Detailed health report: database, readiness, FHIR versions, terminology allowlist.
970
+
971
+ A 503 with a report body is returned (``is_healthy`` is ``False``), not raised.
972
+
973
+ No API key is needed.
974
+
975
+ Args:
976
+ raw: Return the unparsed ``RawResponse``.
977
+ timeout: Per-call timeout; ``None`` uses the client's.
978
+ extra_headers: Extra headers for this call.
979
+
980
+ Returns:
981
+ ``HealthReport`` (or ``RawResponse``).
982
+ """
983
+ return await self._send(
984
+ build_health(), parse_health, raw=raw, timeout=timeout, extra_headers=extra_headers
985
+ )
986
+
987
+ @overload
988
+ async def liveness(
989
+ self,
990
+ *,
991
+ raw: Literal[False] = False,
992
+ timeout: float | httpx.Timeout | None = None,
993
+ extra_headers: Mapping[str, str] | None = None,
994
+ ) -> LivenessReport: ...
995
+ @overload
996
+ async def liveness(
997
+ self,
998
+ *,
999
+ raw: Literal[True],
1000
+ timeout: float | httpx.Timeout | None = None,
1001
+ extra_headers: Mapping[str, str] | None = None,
1002
+ ) -> RawResponse: ...
1003
+ async def liveness(
1004
+ self,
1005
+ *,
1006
+ raw: bool = False,
1007
+ timeout: float | httpx.Timeout | None = None,
1008
+ extra_headers: Mapping[str, str] | None = None,
1009
+ ) -> LivenessReport | RawResponse:
1010
+ """Liveness probe: the service process is alive.
1011
+
1012
+ No API key is needed.
1013
+
1014
+ Args:
1015
+ raw: Return the unparsed ``RawResponse``.
1016
+ timeout: Per-call timeout; ``None`` uses the client's.
1017
+ extra_headers: Extra headers for this call.
1018
+
1019
+ Returns:
1020
+ ``LivenessReport`` (or ``RawResponse``).
1021
+ """
1022
+ return await self._send(
1023
+ build_liveness(), parse_liveness, raw=raw, timeout=timeout, extra_headers=extra_headers
1024
+ )
1025
+
1026
+ @overload
1027
+ async def readiness(
1028
+ self,
1029
+ *,
1030
+ raw: Literal[False] = False,
1031
+ timeout: float | httpx.Timeout | None = None,
1032
+ extra_headers: Mapping[str, str] | None = None,
1033
+ ) -> ReadinessReport: ...
1034
+ @overload
1035
+ async def readiness(
1036
+ self,
1037
+ *,
1038
+ raw: Literal[True],
1039
+ timeout: float | httpx.Timeout | None = None,
1040
+ extra_headers: Mapping[str, str] | None = None,
1041
+ ) -> RawResponse: ...
1042
+ async def readiness(
1043
+ self,
1044
+ *,
1045
+ raw: bool = False,
1046
+ timeout: float | httpx.Timeout | None = None,
1047
+ extra_headers: Mapping[str, str] | None = None,
1048
+ ) -> ReadinessReport | RawResponse:
1049
+ """Readiness probe: can the instance serve traffic?
1050
+
1051
+ A 503 with a report body is returned (``is_ready`` is ``False``), not raised.
1052
+
1053
+ No API key is needed.
1054
+
1055
+ Args:
1056
+ raw: Return the unparsed ``RawResponse``.
1057
+ timeout: Per-call timeout; ``None`` uses the client's.
1058
+ extra_headers: Extra headers for this call.
1059
+
1060
+ Returns:
1061
+ ``ReadinessReport`` (or ``RawResponse``).
1062
+ """
1063
+ return await self._send(
1064
+ build_readiness(),
1065
+ parse_readiness,
1066
+ raw=raw,
1067
+ timeout=timeout,
1068
+ extra_headers=extra_headers,
1069
+ )