{"id":6627,"library":"fhirclient","title":"FHIRClient Python Library","description":"fhirclient is a flexible Python client for interacting with FHIR (Fast Healthcare Interoperability Resources) servers, supporting the SMART on FHIR protocol. It provides data model classes for FHIR resources and utilities for API interactions like reading, searching, and authorization. Currently at version 4.4.0, the library is actively maintained with regular releases addressing Python compatibility, FHIR specification updates, and feature enhancements.","status":"active","version":"4.4.0","language":"en","source_language":"en","source_url":"https://github.com/smart-on-fhir/client-py","tags":["FHIR","healthcare","API client","SMART on FHIR","medical informatics","interoperability"],"install":[{"cmd":"pip install fhirclient","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Minimum Python version required for fhirclient 4.4.0 is 3.10.","package":"python","optional":false}],"imports":[{"symbol":"FHIRClient","correct":"from fhirclient import client\nsmart = client.FHIRClient(...)"},{"symbol":"Patient","correct":"from fhirclient.models.patient import Patient"},{"symbol":"FHIRSearch","correct":"from fhirclient.client import FHIRSearch"},{"symbol":"FHIRDate","correct":"from fhirclient.models.fhirdate import FHIRDate"},{"note":"Introduced in v4.2.0, along with FHIRInstant and FHIRTime, for more specific date/time handling. FHIRDate is now the base class.","symbol":"FHIRDateTime","correct":"from fhirclient.models.fhirdate import FHIRDateTime"}],"quickstart":{"code":"import os\nfrom fhirclient import client\nfrom fhirclient.models.patient import Patient\n\n# Configure settings for an open FHIR server\nsettings = {\n    'app_id': os.environ.get('FHIR_APP_ID', 'my_app'),\n    'api_base': os.environ.get('FHIR_API_BASE', 'https://r4.smarthealthit.org')\n}\n\n# Initialize the FHIRClient\nsmart = client.FHIRClient(settings=settings)\n\n# Try to read a specific patient by ID\ntry:\n    patient_id = os.environ.get('FHIR_PATIENT_ID', '2cda5aad-e409-4070-9a15-e1c35c46ed5a') # Example ID for smarthealthit.org sandbox\n    patient = Patient.read(patient_id, smart.server)\n    print(f\"Successfully fetched Patient: {patient.id}\")\n    if patient.name:\n        print(f\"Patient Name: {smart.human_name(patient.name[0])}\")\n    if patient.birthDate:\n        print(f\"Birth Date: {patient.birthDate.isostring}\")\nexcept Exception as e:\n    print(f\"Error fetching patient: {e}\")\n\n# Example of a simple search for Patients\ntry:\n    search = Patient.where({'gender': 'female'}).limit(2)\n    # Using perform_resources_iter for robust pagination handling (introduced in v4.3.0)\n    female_patients = list(search.perform_resources_iter(smart.server))\n    print(f\"\\nFound {len(female_patients)} female patients (first 2):\")\n    for p in female_patients:\n        print(f\" - {smart.human_name(p.name[0]) if p.name else 'Unnamed'} (ID: {p.id})\")\nexcept Exception as e:\n    print(f\"Error during patient search: {e}\")","lang":"python","description":"This quickstart demonstrates how to initialize the `FHIRClient`, fetch a specific patient resource by ID, and perform a basic search query. It uses environment variables for configuration to ensure security and flexibility, falling back to a public SMART Health IT sandbox for demonstration. The example also shows the use of `perform_resources_iter` for handling search results, which is recommended for robust pagination."},"warnings":[{"fix":"Upgrade your Python environment to 3.10 or newer, or pin `fhirclient` to an older compatible version (e.g., `<4.3.0` for Python 3.8).","message":"Python 3.8 support was dropped in `fhirclient` v4.3.0. As of v4.4.0, the minimum required Python version is 3.10. Older versions of Python will no longer work with these client versions.","severity":"breaking","affected_versions":">=4.3.0"},{"fix":"Update type checks from `field_type is FHIRDate` to `issubclass(field_type, FHIRDate)` to correctly identify all FHIR date/time types.","message":"In v4.2.0, the date/time model was refined. `FHIRDate` is now a base class, with new specific classes `FHIRDateTime`, `FHIRInstant`, and `FHIRTime` inheriting from it. Code that used `field_type is FHIRDate` for exact type checking will break.","severity":"breaking","affected_versions":">=4.2.0"},{"fix":"Review existing uses of `FHIRSearch.perform_resources` to ensure the new pagination behavior is intended. For explicit control over pagination or to avoid loading all results into memory at once, switch to `perform_iter` or `perform_resources_iter`.","message":"Beginning with v4.3.0, `FHIRSearch.perform_resources` now automatically handles pagination behind the scenes, potentially returning more results than previously. New methods `perform_iter` and `perform_resources_iter` were added for explicit iteration over paged results.","severity":"gotcha","affected_versions":">=4.3.0"},{"fix":"Ensure your authorization flow incorporates PKCE if interacting with servers that require it. Refer to the `fhirclient` documentation or the SMART on FHIR specification for details on implementing PKCE with the library.","message":"Version 4.4.0 added support for PKCE (Proof Key for Code Exchange) parameters in the authorization code exchange. While not a breaking change for existing flows, integration with FHIR servers that mandate PKCE for enhanced security might require client updates for full compliance or prevent authentication with older clients.","severity":"gotcha","affected_versions":"All"},{"fix":"Before using `fhirclient`, verify its compatibility with your target FHIR server's specification version by checking the official client-py documentation.","message":"The `fhirclient` library's versioning is not directly tied to the FHIR specification versioning (e.g., R4, STU3). Always consult the `fhirclient` documentation or GitHub README to understand which FHIR specification versions a particular client version supports.","severity":"gotcha","affected_versions":"All"},{"fix":"Upgrade to `fhirclient` v4.3.1 or newer to avoid spurious deprecation warnings when using `perform_iter` or `perform_resources_iter`.","message":"Implicit deprecation warnings for `FHIRSearch.perform` and `FHIRSearch.perform_resources` were being triggered by their `_iter` counterparts prior to v4.3.1. These warnings were unintended for the `_iter` versions.","severity":"deprecated","affected_versions":"<4.3.1"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[]}