Registry / serialization / fhir-core

fhir-core

JSON →
library1.1.10pypypi✓ verified 23d 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.

pip install fhir-core
INSTALL
IMPORT
SIG · FHIR-CORE
F
fhir-core
serializationpythonv1.1.10
Install
3.3s avg
Import
386ms
Disk
26MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.1.10 · 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.95 runs
installs and imports cleanly · install 0.0s · import 0.320s · 28MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 3.3s · import 0.298s · 28MB
26MB installed
● package 26MB
Code
Verified usage

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

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

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 issues
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.
fix
Update your code to use `FHIRAbstractModel` as the base class. Review and adapt calls to `parse_obj` (now a classmethod), and prefer `model_dump()` or `model_dump_json()` from Pydantic V2 for serialization instead of `as_json` or `dict`.
affects: <1.0.0
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).
fix
Always verify the `pypi-slug` and `source_url` to confirm you are using the correct library. Use `pip install fhir-core` for this specific library.
affects: All versions
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.
fix
Upgrade Pydantic to version 2 or greater (`pip install 'pydantic>=2'`). Review Pydantic V1 to V2 migration guides if you have existing Pydantic models.
affects: All versions
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.
fix
Always ensure that the `fhir-core` version installed meets or exceeds the minimum requirement specified by your `fhir.resources` version. Check the release notes or `install_requires` of `fhir.resources` for compatibility.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'fhir_core'
The `fhir-core` package is not installed in the current Python environment.
fix
Install the package using pip: `pip install fhir-core`
ImportError: cannot import name 'ROOT_VALIDATOR_CONFIG_KEY' from 'pydantic.class_validators'
This error typically occurs when `fhir-core` (or a library depending on it like `fhir.resources`) is used with an incompatible version of Pydantic, specifically when Pydantic v1 code attempts to run in a Pydantic v2 environment due to breaking changes in Pydantic's API. `fhir-core` is powered by Pydantic V2.
fix
Ensure that all libraries in your environment are compatible with Pydantic V2. If you are using `fhir.resources`, make sure you have a version compatible with `fhir-core`'s Pydantic V2 dependency (e.g., `fhir.resources` version 8.0.0 or higher). If other dependencies require Pydantic V1, you might need to isolate environments or update those dependencies.
pydantic.ValidationError
This error occurs when data provided to construct a FHIR resource model (which is built using Pydantic V2 by `fhir-core`) does not conform to the FHIR specification or the Pydantic model's defined schema. This could be due to missing required fields, incorrect data types, or invalid values for specific fields.
fix
Inspect the error details provided by Pydantic (e.g., `pydantic.ValidationError.errors()`) to identify which specific fields have validation issues. Adjust the input data to match the expected FHIR structure, data types, and constraints defined by the `fhir-core` models.
Upgrade
Version history
1.1.10latest on PyPI · released Jul 25, 2026
Audit
Dependencies
pydantic>=2requiredThe library leverages Pydantic V2 for data validation, serialization, and deserialization.
fhir.resourcesoptionalThis library is developed to support fhir.resources, which provides generated Python classes for all FHIR Resources.
Agent activity
8 hits · last 30 days
node
6
Amazon
1
Resources
fhir-core — pip install fhir-core · libregistry