FHIR Packages Client¶
FHIR Package Registry client utilities.
client ¶
Lightweight client for FHIR Package Registry API.
Classes:
| Name | Description |
|---|---|
FHIRPackageRegistryClient |
Lightweight client for the FHIR Package Registry API. |
Functions:
| Name | Description |
|---|---|
get_package_metadata |
Convenience function to get package metadata. |
download_package |
Convenience function to download a package. |
download_latest_package |
Convenience function to download the latest version of a package. |
FHIRPackageRegistryClient
Path: fhircraft.fhir.packages.client.FHIRPackageRegistryClient
FHIRPackageRegistryClient(base_url: Optional[str] = None, timeout: float = 30.0, session: Optional[Session] = None)
Lightweight client for the FHIR Package Registry API.
Supports both packages.simplifier.net and packages.fhir.org endpoints.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_url
|
Optional[str]
|
Base URL for the API |
None
|
timeout
|
float
|
Request timeout in seconds |
30.0
|
session
|
Optional[Session]
|
Optional requests session to use |
None
|
Methods:
| Name | Description |
|---|---|
list_package_versions |
List all versions for a package. |
download_package |
Download a specific package version. |
get_latest_version |
Get the latest version tag for a package. |
download_latest_package |
Download the latest version of a package. |
load_resources_from_package |
Load a FHIR package from the registry and add all structure definitions. |
list_package_versions ¶
list_package_versions(package_name: str) -> PackageMetadata
List all versions for a package.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
package_name
|
str
|
Name of the package (e.g., "hl7.fhir.us.core") |
required |
Returns:
| Type | Description |
|---|---|
PackageMetadata
|
(PackageMetadata) Package metadata object with all available versions |
Raises:
| Type | Description |
|---|---|
PackageNotFoundError
|
If the package is not found |
PackageResolutionError
|
For other API errors |
download_package ¶
download_package(package_name: str, package_version: str, extract: bool = False) -> Union[bytes, TarFile]
Download a specific package version.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
package_name
|
str
|
Name of the package |
required |
package_version
|
str
|
Version of the package |
required |
extract
|
bool
|
If True, return extracted TarFile object, otherwise raw bytes |
False
|
Returns:
| Type | Description |
|---|---|
Union[bytes, TarFile]
|
(TarFile) Raw tar.gz bytes or extracted TarFile object |
Raises:
| Type | Description |
|---|---|
PackageNotFoundError
|
If the package or version is not found |
PackageResolutionError
|
For other API errors |
get_latest_version ¶
download_latest_package ¶
Download the latest version of a package.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
package_name
|
str
|
Name of the package |
required |
extract
|
bool
|
If True, return extracted TarFile object, otherwise raw bytes |
False
|
Returns:
| Type | Description |
|---|---|
Union[bytes, TarFile]
|
(Union[bytes, tarfile.TarFile]) Raw tar.gz bytes or extracted TarFile object |
Raises:
| Type | Description |
|---|---|
PackageNotFoundError
|
If the package is not found or has no latest version |
PackageResolutionError
|
For other API errors |
load_resources_from_package ¶
load_resources_from_package(target_resource: str, package_name: str, package_version: Optional[str] = None, install_dependencies: bool = True, raise_on_errors: bool = False) -> list[dict]
Load a FHIR package from the registry and add all structure definitions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
package_name
|
str
|
Name of the package (e.g., "hl7.fhir.us.core") |
required |
package_version
|
Optional[str]
|
Version of the package (defaults to latest) |
None
|
install_dependencies
|
bool
|
If True, checks and installs any dependencies of the package |
True
|
raise_on_errors
|
bool
|
If True, raises on processing errors; otherwise emits warnings |
False
|
Raises:
| Type | Description |
|---|---|
PackageNotFoundError
|
If package or version not found |
PackageResolutionError
|
If download fails |
PackageValidationError
|
If downloaded content is not a tar.gz file or no valid resources are found in the package |
get_package_metadata ¶
get_package_metadata(package_name: str, base_url: Optional[str] = None) -> PackageMetadata
Convenience function to get package metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
package_name
|
str
|
Name of the package |
required |
base_url
|
Optional[str]
|
Optional base URL |
None
|
Returns:
| Type | Description |
|---|---|
PackageMetadata
|
(PackageMetadata) Metadata of the package |
download_package ¶
download_package(package_name: str, package_version: str, base_url: Optional[str] = None, extract: bool = False) -> Union[bytes, TarFile]
Convenience function to download a package.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
package_name
|
str
|
Name of the package |
required |
package_version
|
str
|
Version of the package |
required |
base_url
|
Optional[str]
|
Optional base URL |
None
|
extract
|
bool
|
If True, return extracted TarFile object, otherwise raw bytes |
False
|
Returns:
| Type | Description |
|---|---|
Union[bytes, TarFile]
|
Raw tar.gz bytes or extracted TarFile object |
download_latest_package ¶
download_latest_package(package_name: str, base_url: Optional[str] = None, extract: bool = False) -> Union[bytes, TarFile]
Convenience function to download the latest version of a package.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
package_name
|
str
|
Name of the package |
required |
base_url
|
Optional[str]
|
Optional base URL |
None
|
extract
|
bool
|
If True, return extracted TarFile object, otherwise raw bytes |
False
|
Returns:
| Type | Description |
|---|---|
Union[bytes, TarFile]
|
(Union[bytes, tarfile.TarFile]) Raw tar.gz bytes or extracted TarFile object |