FHIR Packages Client
FHIR Package Registry client utilities.
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. Defaults to packages.simplifier.net |
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. |
Source code in fhircraft/fhir/packages/client.py
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 |
FHIRPackageRegistryError
|
For other API errors |
Source code in fhircraft/fhir/packages/client.py
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 |
FHIRPackageRegistryError
|
For other API errors |
Source code in fhircraft/fhir/packages/client.py
get_latest_version
Get the latest version tag for a package.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
package_name
|
str
|
Name of the package |
required |
Returns:
| Type | Description |
|---|---|
Optional[str]
|
(str | None) Latest version string or None if not available |
Source code in fhircraft/fhir/packages/client.py
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 |
FHIRPackageRegistryError
|
For other API errors |
Source code in fhircraft/fhir/packages/client.py
load_resources_from_package
load_resources_from_package(target_resource: str, package_name: str, package_version: Optional[str] = None, install_dependencies: bool = True, fail_if_exists: 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
|
fail_if_exists
|
bool
|
If True, raise error if package already loaded |
False
|
Raises:
| Type | Description |
|---|---|
PackageNotFoundError
|
If package or version not found |
FHIRPackageRegistryError
|
If download fails |
RuntimeError
|
If package processing fails |
Source code in fhircraft/fhir/packages/client.py
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | |
FHIRPackageRegistryError
Path: fhircraft.fhir.packages.client.FHIRPackageRegistryError
Bases: Exception
Base exception for FHIR Package Registry client errors.
PackageNotFoundError
Path: fhircraft.fhir.packages.client.PackageNotFoundError
Bases: FHIRPackageRegistryError
Raised when a package is not found.
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 (defaults to packages.simplifier.net) |
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 |
Source code in fhircraft/fhir/packages/client.py
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 (defaults to packages.simplifier.net) |
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 |
Source code in fhircraft/fhir/packages/client.py
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 (defaults to packages.simplifier.net) |
None
|
Returns:
| Type | Description |
|---|---|
PackageMetadata
|
(PackageMetadata) Metadata of the package |