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. |
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
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 |