{"id":131,"library":"fhir.resources","title":"FHIR Resources (Python)","description":"Python library for FHIR (Fast Healthcare Interoperability Resources) providing Pydantic-based models for all FHIR resource types. Supports FHIR R4, R4B, R5, STU3, and DSTU2. Built on Pydantic v2 for validation, serialization, and deserialization of FHIR JSON. Current version targets FHIR R5 by default with backwards-compatible imports for older FHIR versions.","status":"active","version":"8.0.0","language":"python","source_language":"en","source_url":"https://github.com/nazrulworld/fhir.resources","tags":["fhir","healthcare","hl7","pydantic","validation","interoperability","python","medical"],"install":[{"cmd":"pip install fhir.resources","lang":"bash","label":"Python (latest, FHIR R5 default)"},{"cmd":"pip install 'fhir.resources[r4]'","lang":"bash","label":"Python (with R4 extras)"}],"dependencies":[{"reason":"Core dependency. fhir.resources 8.x requires Pydantic v2. Pydantic v1 is not supported.","package":"pydantic","optional":false},{"reason":"Optional faster JSON serializer. Used automatically if installed.","package":"orjson","optional":true}],"imports":[{"note":"The package uses a namespace package 'fhir.resources'. Each resource type is in its own module with a lowercase name.","wrong":"from fhir_resources import Patient","symbol":"Patient","correct":"from fhir.resources.patient import Patient"},{"note":"To use FHIR R4B resources, import from fhir.resources.R4B subpackage. Default top-level imports are R5.","wrong":"from fhir.resources.patient import Patient  # this gives R5","symbol":"Patient (R4)","correct":"from fhir.resources.R4B.patient import Patient"},{"note":"STU3 resources live under the fhir.resources.STU3 subpackage.","symbol":"Patient (STU3)","correct":"from fhir.resources.STU3.patient import Patient"},{"note":"Each FHIR resource is its own module. Import the class with the CamelCase name from the lowercase module.","symbol":"Bundle","correct":"from fhir.resources.bundle import Bundle"}],"quickstart":{"code":"from fhir.resources.patient import Patient\n\n# Create from dict\npatient_data = {\n    \"resourceType\": \"Patient\",\n    \"id\": \"example\",\n    \"active\": True,\n    \"name\": [\n        {\n            \"use\": \"official\",\n            \"family\": \"Doe\",\n            \"given\": [\"John\"]\n        }\n    ],\n    \"gender\": \"male\",\n    \"birthDate\": \"1990-01-01\"\n}\n\npatient = Patient.model_validate(patient_data)\nprint(patient.name[0].family)  # 'Doe'\n\n# Serialize back to FHIR JSON\nprint(patient.model_dump_json(indent=2))\n\n# Parse from JSON string\njson_str = patient.model_dump_json()\npatient2 = Patient.model_validate_json(json_str)\nprint(patient2.id)  # 'example'","lang":"python","description":"Create, validate, and serialize a FHIR Patient resource using Pydantic v2 methods."},"warnings":[{"fix":"Either upgrade your Python environment to 3.10 or later and install 'pydantic>=2.0', or pin fhir.resources<7.0.0 for Pydantic v1 compatibility (which supports Python 3.8+).","message":"fhir.resources 7.x+ requires Pydantic v2. Pydantic v2 leverages modern Python typing features (like the '|' operator for unions) that are fully supported from Python 3.10 onwards. Running fhir.resources 7.x+ with Python 3.9 or older (alongside Pydantic v2) will result in a TypeError due to unrecognized syntax. Projects still on Pydantic v1 must use fhir.resources 6.x.","severity":"breaking","affected_versions":">= 7.0.0"},{"fix":"For R4B resources, import from fhir.resources.R4B.* subpackage instead of top-level fhir.resources.*.","message":"Default FHIR version changed from R4B to R5 in fhir.resources 7.x+. Top-level imports now return R5 models.","severity":"breaking","affected_versions":">= 7.0.0"},{"fix":"Use Patient.model_validate(data) instead of Patient.parse_obj(data), and patient.model_dump_json() instead of patient.json().","message":"Pydantic v2 migration changed validation and serialization methods. .parse_obj() and .json() are replaced.","severity":"breaking","affected_versions":">= 7.0.0"},{"fix":"Avoid naming your own modules or packages 'fhir' to prevent import conflicts.","message":"The package installs as a namespace package (fhir.resources). Do not create your own 'fhir' package in your project or it will shadow the library.","severity":"gotcha","affected_versions":"all"},{"fix":"Catch pydantic.ValidationError and inspect e.errors() for details on which fields failed validation.","message":"FHIR resource validation is strict by default. Missing required fields or invalid value sets will raise ValidationError.","severity":"gotcha","affected_versions":"all"},{"fix":"Always use the exact CamelCase resourceType, e.g. 'Patient', 'Observation', 'Bundle'.","message":"resourceType field must match the class name exactly. Passing resourceType='patient' (lowercase) will raise a validation error.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-12T08:12:01.586Z","next_check":"2026-06-17T00:00:00.000Z","problems":[{"fix":"Ensure that your Pydantic installation is compatible with your `fhir.resources` version. For `fhir.resources` v7.0.0 and above, upgrade Pydantic to version 2.x: `pip install --upgrade pydantic`. For older `fhir.resources` versions, you might need to downgrade Pydantic: `pip install 'pydantic<2'`.","cause":"This error typically occurs when `fhir.resources` (version 7.0.0 or higher) is installed in an environment where Pydantic v1 is present, or an older version of `fhir.resources` (prior to 7.0.0) is attempting to run with Pydantic v2. `fhir.resources` 7.x+ depends on Pydantic v2, which includes `pydantic_core`.","error":"ModuleNotFoundError: No module named 'pydantic_core._pydantic_core'"},{"fix":"Provide a valid value for the missing required field. For example, when creating a `Patient` resource, ensure all mandatory fields as per the FHIR specification are included:\n```python\nfrom fhir.resources.R5.patient import Patient\n\npatient_data = {\n    \"resourceType\": \"Patient\",\n    \"id\": \"example\",\n    \"active\": True,\n    \"name\": [\n        {\n            \"use\": \"official\",\n            \"family\": \"Chalmers\",\n            \"given\": [\"Peter\"]\n        }\n    ],\n    \"gender\": \"male\",\n    \"birthDate\": \"1974-12-25\"\n}\n\npatient = Patient(**patient_data)\n# Or, if loading from JSON string\n# patient = Patient.parse_raw(json_string_data)\n```\nNote: `Patient` itself does not have a 'status' field, but other resources like `Observation` or `ServiceRequest` do. The example `Patient` data is shown to illustrate providing required fields.","cause":"This Pydantic validation error indicates that a required field within the FHIR resource (e.g., `status` for a `Patient` resource) is missing in the data provided when instantiating the `fhir.resources` model, violating the FHIR specification.","error":"pydantic.error_wrappers.ValidationError: 1 validation error for Patient\\nresource -> status\\n  field required (type=value_error.missing)"},{"fix":"Import resources from the correct FHIR version sub-package. For R4B resources, use `from fhir.resources.R4B.patient import Patient`. For STU3 resources, use `from fhir.resources.STU3.patient import Patient`. If you intend to use the default R5, simply use `from fhir.resources.R5.patient import Patient` or `from fhir.resources.patient import Patient` (as R5 is the default).","cause":"This error occurs when trying to import FHIR resources from a specific version (like R4) using an incorrect path. The `fhir.resources` library (version 7.0.0+) defaults to R5, and older versions (STU3, R4B) are located in specific sub-packages. R4 is explicitly noted to not have its own sub-package in newer versions, with R4B being the closest available.","error":"AttributeError: module 'fhir.resources' has no attribute 'R4'"},{"fix":"Ensure that the input data strictly conforms to the FHIR specification for the target resource and version. Remove any extraneous fields that are not part of the standard, or ensure that you are using the correct FHIR version's resource definition. For example, if parsing a resource, inspect the input JSON to remove unexpected keys:\n```python\nfrom fhir.resources.R5.patient import Patient\n\n# This will raise 'extra fields not permitted' because 'unexpectedField' is not part of Patient\nmalformed_data = {\n    \"resourceType\": \"Patient\",\n    \"id\": \"example\",\n    \"active\": True,\n    \"gender\": \"male\",\n    \"unexpectedField\": \"some value\"\n}\n\ntry:\n    patient = Patient(**malformed_data)\nexcept Exception as e:\n    print(e)\n\n# Corrected data\ncorrect_data = {\n    \"resourceType\": \"Patient\",\n    \"id\": \"example\",\n    \"active\": True,\n    \"gender\": \"male\"\n}\npatient = Patient(**correct_data)\n```","cause":"This validation error from Pydantic indicates that the input JSON or dictionary for a FHIR resource contains fields that are not defined in the FHIR specification for that resource type or its current profile, or it may contain elements from a different FHIR version.","error":"pydantic.error_wrappers.ValidationError: ... extra fields not permitted (type=value_error.extra)"}],"ecosystem":"pypi","meta_description":null,"install_score":90,"install_tag":"verified","quickstart_score":70,"quickstart_tag":"verified","pypi_latest":null,"install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"r4","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.56,"mem_mb":14.1,"disk_size":"52.2M"},{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.56,"mem_mb":14.1,"disk_size":"52.2M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"r4","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.41,"mem_mb":14.1,"disk_size":"52M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.39,"mem_mb":14.1,"disk_size":"52M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"r4","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.8,"mem_mb":15.7,"disk_size":"57.2M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.82,"mem_mb":15.7,"disk_size":"57.2M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"r4","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.67,"mem_mb":15.7,"disk_size":"57M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.7,"mem_mb":15.7,"disk_size":"57M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"r4","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.95,"mem_mb":15.7,"disk_size":"47.8M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.96,"mem_mb":15.7,"disk_size":"47.8M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"r4","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.91,"mem_mb":15.7,"disk_size":"48M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.91,"mem_mb":15.7,"disk_size":"48M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"r4","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.54,"mem_mb":12.5,"disk_size":"47.3M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.53,"mem_mb":12.5,"disk_size":"47.3M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"r4","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.53,"mem_mb":12.5,"disk_size":"47M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.53,"mem_mb":12.5,"disk_size":"47M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"r4","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"r4","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null}]},"quickstart_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"quickstart runs on critical runtimes, recently tested","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":1},{"runtime":"python:3.9-slim","exit_code":1}]}}