Skip to main content

Python DIC Helper Toolkit

This Toolkit contains helper libraries for the daily tasks of Data Integration Centers (DICs) — the data integration and interoperability platforms operated by German university hospitals, as defined by the German Medical Informatics Initiative (Medizininformatik-Initiative, MII) and used across projects of the Network of University Medicine (Netzwerk Universitätsmedizin, NUM). DICs provide standardized, FHIR-based access to clinical and research data for secondary use.

Installation

Requires Python 3.13 or newer: the HTTP client's strict RFC 5280 certificate checks (rfc5280=True, the default) are Python's default from 3.13 on.

pip install dic-helper-toolkit

The package is published on PyPI. To use the FHIR XML reader, install the xml extra: pip install dic-helper-toolkit[xml].

Contents

HTTP client

A wrapper around the requests library which allows to create an object for an endpoint holding all needed configuration including authentication and certificate verification. It supports Basic Auth and OAuth 2.0.

Usage:

from dic_helpers.http_client import HTTPClient

## No authentication or CA certificate at all
client = HTTPClient(base_url="https://example.com")

## Basic Auth with CA certificate
#client = HTTPClient(base_url="https://example.com", username="user", password="P4SSW0RD", ca_file="MyCA.crt")

## OAuth 2.0 with username and password
#client = HTTPClient(base_url="https://example.com", username="user", password="P4SSW0RD",
#                    auth_url="https://keycloak.example.com", realm="MyRealm", client_id="MyClient",
#                    client_secret="00000000-00000000-00000000-00000000", ca_file="MyCA.crt")

with client.get("index.html") as result:
    print(result)

FHIR client

A simple FHIR client library which uses the HTTP client from above and handles resources directly as fhir.resources (https://github.com/nazrulworld/fhir.resources) object.

Usage:

from dic_helpers.fhir_client import FHIRClient

client = FHIRClient(base_url="https://example.com", username="user", password="P4SSW0RD",
                    auth_url="https://keycloak.example.com", realm="MyRealm", client_id="MyClient",
                    client_secret="00000000-00000000-00000000-00000000", ca_file="MyCA.crt")

# Fetch a patient 
patients = client.search("Patient", "identifier=0123456789&_lastUpdated=ge2025-01-01"):
for patient in patients:
    print(patient)

Keep in mind, that this returns an object.

Directory reader

Lists the files of a directory, optionally including all subdirectories, whose names match shell-style patterns.

Usage:

from dic_helpers.directory_reader import DirectoryReader

reader = DirectoryReader("/data/export", patterns=["*.json", "*.ndjson"], recursive=True)
for path in reader.list_files():
    print(path)
  • Only regular files are listed, sorted by path, as pathlib.Path objects that start with the directory as given.
  • patterns (default "*") are matched case-sensitively against the file names (*, ?, [seq]). A single pattern can be a string; a file is listed if it matches any pattern. Special characters in the directory's own name don't matter.
  • recursive (default False) also lists the files of all subdirectories.
  • include_hidden (default False): hidden files (names starting with .) are skipped and hidden directories are not read, unless this is True.
  • follow_symlinks (default False): symbolic links to directories are only read if this is True. Every directory is read once at most, so symlink loops end. Symbolic links to files are always listed, broken links never.
  • Errors: a missing directory raises FileNotFoundError, a file instead of a directory NotADirectoryError, and an unreadable directory PermissionError. An empty list therefore always means that no file matched.

FHIR file reader

Reads FHIR R4B resources from files as fhir.resources objects, together with the file and line they were read from. Combined with the directory reader:

from dic_helpers.directory_reader import DirectoryReader
from dic_helpers.fhir_file_reader import FHIRFileReader

paths = DirectoryReader("/data/export", patterns=["*.json", "*.ndjson", "*.xml", "*.gz"], recursive=True).list_files()
for item in FHIRFileReader(paths).resources():
    print(item.path, item.line, item.resource.get_resource_type(), item.resource.id)

Formats, by file extension (case-insensitive):

Extension Content item.line
.json one resource None
.ndjson one resource per line (FHIR bulk data), empty lines are skipped line number, from 1
.xml one resource in FHIR XML, the resource type comes from the root element None
.json.gz, .ndjson.gz, .xml.gz the same, gzip compressed as above

Other extensions are an error, the format is not guessed. Text is UTF-8, a byte order mark is allowed. Reading XML needs lxml: install dic-helper-toolkit[xml]. External entities are not resolved, an XML file that references one is invalid.

Parameters:

  • paths: the files, read in this order; a single path can be given on its own. Resources come in the order they appear in each file. NDJSON files are read line by line, also compressed ones; JSON and XML files as a whole.
  • unpack_bundles (default True): a Bundle gives the resources of its entries, of any Bundle type. Only the outermost Bundle is unpacked, entries without a resource are left out. With False the Bundle is returned.
  • on_error (default "raise"): an unreadable or invalid file, NDJSON line or resource raises FHIRFileError, whose message starts with the file and line, e.g. export/Patient.ndjson:17: invalid JSON: … or patient.json: invalid Patient: birthDate: Date value string does not match spec regex.. With "skip" the message is logged as a warning, and reading continues with the next line (NDJSON) or the next file. A missing lxml is always an error.

License

dic-helper-toolkit is licensed under the MIT License.

Metadata

Release files for dic-helper-toolkit 1.0.6

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

Source distribution (sdist)

Source distribution for dic-helper-toolkit 1.0.6
File Size Uploaded Provenance Actions
dic_helper_toolkit-1.0.6.tar.gz 23.1 kB With provenance Details for dic_helper_toolkit-1.0.6.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for dic-helper-toolkit 1.0.6
File Interpreter ABI Platform Actions
dic_helper_toolkit-1.0.6-py3-none-any.whl Python 3 none any Details for dic_helper_toolkit-1.0.6-py3-none-any.whl

Total release size: 40.0 kB

Release files / dic_helper_toolkit-1.0.6.tar.gz

Download URL dic_helper_toolkit-1.0.6.tar.gz
Size 23.1 kB
Tags Source
SHA-256 checksum
How to use checksums
9b48feafe8f157c2cbd27b0a961b11efd57bee411c27d1aba3a022fecf4ed00d
BLAKE2b-256 checksum
How to use checksums
583d4ca5b4929305a26c8af18c77e2715f7792128a311e1c986c2ed2084fad90
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Oct 28, 2026.

Transparency log

Release files / dic_helper_toolkit-1.0.6-py3-none-any.whl

Download URL dic_helper_toolkit-1.0.6-py3-none-any.whl
Size 16.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c2a19c669083ef82b4f0860031f92f3bc4e4f1b680663145ebc9c06b0217ba1f
BLAKE2b-256 checksum
How to use checksums
0d87bbfa97ce2be49558786acde365fce89df6e2fca721629bd5cf3b01843834
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Oct 28, 2026.

Transparency log

Security for dic-helper-toolkit 1.0.6

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.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for dic_helper_toolkit-1.0.6.tar.gz

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 Oct 28, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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