Registry / serialization / fhir-core

fhir-core

JSON →
library1.1.7pypypi✓ verified 35d ago

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.

serializationdata
Install & Compatibility
Where this runs
tested against v1.1.8 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.421s · 28MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 3.2s · import 0.386s · 28MB
26MB installed
● package 26MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

from fhir_core.fhirabstractmodel import FHIRAbstractModel
from fhir_core.types import IdType
from fhir_core.types import BooleanType
from fhir_core.types import StringType

This example demonstrates how to define a simple FHIR 'Organization' model inheriting from `FHIRAbstractModel` and populate it with data. It showcases the use of `fhir_core.types` for primitive FHIR data types and Pydantic's `Field` for alias and validation.

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))
Debug
Known footguns
breakingBetween 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.
gotchafhir-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).
breakingfhir-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.
breakingThe `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.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
15 hits · last 30 days
gptbot
4
ahrefsbot
4
bytedance
2
script
1
Resources