{"id":132,"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.2.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 to Pydantic v2 (pip install 'pydantic>=2.0') or pin fhir.resources<7.0.0 for Pydantic v1 compatibility.","message":"fhir.resources 7.x+ requires Pydantic v2. 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"},{"fix":"Upgrade your Python environment to 3.10 or newer to ensure compatibility with Pydantic v2's type hint evaluation. If unable to upgrade Python, consider pinning `fhir.resources<7.0.0` for Pydantic v1 compatibility (as per warning #0).","message":"fhir.resources 7.x+ relies on Pydantic v2, which may utilize type annotations incompatible with Python 3.9 or earlier (e.g., the `|` union operator syntax introduced in Python 3.10). This can lead to a `TypeError` during model import or evaluation.","severity":"breaking","affected_versions":">= 7.0.0"}],"env_vars":null,"last_verified":"2026-05-12T08:13:11.154Z","next_check":"2026-06-17T00:00:00.000Z","problems":[{"fix":"Review the FHIR specification for the specific resource and its fields, ensuring that all required fields are present and data types/formats (e.g., dates, codes, quantities) match the expected schema for the FHIR version being used.","cause":"Input data provided to a FHIR resource constructor does not conform to the FHIR specification's data model, such as incorrect data types, missing required fields, or invalid formats, which Pydantic then flags.","error":"pydantic.ValidationError: X validation error for Y"},{"fix":"Add a check to verify that the returned object is not 'None' before attempting to access its attributes or methods. For example, `resource = Patient.get('some_id')` should be followed by `if resource: resource.serialize()`.","cause":"A preceding operation, such as a search or retrieval, failed to find a FHIR resource and returned 'None', on which a subsequent method (like '.serialize()' or any other attribute access) was then attempted.","error":"AttributeError: 'NoneType' object has no attribute 'serialize'"},{"fix":"For FHIR R5 resources, import directly from `fhir.resources`, e.g., `from fhir.resources.patient import Patient`. For older FHIR versions, ensure you are importing from the correct versioned submodule, e.g., `from fhir.resources.R4.patient import Patient` for R4, or `from fhir.resources.STU3.patient import Patient` for STU3.","cause":"Attempting to import a FHIR resource from an incorrect or non-existent version-specific submodule. While `fhir-resources` version 8.2.0 defaults to FHIR R5, older versions (like R4, R4B, STU3) are available in specific submodules, and incorrect paths will lead to this error.","error":"ModuleNotFoundError: No module named 'fhir.resources.R4.patient'"}],"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.57,"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.39,"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.4,"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.81,"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.83,"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.69,"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.95,"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.92,"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.92,"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.55,"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.52,"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.54,"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.55,"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}]}}