A simple Python client library for querying FHIR servers. Sync and async support.
- Synchronous and asynchronous FHIR server querying
- Multiple authentication methods (Basic Auth, Token Auth, Login Auth)
- Support for GET and POST search requests
- Pagination handling
- Bundle response handling with DataFrame conversion
- Type hints and resource type validation
pip install fhir-queryfrom fhir_query import FhirQueryClient
# Initialize the client
client = FhirQueryClient(
base_url="https://hapi.fhir.org/baseR4/",
)
# Query patients
response = client.get(resource_type="Patient", params={"family": "Smith"})
# Access the raw bundle
bundle = response.data
print(bundle)
# Access the resources
resources = response.resources
print(resources)from fhir_query import AsyncFhirQueryClient
import asyncio
async def main():
# Initialize the async client
client = AsyncFhirQueryClient(
base_url="https://hapi.fhir.org/baseR4/",
)
# Query patients
response = await client.get(
resource_type="Patient",
params={"gender": "female"}
)
# Convert to DataFrame
df = response.to_df()
print(df)
asyncio.run(main())The client supports three authentication methods:
basic: Basic HTTP authentication with username and passwordtoken: Bearer token authenticationlogin: Login-based authentication that obtains a token from a login endpoint
The FhirQueryBundle class provides convenient methods to work with FHIR Bundle responses:
# Get total count
total_count = bundle.total
# Access resources
resources = bundle.resources
# Convert to DataFrame
df = bundle.to_df()
# Pagination
next_link = bundle.next_link
previous_link = bundle.previous_link