FHIR Python Analysis and Conversion Kit (PACK)

FHIRPACK (FHIR Python Analysis Conversion Kit) is a general purpose package that simplifies the access, analysis and representation of FHIR and EHR data. FHIRPACK was designed and developed at Institute for Artificial Intelligence in Medicine (IKIM) and the Database Systems Research Group of the University of Heidelberg (HDDBS).

About this Project

A brief description of this repository and the background of this project.


  • Minimalistic yet feature rich
  • CLI and API feature parity
  • Workflow friendliness
  • Extensible and flexible yet sane by default
  • Every data-manipulation step is an ETL step
  • Pandas DataFrames as primary user-facing data format


putup lib-fhirpack -p fhirpack -n 'fhirpack' -d 'A minimalistic Python package that simplifies crawling, correlating and representing FHIR resources related to individual patients or cohorts thereof.' --markdown --gitlab

├── AUTHORS.md
├── dist (generated during build time)
├── docs (generated during build time)
├── execution.log
├── LICENSE.txt
├── logo.png
├── Pipfile
├── Pipfile.lock
├── pyproject.toml
├── README.md
├── setup.cfg
├── setup.py
├── src
│   ├── fhirpack
│   └── fhirpack.egg-info
├── tests
│   ├── conftest.py
│   ├── __init__.py
│   ├── __pycache__
│   ├── test_cli.py
│   ├── test_pack.py
│   └── test_utils.py
└── tox.ini


Describe how to contribute.


Describe how to open issues, who to assign them to, what goes where, etc.

Merge Requests

Describe how to open MRs, who to assign them to, what goes where, etc.


Describe the architecture of the project and add an architecture diagram.


Describe the stack components in detail


For more information, see our Pipfile



Clone this repository

git clone ssh://[email protected]:2222/main/lib-fhirpack.git

Install your virtual environment

pip install pipenv python-dotenv tox pipenv-setup
pipenv install --dev

Verify you can run the tests and build FHIR PACK via tox

tox -e; tox -e build; tox -e clean

Verify you can run the tests and execute FHIR PACK via your virtual environment

pipenv run pytest --mypkg fhirpack
pipenv run ptw --runner "pytest --testmon"

In some cases, tox can have problems installing dependencies, you can recreate the environment used by tox (under ./tox) by using tox --recreate -e py3096


This project only relies on pyenv or asdf, pipenv, pipenv-setup, python-dotenv, pytest, pytest-watch, pytest-picked, pytest-testmon, bump2version and tox for development, testing, building and publishing

Tool Rationale
pyenv or asdf managing multiple python versions
pipenv managing virtual environments and seemless environment setup
tox one single tool for testing, packaging and publishing
pytest running unit tests
pytest-picked running only unit tests of code that has been changed
pytest-watch run unit tests continuously
python-dotenv use .env variables within tox.ini seemlesly
pipenv-setup automatically populate Python’s setup.py requirements
bump2version simple version management

Jupyter Notebook

You can use Jupyter, JupyterLab or VSCode’s Jupyter Plugin to use and improve usage.py and samples.py. However, keep in mind to not upload notebook outputs as they bloat the files and are irrelevant to the reader. To prevent that, execute echo -e '[filter "strip-notebook-output"]\n\tclean = jupyter nbconvert --ClearOutputPreprocessor.enabled=True --to=notebook --stdin --stdout --log-level=ERROR' >> .git/config within the repository. That line defines a clean for Jupyter notebooks that git can then use for all .ipynb files as described in .gitattributes

VS Code

tox -e clean


pipenv run pytest tests

ptw --runner "pytest --testmon"


pipenv run pytest -s --use-running-containers --docker-compose-no-build --pyargs fhirpack tests

ptw -- -s --use-running-containers --docker-compose-no-build --pyargs fhirpack tests -m 'not reqdocker'


bumpversion --allow-dirty patch ; cat VERSION


tox -e build

tox -e publish



The CLI can be invoked by using python -m fhirpack.cli or fp.

> fp --help                                
Usage: fp [OPTIONS]

  The pack for your FHIR server.

  --version               Show the version and exit.
  -s, --source TEXT       URL of the FHIR server or path to json files.
  -e, --environment TEXT  Path to Dotenv file containing configurations.
  -d, --destination TEXT  Location of the output.
  -o, --operation TEXT    Operations to retrieve data.
  -p, --params TEXT       Provide additional search parameters.
  -v, --verbose           Print results in verbose format.
  -h, --help              Show this message and exit.

CLI usage is analogous to the general fhirpack dataflow.

python shell
pack.getPatients(["1"]) fp -o "getPatients 1"
pack.getPatients(["1", "181", "525"]) fp -o "getPatients 1, 181, 525"
PACK(envFile=".../env.example").getPatients(["1"]) fp -e .env.example -o "getPatients 1"
pack.getPatients(searchParams={}).gatherSimplePaths(["name.family"]) fp -o "getPatients" -p all -o "gatherSimplePaths name.family"
pack.getPatients(searchParams={"family":"Koepp"}) fp -o "getPatients" -p "family = Koepp"

Of note, operations spanning mutliple spaces have to be quoted.

Python with .env File

pack= fp.pack.PACK(client)

Python with Manual Client Definition

import fhirpy
client = fhirpy.SyncFHIRClient("")
pack  = fp.pack.PACK(client)


List any important or related reading material


Acknowledge contributors


View Github