fhir.resources

Pydantic-powered Python models for every HL7® FHIR® resource and data type — R5, R4B and STU3 — with validation, JSON, XML and YAML built in.

$ pip install fhir.resources
>>> from fhir.resources.patient import Patient
>>> patient = Patient.model_validate({
...     "resourceType": "Patient",
...     "id": "p001",
...     "name": [{"family": "Smith", "given": ["Adam"]}],
...     "birthDate": "1985-06-12",
... })
>>> patient.name[0].family
'Smith'
>>> patient.birthDate
datetime.date(1985, 6, 12)
>>> patient.model_dump_json()
'{"resourceType":"Patient","id":"p001","name":[{"family":"Smith","given":["Adam"]}],"birthDate":"1985-06-12"}'
Every resource, every release

All FHIR R5 resources and data types by default, plus R4B and STU3 as sub-packages. Generated directly from the official StructureDefinitions.

Resource catalogue
Validation you can trust

Types, cardinality, required elements, value[x] choice rules and primitive formats are checked when a model is built.

Validation
JSON, XML and YAML

Round-trip FHIR JSON natively; XML (with optional XSD validation) and YAML through optional extras.

Serialization
Pydantic V2 inside

Every model is a pydantic BaseModel. Use them as FastAPI request and response types, subclass them, add your own validators.

Pydantic and FastAPI
Primitive extensions

Full support for _element extensions on primitive values, including the data-absent-reason pattern.

Extensions
Summary mode & comments

Serialize only _summary elements, and keep or strip fhir_comments on demand.

Summary mode and comments

Where next?


HL7®, FHIR® and the FHIR® flame logo are registered trademarks of Health Level Seven International. This project is not affiliated with or endorsed by HL7.