Skip to main content

helix.fhir.client.sdk

Continuous Integration Latest Release GitHub license

Fluent API to call the FHIR server that handles:

  1. Authentication to FHIR server
  2. Renewing access token when they expire
  3. Retry when there are transient errors
  4. Un-bundling the resources received from FHIR server
  5. Paging
  6. Streaming
  7. Logging
  8. Simulating a $graph call when the server does not support it

Usage

pip install helix.fhir.client.sdk

Documentation

https://icanbwell.github.io/helix.fhir.client.sdk/

Test Project using this

https://github.com/icanbwell/fhir-server-performance

Python Version Support

  • 1.x supports python 3.7+
  • 2.x supports python 3.10+
  • 3.x supports python 3.12+

Asynchronous Support

When communicating with FHIR servers, a lot of time is spent waiting for the server to respond. This is a good use case for using asynchronous programming. This SDK supports asynchronous programming using the async and await keywords.

The return types are Python AsyncGenerators. Python makes it very easy to work with AsyncGenerators.

For example, if the SDK provides a function like this:

async def get_resources(self) -> AsyncGenerator[FhirGetResponse, None]:
    ...

You can iterate over the results as they become available:

response: Optional[FhirGetResponse]
async for response in client.get_resources():
    print(response.resource)

Or you can get a list of responses (which will return AFTER all the responses are received:

responses: List[FhirGetResponse] = [response async for response in client.get_resources()]

Or you can aggregate the responses into one response (which will return AFTER all the responses are received:

response: Optional[FhirGetResponse] = await FhirGetResponse.from_async_generator(client.get_resources())

Data Streaming

For FHIR servers that support data streaming (e.g., b.well FHIR server), you can just set the use_data_streaming parameter to stream the data as it is received. The data will be streamed in AsyncGenerators as described above.

Streaming $merge Responses

use_data_streaming also applies to $merge calls (merge_async, merge_resources_async, merge_bundle_async, merge_bundle_uncompressed). When enabled, the SDK sends Accept: application/fhir+ndjson so a b.well FHIR server that supports it (see merge.md) can stream the $merge response back instead of building the whole response in memory first.

from helix_fhir_client_sdk.fhir_client import FhirClient

fhir_client = FhirClient().url(fhir_server_url).resource("Patient").use_data_streaming(True)

merge_response = await FhirMergeResponse.from_async_generator(
    fhir_client.merge_async(json_data_list=[json.dumps(patient_resource)])
)

This only changes how the response is read; it does not change the request body. If you also want the request body sent with chunked transfer encoding (independent of response streaming), opt in separately with send_data_as_chunked(True).

Error responses (e.g. a 400 with an OperationOutcome) are unaffected by streaming - the SDK always returns the full error body via response.error/response.responses[...]["issue"], whether or not use_data_streaming is enabled.

Persistent Sessions (Connection Reuse)

By default, the SDK creates a new HTTP session for each request. For better performance (~4× faster), you can use persistent sessions to reuse connections across multiple requests.

Important: When you provide a custom session factory using use_http_session(), YOU are responsible for managing the session lifecycle, including closing it when done. The SDK will NOT automatically close user-provided sessions.

import aiohttp
from helix_fhir_client_sdk.fhir_client import FhirClient

# Create a persistent session for connection reuse
session = aiohttp.ClientSession()

try:
    # Configure FhirClient to use persistent session
    fhir_client = (
        FhirClient()
        .url("https://fhir.example.com")
        .resource("Patient")
        .use_http_session(lambda: session)  # User provides session factory
    )
    
    # Multiple requests reuse the same connection (~4× performance boost)
    response1 = await fhir_client.get_async()
    response2 = await fhir_client.clone().resource("Observation").get_async()
    
finally:
    # User must close the session when done
    await session.close()

Session Lifecycle Rules:

  • No custom factory (default): SDK creates and closes the session automatically
  • Custom factory provided: User is responsible for closing the session

Storage Compression

The FHIR client SDK supports two types of compression:

  1. HTTP Compression (compress): Compresses HTTP request body when sending data to the server. Default: enabled
  2. In-Memory Storage (storage_mode): Controls how FHIR resources are stored in memory. Default: raw (no compression)

Disabling HTTP Compression

HTTP compression (gzip) is enabled by default for request bodies. To disable it:

from helix_fhir_client_sdk.fhir_client import FhirClient

# Disable HTTP compression for requests
fhir_client = FhirClient().url("https://fhir.example.com").compress(False)

In-Memory Storage Modes

The SDK supports different storage modes for FHIR resources through the set_storage_mode() method. By default, resources are stored as raw Python dictionaries (no compression).

from helix_fhir_client_sdk.fhir_client import FhirClient
from compressedfhir.utilities.compressed_dict.v1.compressed_dict_storage_mode import CompressedDictStorageMode

# Use raw storage (default) - no compression, resources stored as plain Python dicts
fhir_client = FhirClient().set_storage_mode(CompressedDictStorageMode(storage_type="raw"))

# Use msgpack storage - stores resources in msgpack format
fhir_client = FhirClient().set_storage_mode(CompressedDictStorageMode(storage_type="msgpack"))

# Use compressed msgpack storage - stores resources in compressed msgpack format
fhir_client = FhirClient().set_storage_mode(CompressedDictStorageMode(storage_type="compressed_msgpack"))

Available storage types:

  • raw: Default. Resources are stored as standard Python dictionaries (no compression)
  • msgpack: Resources are serialized using MessagePack for efficient storage
  • compressed_msgpack: Resources are serialized using MessagePack and then compressed

Getting Raw Python Dictionaries

To completely bypass the compressedfhir library and get plain Python dictionaries:

# Returns plain Python dicts, not FhirResource objects
result = await fhir_client.get_raw_resources_async()
resources = result["_resources"]  # list[dict[str, Any]]

Download files

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

Source Distribution

helix_fhir_client_sdk-5.0.5.tar.gz (189.3 kB view details)

Uploaded Source

Built Distribution

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

helix_fhir_client_sdk-5.0.5-py3-none-any.whl (321.3 kB view details)

Uploaded Python 3

File details

Details for the file helix_fhir_client_sdk-5.0.5.tar.gz.

File metadata

  • Download URL: helix_fhir_client_sdk-5.0.5.tar.gz
  • Upload date:
  • Size: 189.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.14

File hashes

Hashes for helix_fhir_client_sdk-5.0.5.tar.gz
Algorithm Hash digest
SHA256 27baa81601471ba4671ea546ca8be1ed4c6b3dd4a5ad43b9e9ad614bf5352a36
MD5 7ac90778219f1fb767f148eaceb8b8ab
BLAKE2b-256 ef414de3efd02e8d40a41ba426c2ce78e2a9d9cb1b123ffbd5f20b1bc7423946

See more details on using hashes here.

File details

Details for the file helix_fhir_client_sdk-5.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for helix_fhir_client_sdk-5.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 df7fb97ac278e7dcdc2664ab572b58e7d27d3adf3f99929a248ce372564969e3
MD5 0896b651e511b1f58a10fec72423108b
BLAKE2b-256 ef0fa310651f3861d58fe4ab8cd0454838c2f56bb85acef594516ca4b4d412af

See more details on using hashes here.

Release history Release notifications | RSS feed

5.0.9

2 files

5.0.8

2 files

5.0.7

2 files

5.0.6

2 files

This release

5.0.5 This release

2 files

5.0.4

2 files

5.0.3

2 files

5.0.2

2 files

5.0.1

2 files

4.2.29

2 files

4.2.28

2 files

4.2.26

2 files

4.2.25

2 files

4.2.24

2 files

4.2.23

2 files

4.2.22

2 files

4.2.21

2 files

4.2.20

2 files

4.2.19

2 files

4.2.18

2 files

4.2.17

2 files

4.2.16

2 files

4.2.15

2 files

4.2.14

2 files

4.2.13

2 files

4.2.12

2 files

4.2.11

2 files

4.2.10

2 files

4.2.9

2 files

4.2.8

2 files

4.2.7

2 files

4.2.6

2 files

4.2.5

2 files

4.2.4

2 files

4.2.3

2 files

4.2.2

2 files

4.2.1

2 files

4.1.77

2 files

4.1.76

2 files

4.1.75

2 files

4.1.74

2 files

4.1.73

2 files

4.1.72

2 files

4.1.71

2 files

4.1.70

2 files

4.1.69

2 files

4.1.68

2 files

4.1.67

2 files

4.1.66

2 files

4.1.65

2 files

4.1.64

2 files

4.1.63

2 files

4.1.62

2 files

4.1.61

2 files

4.1.60

2 files

4.1.59

2 files

4.1.58

2 files

4.1.57

2 files

4.1.56

2 files

4.1.55

2 files

4.1.54

2 files

4.1.53

2 files

4.1.52

2 files

4.1.51

2 files

4.1.50

2 files

4.1.49

2 files

4.1.48

2 files

4.1.47

2 files

4.1.46

2 files

4.1.45

2 files

4.1.44

2 files

4.1.43

2 files

4.1.42

2 files

4.1.41

2 files

4.1.40

2 files

4.1.39

2 files

4.1.38

2 files

4.1.37

2 files

4.1.36

2 files

4.1.35

2 files

4.1.34

2 files

4.1.33

2 files

4.1.32

2 files

4.1.31

2 files

4.1.30

2 files

4.1.29

2 files

4.1.28

2 files

4.1.27

2 files

4.1.26

2 files

4.1.25

2 files

4.1.24

2 files

4.1.23

2 files

4.1.22

2 files

4.1.21

2 files

4.1.20

2 files

4.1.19

2 files

4.1.18

2 files

4.1.17

2 files

4.1.16

2 files

4.1.14

2 files

4.1.13

2 files

4.1.12

2 files

4.1.11

2 files

4.1.10

2 files

4.1.9

2 files

4.1.8

2 files

4.1.7

2 files

4.1.6

2 files

4.1.5

2 files

4.1.4

2 files

4.1.3

2 files

4.1.2

2 files

4.1.1

2 files

4.1.0

2 files

4.0.20

2 files

4.0.19

2 files

4.0.18

2 files

4.0.17

2 files

4.0.16

2 files

4.0.15

2 files

4.0.14

2 files

4.0.13

2 files

4.0.12

2 files

4.0.11

2 files

4.0.10

2 files

4.0.9

2 files

4.0.8

2 files

4.0.7

2 files

4.0.6

2 files

4.0.5

2 files

4.0.4

2 files

4.0.3

2 files

4.0.2

2 files

4.0.1

2 files

3.0.48

2 files

3.0.47

2 files

3.0.46

2 files

3.0.45

2 files

3.0.44

2 files

3.0.43

2 files

3.0.42

2 files

3.0.41

2 files

3.0.40

2 files

3.0.39

2 files

3.0.38

2 files

3.0.37

2 files

3.0.36

2 files

3.0.35

2 files

3.0.34

2 files

3.0.33

2 files

3.0.32

2 files

3.0.31

2 files

3.0.30

2 files

3.0.29

2 files

3.0.28

2 files

3.0.27

2 files

3.0.26

2 files

3.0.25

2 files

3.0.24

2 files

3.0.23

2 files

3.0.22

2 files

3.0.21

2 files

3.0.20

2 files

3.0.19

2 files

3.0.18

2 files

3.0.17

2 files

3.0.16

2 files

3.0.15

2 files

3.0.14

2 files

3.0.13

2 files

3.0.12

2 files

3.0.11

2 files

3.0.10

2 files

3.0.9

2 files

3.0.8

2 files

3.0.7

2 files

3.0.6

2 files

3.0.5

2 files

3.0.4

2 files

3.0.3

2 files

3.0.2

2 files

3.0.1

2 files

3.0.0

2 files

2.0.30

2 files

2.0.29

2 files

2.0.28

2 files

2.0.27

2 files

2.0.26

2 files

2.0.25

2 files

2.0.24

2 files

2.0.23

2 files

2.0.22

2 files

2.0.21

2 files

2.0.20

2 files

2.0.19

2 files

2.0.18

2 files

2.0.17

2 files

2.0.16

2 files

2.0.15

2 files

2.0.14

2 files

2.0.13

2 files

2.0.12

2 files

2.0.11

2 files

2.0.10

2 files

2.0.9

2 files

2.0.8

2 files

2.0.7

2 files

2.0.6

2 files

2.0.5

2 files

2.0.4

2 files

2.0.3

2 files

2.0.2

2 files

2.0.1

2 files

2.0.0

2 files

1.0.53

2 files

1.0.51

2 files

1.0.50

2 files

1.0.49

2 files

1.0.48

2 files

1.0.47

2 files

1.0.46

2 files

1.0.45

2 files

1.0.44

2 files

1.0.43

2 files

1.0.42

2 files

1.0.41

2 files

1.0.40

2 files

1.0.39

2 files

1.0.38

2 files

1.0.37

2 files

1.0.36

2 files

1.0.35

2 files

1.0.34

2 files

1.0.33

2 files

1.0.32

2 files

1.0.31

2 files

1.0.30

2 files

1.0.29

2 files

1.0.28

2 files

1.0.27

2 files

1.0.26

2 files

1.0.25

2 files

1.0.24

2 files

1.0.23

2 files

1.0.22

2 files

1.0.21

2 files

1.0.20

2 files

1.0.19

2 files

1.0.18

2 files

1.0.17

2 files

1.0.16

2 files

1.0.15

2 files

1.0.14

2 files

1.0.13

2 files

1.0.12

2 files

1.0.11

2 files

1.0.10

2 files

1.0.9

2 files

1.0.8

2 files

1.0.7

2 files

1.0.6

2 files

1.0.5

2 files

1.0.4

2 files

1.0.3

2 files

1.0.2

2 files

1.0.1

2 files

1.0.0

2 files

0.1.53

2 files

0.1.52

2 files

0.1.51

2 files

0.1.50

2 files

0.1.49

2 files

0.1.48

2 files

0.1.46

2 files

0.1.45

2 files

0.1.44

2 files

0.1.43

2 files

0.1.42

2 files

0.1.41

2 files

0.1.40

2 files

0.1.39

2 files

0.1.38

2 files

0.1.37

2 files

0.1.36

2 files

0.1.35

2 files

0.1.34

2 files

0.1.33

2 files

0.1.32

2 files

0.1.31

2 files

0.1.30

2 files

0.1.29

2 files

0.1.28

2 files

0.1.27

2 files

0.1.26

2 files

0.1.25

2 files

0.1.24

2 files

0.0.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page