Skip to main content

A simple client for querying FHIR servers

Project description

fhir-query

A simple Python client library for querying FHIR servers. Sync and async support.

Features

  • 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

Installation

pip install fhir-query

Quick Start

Synchronous Client

from 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)

Asynchronous Client

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())

Authentication Methods

The client supports three authentication methods:

  • basic: Basic HTTP authentication with username and password
  • token: Bearer token authentication
  • login: Login-based authentication that obtains a token from a login endpoint

Bundle Handling

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fhir_query-0.1.1.tar.gz (15.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fhir_query-0.1.1-py3-none-any.whl (18.4 kB view details)

Uploaded Python 3

File details

Details for the file fhir_query-0.1.1.tar.gz.

File metadata

  • Download URL: fhir_query-0.1.1.tar.gz
  • Upload date:
  • Size: 15.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.4.22

File hashes

Hashes for fhir_query-0.1.1.tar.gz
Algorithm Hash digest
SHA256 2868ff36dc8ae59726d9ae84763e68ba8e8aff18e16d9691415d99cf4c8a6f22
MD5 f8125ca73ebe7b8e57dc12f27975f92d
BLAKE2b-256 06f475e5e719c4846f45fc5c72bef66e3c2bd88cec3609b6fda32d5496e4b09a

See more details on using hashes here.

File details

Details for the file fhir_query-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: fhir_query-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 18.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.4.22

File hashes

Hashes for fhir_query-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 90e4b645a15c18a420e7ad226d97e9b917b75d3d27a79588a8de85d1248b2cf1
MD5 ca3828aa430841a7e60a63342da0ccae
BLAKE2b-256 57d5d3f552c94262e3e89fef69421f229bc22a695a802df4ed1d4f0281af6e41

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page