Registry / serialization / fhir.resources

fhir.resources

JSON →
library8.0.0pypypi✓ verified 36d ago

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.

serializationai-ml
Install & Compatibility
Where this runs
tested against v8.2.0 · 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
glibc
py 3.10
✓ —
✓ 4.82s
py 3.11
✓ —
✓ 4.1s
py 3.12
✓ —
✓ 3.7s
py 3.13
✓ —
✓ 3.83s
py 3.9
6/10 runs
6/10 runs
51MB installed
● package 51MB
Code
Verified usage

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

The package uses a namespace package 'fhir.resources'. Each resource type is in its own module with a lowercase name.

from fhir.resources.patient import Patient

To use FHIR R4B resources, import from fhir.resources.R4B subpackage. Default top-level imports are R5.

from fhir.resources.R4B.patient import Patient

STU3 resources live under the fhir.resources.STU3 subpackage.

from fhir.resources.STU3.patient import Patient

Each FHIR resource is its own module. Import the class with the CamelCase name from the lowercase module.

from fhir.resources.bundle import Bundle

Create, validate, and serialize a FHIR Patient resource using Pydantic v2 methods.

from fhir.resources.patient import Patient # Create from dict patient_data = { "resourceType": "Patient", "id": "example", "active": True, "name": [ { "use": "official", "family": "Doe", "given": ["John"] } ], "gender": "male", "birthDate": "1990-01-01" } patient = Patient.model_validate(patient_data) print(patient.name[0].family) # 'Doe' # Serialize back to FHIR JSON print(patient.model_dump_json(indent=2)) # Parse from JSON string json_str = patient.model_dump_json() patient2 = Patient.model_validate_json(json_str) print(patient2.id) # 'example'
Debug
Known footguns
breakingfhir.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.
breakingDefault FHIR version changed from R4B to R5 in fhir.resources 7.x+. Top-level imports now return R5 models.
breakingPydantic v2 migration changed validation and serialization methods. .parse_obj() and .json() are replaced.
gotchaThe package installs as a namespace package (fhir.resources). Do not create your own 'fhir' package in your project or it will shadow the library.
gotchaFHIR resource validation is strict by default. Missing required fields or invalid value sets will raise ValidationError.
gotcharesourceType field must match the class name exactly. Passing resourceType='patient' (lowercase) will raise a validation error.
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
25 hits · last 30 days
claudebot
5
gptbot
4
amazonbot
4
ahrefsbot
3
chatgpt-user
3
bytedance
1
meta-externalagent
1
Resources