Skip to main content

A Python client to interact with FHIR servers

Project description

fhir‑client

A lightweight, opinionated Python client for working with FHIR servers via the REST API.

PyPI version PyPI Downloads Python 3.12+ License: MIT CI


📚 Table of Contents


🔍 What is fhir‑client?

fhir-client is a minimal wrapper around the FHIR REST API.
It handles:

  • Standard CRUD operations (GET, POST, PUT, DELETE)
  • Automatic JSON serialization/deserialization
  • Optional authentication (Basic Auth, OAuth2)

Designed for developers who want to get started quickly without the overhead of a full‑blown SDK.


✨ Key Features

Feature Description
Simple API FHIRClient exposes high‑level methods that map directly to FHIR operations.
Configurable Base URL and authentication can be set globally or per request.

📦 Installation

# From PyPI
pip install fhir-server-client

Developed and tested on Python 3.12


🚀 Getting Started

from fhir_client.client import FhirClient

# Create a client pointing at the HAPI FHIR demo server
client = FhirClient(base_url="https://hapi.fhir.org/baseR4")

# Perform a GET request for a Patient
patient = client.get("Patient", _id=123)
print(patient)

# Or use the generic GET method
patients = client.get("/Patient")
print(patients)

📚 Examples

Below are a few common use cases. Feel free to copy‑paste and adapt.

📦 Basic CRUD

# CREATE a new Patient
new_patient = {
    "resourceType": "Patient",
    "name": [{"family": "Doe", "given": ["John"]}],
    "gender": "male",
    "birthDate": "1974-12-25"
}
created = client.post("Patient", data=new_patient)
print("Created patient ID:", created["id"])

# READ the newly created Patient
patient = client.get("Patient", _id=created["id"])
print(patient)

# UPDATE the Patient
patient["name"][0]["given"] = ["Jonathan"]
updated = client.put("Patient", id=created["id"], data=patient)
print("Updated patient:", updated)

# DELETE the Patient
client.delete(resource_type="Patient", _id=patient["id"])
print("Patient deleted.")

🔍 Search & Filtering

# Search for patients named "John" with a minimum age of 18
results = client.get("Patient", name="John", birthdate="ge1975-01-01")

for patient in results["entry"]:
    print(patient["resource"]["id"], patient["resource"]["name"][0]["given"])

# Checking for and getting self, next and previous links
if client.has_self():
    self_link = client.self

if client.has_next():
    next_link = client.next

if client.has_previous():
    previous_link = client.previous

The get method accepts search parameters as python keyword arguments. Those are appended in the FHIR Search Query

🔐 Authentication

# Using Basic Auth
from fhir_client.auth import FhirAuth

auth = FhirAuth().set_basic_auth("username", "password")
client = FHIRClient("https://fhir.example.com", auth=auth)

# Using OAuth2 (client credentials flow)
from fhir_client.auth import FhirAuth

auth = FhirAuth().set_o_auth(
    auth_url="https://auth.example.com/token",
    client_id="client-id",
    client_secret="client-secret"
)
client = FHIRClient(base_url="https://fhir.example.com", auth=auth)

🤝 Contributing (WORK IN PROGRESS)

We love contributions! Please read our CONTRIBUTING.md for guidelines on coding style, testing, and pull requests.

Steps to get started

  1. Fork the repo and clone it locally.
  2. Create a new branch (git checkout -b feature/foo).
  3. Write tests for your change.
  4. Run the test suite (pytest).
  5. Submit a pull request.

📄 License

MIT © 2026

See the LICENSE file for details.


🙏 Acknowledgements


Happy coding! 🎉

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fhir_server_client-0.0.4.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fhir_server_client-0.0.4-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file fhir_server_client-0.0.4.tar.gz.

File metadata

  • Download URL: fhir_server_client-0.0.4.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for fhir_server_client-0.0.4.tar.gz
Algorithm Hash digest
SHA256 26f475a4feb2abbf278f904d932d68c16d95d0901d6c52be60bfd61250ccca33
MD5 ef1467fff8eb2515e9494832fb2d453a
BLAKE2b-256 8205d34943fe89f0556e497f0eed3f6801b005638fba50aa27d1e99f488e4a11

See more details on using hashes here.

File details

Details for the file fhir_server_client-0.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for fhir_server_client-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 c75a75233e804615c2186c598bb701e6c33799cc77deebff65e58d5a7b717dfd
MD5 b952d70f43d594497270a9f3571530bb
BLAKE2b-256 acb5087eb5bf0aa56b5b4228f40dfdf8bea8903179b6e596c348a0b152219ce0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page