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.2.tar.gz (15.8 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.2-py3-none-any.whl (19.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for fhir_query-0.1.2.tar.gz
Algorithm Hash digest
SHA256 69ebeeb75c353ffe86c88be8880d9a0c7ae684a2e57332ac0d53f2b9f5e8294d
MD5 8aefbedd5871326d9238d82a6305898f
BLAKE2b-256 0c01fd38ca9983feeafbf4942b6042eec6007d40cc2a4528d73b159e73005a97

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for fhir_query-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2260f367be08a37b75266ea576fac9d76eaf721bd8657f09cf4cd398c4064ed5
MD5 2bd33b1b3683ee30e2f3f78dc0632ebc
BLAKE2b-256 7191b0b4db34ca93aac7044d7a5034db059873435d918cd245b0f31eb1176ebb

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