FHIR Core Library
fhir-core is a Python library providing an abstract base class for FHIR resource models and Primitive Datatypes, along with factories to create FHIR resource models and other complex datatypes. It is powered by Pydantic V2, ensuring data validation and efficient serialization/deserialization. This library is primarily developed to support the 'fhir.resources' library but can be used independently. As of March 2026, the current version is 1.1.7, with frequent patch releases.
Warnings
- breaking Between fhir-core 0.x and 1.x (and consequently fhir.resources <8.0.0 and >=8.0.0), there were significant breaking changes in the base model class and its methods. `FHIRAbstractBase` was replaced by `FHIRAbstractModel`. Methods like `__init__`, `parse_obj`, `as_json`, and `dict` had their signatures or behavior altered.
- gotcha fhir-core is developed by 'nazrulworld'. Be aware that other Python libraries with similar names exist (e.g., `google-fhir-core`, `fhir-py`, `fhirclient`), which serve different purposes or are maintained by different entities. Ensure you are importing from `fhir_core` (with an underscore).
- breaking fhir-core relies on Pydantic V2. If your project uses Pydantic V1, there will be incompatibilities. Ensure your environment is set up with Pydantic V2 or later.
- breaking The `fhir.resources` library, which `fhir-core` supports, has minimum version requirements for `fhir-core`. For instance, `fhir.resources` 8.0.0 requires `fhir-core` 1.0.0, and `fhir.resources` 8.2.0 requires `fhir-core` 1.1.5. Incompatible versions between the two libraries can lead to runtime errors.
Install
-
pip install fhir-core -
git clone https://github.com/nazrulworld/fhir-core.git && cd fhir-core && pip install -e .[dev]
Imports
- FHIRAbstractModel
from fhir_core.fhirabstractmodel import FHIRAbstractModel
- IdType
from fhir_core.types import IdType
- BooleanType
from fhir_core.types import BooleanType
- StringType
from fhir_core.types import StringType
Quickstart
from typing import List
from pydantic import Field
from fhir_core.fhirabstractmodel import FHIRAbstractModel
from fhir_core.types import IdType, BooleanType, StringType
class Organization(FHIRAbstractModel):
resourceType: StringType = Field('Organization', const=True)
id: IdType = Field(None, alias='id')
active: BooleanType = Field(None, alias='active')
name: StringType = Field(None, alias='name')
address: List[dict] = Field(None, alias='address') # Simplified for example
data = {
"id": "f001",
"active": True,
"name": "Acme Corporation",
"address": [
{
"use": "work",
"line": ["534 Erewhon St"],
"city": "PleasantVille",
"state": "Vic",
"postalCode": "3999",
"country": "ZZ"
}
]
}
organization_instance = Organization(**data)
print(organization_instance.json(indent=2))