Skip to main content

Python DIC Helper Toolkit

This Toolkit contains helper libraries for the data integration centers daily tasks.

Installation

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.

Metadata

Release files for dic-helper-toolkit 1.0.2

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.2
File Size Uploaded Provenance Actions
dic_helper_toolkit-1.0.2.tar.gz 21.5 kB With provenance Details for dic_helper_toolkit-1.0.2.tar.gz

Built distribution (wheel)

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

Total release size: 36.9 kB

Release files / dic_helper_toolkit-1.0.2.tar.gz

Download URL dic_helper_toolkit-1.0.2.tar.gz
Size 21.5 kB
Tags Source
SHA-256 checksum
How to use checksums
315c0ec00d53c232206f0ff5854e02653873c436923b31b2d64c4510868e84b7
BLAKE2b-256 checksum
How to use checksums
49cd2fa67f9bab1ed147add7068ba3297eaa7e5967cd9cd06d8a9da6bf349527
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 27, 2026.

Transparency log

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

Download URL dic_helper_toolkit-1.0.2-py3-none-any.whl
Size 15.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9502fed3dbf311dc1c8a09e934b85d372d403472d8e635ba3c784e1ae8b6842d
BLAKE2b-256 checksum
How to use checksums
156b8ae1f79833af7576a6f39a84284b0f5b1c2feab08f38ab8d98f327208399
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 27, 2026.

Transparency log

Security for dic-helper-toolkit 1.0.2

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.2.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 27, 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