Skip to main content


PyPI - Version PyPI - Python Version Pydantic v2 FHIR Releases


Pythonic healthcare interoperability
A comprehensive Python toolkit for working with FHIR healthcare data standards using Pydantic models from core and profiled FHIR specifications, all without external dependencies or complex server infrastructure.

Explore the Documentation »

Report Bug · Request Feature


[!WARNING]
This package is under active development. Major and/or breaking changes are to be expected in future updates.

Key Features

  • Automatic validation of FHIR resources using Pydantic models generated directly from FHIR structure definitions. Catch schema violations and constraint failures without any dedicated servers.

  • Work with FHIR data as standard Python objects. No XML parsing, no external FHIR servers required. Access and modify healthcare data using familiar Python syntax and patterns.

  • Supports FHIR R4, R4B, and R5 out of the box. Load implementation guides and custom profiles directly from the FHIR package registry to work with specialized healthcare data models.

  • Execute FHIRPath expressions directly on Python objects. Query complex nested healthcare data structures using the standard FHIR query language without additional tooling.

  • Implement healthcare data transformations using the official FHIR Mapping Language. Convert between different data formats while maintaining semantic integrity and validation.

(back to top)

Quick Start

Prerequisites

  • Python 3.11 or higher

Installation

Install Fhircraft using your package manager of choice. To download the latest release using the pip manager:

pip install fhircraft

or install the latest development version:

pip install git+https://github.com/luisfabib/fhircraft.git

To verify your installation:

import fhircraft
print("✓ Fhircraft installed successfully!")

(back to top)

Demo

Built-in FHIR Resources

Work with pre-generated Pydantic models for all standard FHIR resources. Each model includes full validation rules from the FHIR specification:

from fhircraft import R5 as fhir

# Create and validate a patient
patient = fhir.Patient(
    name=[{"given": ["Alice"], "family": "Johnson"}],
    gender="female",
    birthDate="1985-03-15"
)

print(f"Created patient: {patient.name[0].given[0]} {patient.name[0].family}")

FHIR Package Integration

Extend base FHIR models with implementation guide profiles loaded directly from the official FHIR package registry:

from fhircraft import FHIRModelFactory

# Create a FHIR (R5 release) factory
factory = FHIRModelFactory(fhir_release="R4")

# Load US Core Implementation Guide
factory.register_package("hl7.fhir.us.core", "5.0.1")

# Create US Core Patient model with enhanced validation
USCorePatient = factory.build(
    canonical_url="http://hl7.org/fhir/us/core/StructureDefinition/us-core-patient"
)

# Use with US Core constraints
patient = USCorePatient(
    identifier=[{"system": "http://example.org/mrn", "value": "12345"}],
    name=[{"family": "Doe", "given": ["John"]}],
    gender="male"
)

FHIRPath Querying

Execute FHIRPath expressions directly on FHIR resource instances to extract, filter, and validate healthcare data:

# Query patient data with FHIRPath
family_names = patient.fhirpath_values("Patient.name.family")
has_phone = patient.fhirpath_exists("Patient.telecom.where(system='phone')")

# Update data using FHIRPath expressions
patient.fhirpath_update_single("Patient.gender", "female")
patient.fhirpath_update_values("Patient.name.given", ["Jane", "Marie"])

print(f"Updated patient: {family_names[0]}, Phone: {has_phone}")

Data Transformation

Convert external data sources into valid FHIR resources using declarative mapping scripts:

from fhircraft import FHIRStructureMapper

# Legacy system data
legacy_patient = {
    "firstName": "Bob",
    "lastName": "Smith", 
    "dob": "1975-06-20",
    "sex": "M"
}

# FHIR Mapping script
mapping_script = """
/// url = "http://example.org/legacy-to-fhir"
/// name = "LegacyPatientToFHIR"

uses "http://hl7.org/fhir/StructureDefinition/Patient" as target

group main(source legacy, target patient: Patient) {
    legacy -> patient.name as name then {
        legacy.firstName -> name.given;
        legacy.lastName -> name.family;
    };
    legacy.dob -> patient.birthDate;
    legacy.sex where($this = 'F') -> patient.gender = "female";
    legacy.sex where($this = 'M') -> patient.gender = "male";
}
"""

# Execute transformation
mapper = FHIRStructureMapper(fhir_release="R5")
targets = mapper.map(mapping_script, legacy_patient)
fhir_patient = targets[0]

print(fhir_patient.model_dump(exclude={'meta','resourceType'}))
#> {'name': [{'family': 'Smith', 'given': ['Bob']}], 'birthDate': '1975-06-20'}

(back to top)

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated. Checkout the Contributing Guide for more details. Thanks to all our contributors!

(back to top)

License

This project is distributed under the MIT License. See LICENSE for more information.

(back to top)

Metadata

Release files for fhircraft 0.9.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fhircraft 0.9.0
File Size Uploaded
fhircraft-0.9.0.tar.gz 15.1 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for fhircraft 0.9.0
File Interpreter ABI Platform
fhircraft-0.9.0-py3-none-any.whl Python 3 none any Details

Total release size: 29.1 MB

Release files / fhircraft-0.9.0.tar.gz

Download URL fhircraft-0.9.0.tar.gz
Size 15.1 MB
Tags Source
SHA-256 checksum
How to use checksums
16086c88f18d61eb7994d68c99a9953b03cfd66050963da91e71f5a5b2a6d7a4
BLAKE2b-256 checksum
How to use checksums
4c1703fa61a9cf5688bfefdafd2ed0908cd65d236a10c4b63dda67d92cf77473
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 6, 2026.

Transparency log

Release files / fhircraft-0.9.0-py3-none-any.whl

Download URL fhircraft-0.9.0-py3-none-any.whl
Size 14.0 MB
Tags Python 3
SHA-256 checksum
How to use checksums
55248c2d90332f88bc8504b2dd6fb7f8c69cca8518acbee14c60967543c7b50e
BLAKE2b-256 checksum
How to use checksums
589ffcd5626f4b7be4622aa8106d591aa83fad487d11f1951877c99a5a78253c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 6, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.9.0 This release

2 release files

0.8.3

2 release files

0.8.2

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.5

2 release files

0.6.4

2 release files

0.6.3

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.7

2 release files

0.3.6

2 release files

0.3.5

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page